TicTacToe - Game Design
Before writing the interface functions to support two-player Tic Tac Toe,
we need to specify the variables used to control the game.
One new data type is declared: PlayerType. Player type can have the
following values: X, O, and PNONE. PlayerType is used in the game board.
The following variables are used in our two-player Tic Tac Toe game:
-
board[3][3], an array of PlayerType. Initially, all
locations in the board array are set to PNONE. When a player
makes a move, the player's symbol (X or O) is placed in the
board array. For example, if an X is placed in the center
square, board[1][1] is set to X.
-
winner, a PlayerType. Initially, winner is set to PNONE.
When someone wins, winner is set to the character of the winner.
-
x_turn, a boolean. x_turn is true if it is X's turn to
play, and false if it is O's turn to play.
-
move_count, an integer. Initially, move_count is 0.
Every time a player makes a move, move_count increases by 1.
-
last_move, an integer. last_move is used to store the
row and column of the most recent move. last_move is computed
as follows: if the player moved in row r and column c, then
last_move = 3*r + c.
Together, these variables define the game state.