Tic Tac Toe Problem

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

1 State spaces

Consider the game of Tic-Tac-Toe in which two players alternate putting marks in a 3 × 3
board. One player marks crosses (referred to as Player X) and the other marks circles
(referred to as Player O). The first player to have a complete row, column or diagonal
filled in with her marks wins and the game ends. The game may also end in a draw if the
board is full but no player has 3 marks on the same line. Initially the board is empty as
in Figure a below (a dash sign represents an empty cell).

- - - - - - - - x
- - - - x - - x -
- - - - - - o o -

Figure a: Initial state Figure b: After one move Figure c: After four moves

Answer the following questions.

1. Define a non-graphical state representation for the board in Figure a above.

2. Assume Player X plays first by placing her mark as depicted in Figure b above. Use
your state representation to represent this state.

3. Assume the game reaches the state depicted in Figure c above and it is Player X’s
turn to play next. Draw the complete search tree that shows the next two plies of
the game.

2 Solution
2.1 Representation of the initial state
A non-graphical state representation for the empty board could be a 3 × 3-array, where
every row, column and diagonal represents a row, column and diagonal respectively on
the board. Each cell of the array may contain either x, or o or a dash sign (empty cell).
Let I be the initial state. It is represented as follows:
 
- - -
I= - - - 
- - -

For the sake of completeness, each state of the game should also contain the mark of the
player whose turn is next. The game assumes Player X to play first. So the initial state
is represented as a pair: I0 = (I, x).

2.2 State representation after the first move


Let M1 be the state of the board after one move. It is represented as follows.
 
- - -
M1 =  - x - 
- - -

1
After this move, it is Player O’s turn to play. So the full state at this stage is: M1 0 =
(M1 , o).

2.3 Search tree


After four moves, the game reaches the state: M4 0 = (M4 , x), where:
 
- - x
M4 =  - x - 
o o -

The complete search tree for the next two plies of the game is given in Figure iv.

x
x
o o

x x
x x x
o o o o x

o x o x x x x o x o x x
x x x x x x o x x o x x x x o
o o o o o o o o o o o x o o x o o x o o x

x x x
x x x
o o o o

x x
x
x x x o x x x x x o o x o x o x x
o x x x o x o x x x x x x x x
o o o o o o o o o o o o o o o o o o

x x o x x x x x x
o x x x o x
o o o o o o o o o

Figure iv: Search tree for two plies of the Tic-Tac-Toe game

You might also like