I made some edits to include the word "possible" more. I'm not sure I didn't make it more confusing. Need to look again another day. --MF, 6/13/18
I need to review the rest of this lab. Looks different than before. --MF, 5/31/20
PG: I haven't thought deeply (haven't even read carefully!) but would want to check carefully to make sure this is /developmentally/ helpful. Maybe it already is.
On this page, you'll program your Tic-Tac-Toe project first to report the contents of one specific set of three squares that would make a win (such as the top row), and then to use that to find the contents of all possible winning triples. You'll use that information to find out if one of the players has won the game.
We need a way to find out if a possible winning triple has actually happened. We can use map
to check each position in one triple to see if either player has won with that triple.
You learned about map
in Unit 3 Lab 2 Page 5: Transforming Every List Item.
Map
applies the function in the gray ring to each item in the input list, and it reports a list of all the results.
Recall that the blank input slot in the function inside the gray ring is where one list item goes every time the function is performed.
map
work here?
This map
expression works the same way as the join
example above, but people sometimes find it a little more complex to think about, because it's natural to expect , but that's not what the expression says. Instead, it maps over a constant list, not a variable. As before,
map
inserts each list item into the blank space in the function inside the gray ring, and it reports a list of the results.
But here, the function in the gray ring is item ( ) of (
board)
, so map
checks items 1, 2, and 3 of the board list, and it reports a list of what is in those three positions (each of which is X, O, or a number if the square is empty).
If you can't see what's inside the board variable, be sure its box is checked in the Variables palette and expand its watcher to see its list items as in the picture below.
{1, 2, 3}
isn't the triple in which x won the game, replace the list in the map
expression with the winning triple, and click the expression again.True
if X won the game in the triple False
otherwise.
status of triple
block with the winning triple. Fix any bugs.
Now you're going to use status of triple
systematically to check all the triples.
For example, Player O has won the game below, and the status of all winning triples
block finds the status of each possible triple. The computer can use this block to check for a winning triple that has either all X or all O.
map
together with some of the other blocks you have made to build the status of all winning triples
block. It should report the status of all of the possible winning triples as a list of lists, as shown above.map
.
When you use map
think:
won?
.
Put it in words: What is it that you want to check?
Are there any blocks that might be helpful for that?
true
if and only if that player has won the game.