ST EK List:
No EK's found

Remembering the Moves

This comment box applies to both pages of the lab.

Why at all? This lab introduces map and gives practice in using HOFs to do interesting analysis. It also lays the groundwork for later strategy computation.

As a side benefit, this lab gives an opportunity to talk about how two very different solutions to the U2 TTT problem are interchangeable here provided they implement the same API, namely providing the board list.

Why here? This unit is about lists, HOFs, and functional programming, all of which are exercised in this lab. In particular, this lab replaces the former one with a page per HOF.

This very short page could possibly be combined with the next, to make a one-page lab, but there's a definite shift in focus between thinking about ties and thinking about wins.

Here is some of the critical teacher feedback (there was some positive feedback, but more like this):

In this lab, you will continue your Tic-Tac-Toe project from Unit 2 to make the program analyze the game board to detect wins and ties.

On this page, you'll prepare by allowing the program to record the moves that are made.

When you first wrote Tic Tac Toe, it was easy to detect illegal moves (moving to a square that's already wearing an X or O costume) because each sprite could test for that without knowing about the rest of the gameboard. But to detect wins and ties, the program needs a way to test the state of the whole gameboard, not just one individual piece. So, we'll use a global variable, board, to keep track of whether the square in each position is empty or filled with an X or an O.

You learned about global variables on Unit 2 Lab 1 Page 3: Keeping Score with Global Variables.

picture of: watcher of board variable showing {X, O, Empty, Empty, X, Empty, Empty, Empty, O}; and Tic Tac Toe game with X in upper left and center and O in upper middle and lower right

  1. Open your U2L4-TicTacToe project, and save it as U3L2-TicTacToe so you'll still have your old version when you edit the new one.
  2. Make a global variable called board that, at the beginning of the game, contains a list with the word "Empty" nine times.

Each sprite needs to know its own position on the board so that we can use the item of block to replace that position with an X or an O. So, we'll create a sprite-local variable, position number, and each clone will have its own version of this variable.

You learned about script-local variables on Unit 2 Lab 1 Page 1: Developing a Number Guessing Game with Script Variables.

A sprite-local variable is like a global variable in that it doesn't belong to a particular script (as a script-local variable does), but it does belong to a particular sprite.

  1. Create a local (sprite) variable position number.

    You make a local variable similarly to how you make global variables:

    • Click make a variable button in the Variables palette
    • Then, as you are typing the variable's name, select "for this sprite only" to make it a local (sprite) variable

    variable name dialog box with 'for this sprite only' selected
  2. As you create the clones, set each one's position number to the appropriate value (1-9).
    In the loop that makes the clones, increase the variable by one for each new clone so that each clone will have a unique value.
    Make sure that the parent's position number doesn't end up being a number 1-9 so that it doesn't conflict with a clone.
  3. When a square is clicked, replace that square's entry in the board list with X or O as appropriate.
  4. Watch the values stored in the board variable as you play a game of Tic Tac Toe. Make sure that it updates as you expect it to, and fix any bugs.
  5. Save. You will use this later.