Professional Documents
Culture Documents
Tic-Tac-Toe (Ai)
Tic-Tac-Toe (Ai)
Tic-Tac-Toe (Ai)
It is two players, X and O, game who take turns marking the spaces
in a 3×3 grid. The player who succeeds in placing three respective
marks in a horizontal, vertical, or diagonal row wins the game.
A total of 3^9 = 19,683 combinations using three symbols can be
achieved. All of these combinations are stored in a vector. Whenever
a move is played by the opponent, the CPU looks for all such
possible combinations in the vector that can be achieved as the next
move to that corresponding move. One of such combinations is
picked up, and board is updated, with the new move chosen.
D AT A S T R U C T U R E
1 2 3
4 5 6
7 8 9
0 – Blank square
1 – Filled with X
2 – Filled with O
ALGORITHM
To make a move, do the following:
The selected vector represents the way the board will look
after the move
0 000000000 000010000
1 000000001 020000001
2 000000002 000100002
3 000000010 002000010
ADVANTAGES
The program is very efficient in terms of time
DISADVANTAGES
Lot of space is required to store the move table.