map
for the first time; reviewing others)map
(Al and Mary agree.)In this lab, students will continue the Tic-Tac-Toe project by teaching the computer how to detect a win or a tie. To do this, the program must remember the moves that have been made. (In a sense, the program already does have that memory, but it is spread out among the nine sprite clones representing the individual squares. Here we add a model of the board in one place, so the program can reason about it.)
The capacity to remember and analyze moves will later be used to let the program make sensible moves as a player.
map
and have a taste of its enormous power to simplify code.map
in context.item
is board, and the item number is rotated in from the items in the list {1, 2, 3}
.if then
conditionals:map
in solving this problem. (What if we were playing tic-tac-toe on a chessboard, so there would be many more winning triples? Would you still want to enumerate them in nested conditionals?)
status of all winning triples
block, it will be beneficial for them to compare the status of each winning triple to the corresponding configuration on the board. For example the eighth row of the list that the status of all winning triples
block reports is the status of the diagonal with squares {3,5,7}, namely {X, Empty, Empty}, agreeing with the board picture. map
will use the status of all winning triples
form we used to detect wins. What students should take away from this is that they have the power to manipulate data into whatever form is most useful for solving each problem that arises. Don't let them feel frustrated because it's not obvious to them ahead of time what format is best in each case; that comes with experience.There are no AP CSP standards connected to this lab.