Note that this is lab is a continuation of Unit 3 Lab 3: Tic-Tac-Toe
Board is the user interface's representation of who has moved where on the board, a straightforward list of nine squares, each of which can be X, O, or the square number to indicate empty. Status of all winning triples represents the same board status, so in a sense it's redundant, but it presents that information in a form that's structured for the decision of the computer's move. One could say that board is for the conversation between the user and the program, while status of all winning triples is for the program thinking about its strategy.broadcast command, when I receive event, and message reporter to implement a computer player.winning triple and winning square blocks are the most challenging parts of this page. Help students prepare by making sure they:
winning triple)winning triple and the page where they first learned about keepYou may also choose to have them each write out their approach to 'determining if a player can win on their next turn' individually after they discuss it and before they start coding.
winning square for, a function whose input is "X" or "O" and whose return value is a number from 1 to 9, or 0 if there is no winning square on this move. Some students will want to jump right into coding, and will have an impossibly long sequence of if board=(some list) report (some number). (There are 39=19,683 possible board configurations, so it would be a very long procedure if they try to cover every one.) But finding a winning triple is just find first from the list of winning triples, where the predicate function is, e.g., "this triple has two O squares and no X squares." And then the actual winning square is find first looking for a number in the winning triple. The resulting program isn't quite a one-liner because it has to check for the case in which there is no winning triple, but it's hardly any code compared to the sequence of if statements.
Next year: need to rename "The procedure
TicTacToe wins" --MF, 6/18/18