Skip to content
by Unity Nodes
NEAR Protocol

NEAR Certified Demo | Episode 5.2 -- Tic Tac Toe

about 10:45 long

Nothing is loaded from YouTube until you press play, and then without tracking cookies.

About this video

This demonstration was presented by the author(s) after just 1 week of working with the NEAR platform as part of the NEAR Certified Developer program.

You can find the source code to this demo here: https://github.com/Learn-NEAR/NCD-05-...

---

Follow the latest from NEAR Protocol on: Website: near.org Discord: near.chat Blog: near.org/blog Twitter:   / nearprotocol   GitHub: github.com/near github.com/nearprotocol #Blockchain #FutureIsNEAR #NEAR #nearprotocol

Transcript

1,177 words

Captions as YouTube publishes them, usually machine-generated, so product and people names can be misheard.

  1. 0:00

    if not um winx you're up yes yes we are okay yeah okay great thanks evan can you guys listen to me yeah okay so let me try to share my screen here all right can you guys see my screen yeah okay so um we created a tic-tac-toe game uh in a smart contract where we have two players and and they play a game in the smart in the smart contract so uh to demonstrate that we we recorded a video that i'm gonna show you to to everyone here so

  2. 0:53

    um can you guys see the video here yes okay uh so let's begin um the first point here is that uh igor is deploying the uh the smart contract and now he will create a game so he called the function create game passing his account id and and attach some near tokens so the basic idea is that uh you have the the the player one who created the game and he needs to attach some near tokens

  3. 1:34

    and then uh he got uh an id here he'll get he'll copy his id and send to me for example and me in the other and i'm gonna get that that id and join the game so we have another function called join game that i passed the game id and uh i need to attach some new tokens to to start playing playing the game so it works a little bit fast but uh here we go it says join at the game let's play so we have the two players already joined the games

  4. 2:22

    so the next part of the the video is uh to start choosing a row and a column to to to to to play the game uh the player one is the uh is the number we we just don't use it the x and o or circle we use one and minus one for this example we recorded yesterday and we made some improvement improvements since then but the main idea is the player one is is he is the number one and the player two is the minus one so here he goes or the

  5. 3:08

    the other function we created its viewport that it shows uh the the tic-tac-toe game so the first row the second row and the third row and no one feel it uh nothing but because we we didn't play any any rounds yet so the next part is actually send a a play color play function here let's see yes so igor call it the play function passing the id the the row or line and the column

  6. 3:54

    and now we can see that uh that that that one and the position he he sent was was fielded here in the game and now it's my turn playing uh choosing another row and another column and the goal it's the tic-tac-toe game so here the game is continuous yes the player can use view board function to see the board yes is that i am using the hassle here uh eager if uh he eager is one and i'm minus one

  7. 4:49

    uh let's see i'm calling a viewport function to see what is where he played the last round uh five minutes all right all right so igor won the game because he made it uh uh uh a column of we call numbers so igor won the game and receive it uh 10 years because we attach it five years each so uh basically that's it we we

  8. 5:50

    we played the game uh won't create the game in order join the game and we can we can play uh and see the board we didn't create no no front end or nothing like that we just created we we started we started to create some wireframes here uh but just using sigma just to to show something but let's go to the code here so that is the function play a couple of ticks please yeah sure

  9. 6:35

    here is it better yeah that's okay yeah okay so yeah it's a little bit is a little bit ugly we do in a little rush but the main idea is to to refactor in this code of next week and the next the next weeks but here we have the the first function is create the game i have the second function to actually play the game to send where you send a line in a column and we have a lot of asserts here to check

  10. 7:13

    if the line is valid the column's valid position if it is your turn yeah uh uh we need to fill the board we need to verify the board if uh if the if the the player won't that won that round or not uh we have another function called a view board where it's returning the the uh the board like uh i show here and in the last ah we have the join game where you send the game id uh in in you are

  11. 7:59

    attach it as a player to their mouth uh and the last one is yeah that's it i think we have another other and other functions that use it in the game but not exported to verify and to do other kind of stuff so the idea is that we can uh the idea is the next month we can create a a ui to this game so you can actually play in the browser not needing to to always send a line of code

  12. 8:46

    i think that's it you want to say something else either no i think anyone has anyone has any questions we record the video just because of the fast we can speed the changes speed but yeah so it took more than it took more than 10 minutes to to to record this video and to play the game so uh yeah great question record the video yeah if you if anyone like to play just yeah uh this is the contract contract

  13. 9:30

    can you post the source code to the chat here yeah sure uh let me see how i can do that if i'm still recording you can stop sharing your screen if that makes it easier to find the chat window yeah okay here we go so this is the ripple you can find the video demo and the figma wireframes there too i think that's it okay nice that's great thank you so much yeah i i i have to interrupt you sheriff

  14. 10:12

    like this is brilliant idea to record this video like it's just just brilliant you guys like just open this like like i've never seen this probably i saw that something like this before but this is like just man this is cool this like people do care about others people time right respect yeah we just don't want to spend 30 minutes here playing a game thank you everyone thank you awesome

  15. 10:45

    thank you