Storyboard: In this lab we will develop a tic-tac-toe board that can be played and used. The “active” part of the board means that in the end of the lab we will be able to play tic tac toe. To create this lab we will use a series of blocks that we will make and use the “clone” feature to duplicate the costumes such as boxes that are the sprites. We will also use a block called “delete the clone” to delete the duplicated boxes. This feature will leave the original block in place and delete all others.
Logic: In this lab we will be using one central idea of computer science, called parallelism or distributed computing. The project is operating on a computer and using an illusion provided by Snap! which allows the sprites to run simultaneously. To expand on this, the computer and this program specifically allows us to use commands and variables such as “MakeBoard” to clone a parent, in this case a block, and place it in a desired layout.
In order to change the costumes based on the player, we included if and else blocks with specific details about X and Y players. If it is X’s turn, then the block switches to the X costume. Additionally, if it is Y turn, the block design switches to O.
We then needed to determine what counts as a win by storing each possible winning triple in a list. We did this by thinking of all possible solutions for three in a row in order to win the game.
Steps:
- First, we created a Sprite with three different costumes, one with an “X”. one with an “O”, and one as an empty box.
We used this set of blocks to create nine boxes to set up the tic tac toe board. We then created a block similar to the one below.
This did not affect the original Sprite.
2.) Then, we deleted the when I am clicked script.
3.) Next, we edited the makeboard to set up nine clones in three rows of three.
4.) The clones will start out without an X or an O, and we did this by creating a “set” block that stated that the list began as “empty”.
5.) The if, else block is then used to create the players of X and Y paired with the costume switch blocks.
6.) We used a repeat block around our “makeBoard”.
7.) Within our “Make Board”, we included several “move x to …” in order to create the grid.
8.) Underneath the make Board block, we added a “set” block with “X’s turn?” to true.
9.) We created a new variable called “Sprite Local Variable” in order to number each block.
10.) We numbered the grid 1 through 9.
11.) We then created a global variable to keep track of the costume of each individual square and its costume (blank, an X, or an O).
12.) We then made a local variable in order to associate each block to a number so that the winning board has the list of the winning triples.
13.) We then created a won? Block which established who was the winner based off of the winning triples
14.) Within this won? Block, we created three levels of steps including reporter blocks call “winning triple” and “status of triples”
15.) We then created two if else blocks and put both of the won blocks within these (one for O won and one for X won).
16.) In the else section, we created the possibility that one block is left empty and included a say block “Tie game!”.
Problems:
We had issues with deleting our parent block after all of the clones were made, after our project was deleted. After a few rounds of trial and error, we added a hide block and were able to erase the parent block and create a complete 3×3 grid.
We struggled to assemble the grid correctly, because at first we had a random alignment of squares.
Also, once we had the grid, we struggled to assign the various costumes (the X’s and O’s) to the squares in order to have them appear.
Our blocks were numbered wrong and so when the first block was clicked, the board stated that the number 2 position was filled and the number 1 position was empty.
FINAL PROJECT: https://snap.berkeley.edu/snapsource/snap.html#present:Username=gigiharthan_apcsp&ProjectName=U2L4-Tic-Tac-Toe