Tic-Tac-Toe (Ai)

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 10

TIC-TAC-TOE (Using Vectors)

Presented by: Pratyusha Bhattacharjee

Cse/3rd year/5th sem/12000120011


INTRODUCTION TO TIC TAC TOE

 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

 BOARD – Consider a board having nine(9) elements There positions


are as follows –

1 2 3
4 5 6
7 8 9

 Who ever starts the game first


Will always start with ‘X’
D AT A S T R U C T U R E ( c o n t . )

 Computer may play as ‘X’ or ‘O’ player.

 Each element will contain:

0 – Blank square
1 – Filled with X
2 – Filled with O
ALGORITHM
To make a move, do the following:

 View the vector (board) as a ternary number and convert it to its


corresponding decimal number.
 Use the computed number as an index into the MT and access the
vector stored there.

The selected vector represents the way the board will look
after the move

 Set board equal to that vector


M O V E TA B L E ( M T )
MT is a vector of 39 elements, each element of which is a nine element
vector representing board position.
Total of 39 (19683) elements in MT

Index Current Board Position New Board Position

0 000000000 000010000

1 000000001 020000001

2 000000002 000100002

3 000000010 002000010
ADVANTAGES
 The program is very efficient in terms of time

 It could play optimal game.

DISADVANTAGES
 Lot of space is required to store the move table.

 Lot of work to specify all the entries in move table

 It is highly error prone as the data is voluminous

 Not intelligent at all


CODE
OUTPUT
THANK YOU

You might also like