0% found this document useful (0 votes)
69 views14 pages

Tic-Tac-Toe - non-AI and AI Technique-Slide Handouts

Uploaded by

Maaz Sayyed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views14 pages

Tic-Tac-Toe - non-AI and AI Technique-Slide Handouts

Uploaded by

Maaz Sayyed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Tic-Tac-Toe

Non-AI and AI technique


Dr. Priyadarshan Dhabe,
Ph.D (IIT Bombay)
How to play tic-tac-toe?
Players Symbol
P1 X
P2 O
Initial Board

Turn of P1- will put one X in any blank cell


Turn of P2- will put one O in any blank cell
P1 &P2- Play alternate turns
Winning position-
P1- will try to put all X in any row, column
or diagonal
P2- will try to put all O’s in any row, column
or diagonal
Max Turns-9
How to play tic-tac-toe?

O
Winning position of P2
O

X
Winning position of P1
X

X
How to play tic-tac-toe using
Computer ?
• Either P1 or P2 will be played by computer
• Computer can use two Techniques to play this
game by
– Non-AI technique
– AI technique
Representation of board position in
computer memory

0 1 2

1. Using 3x 3 Matrix 3 4 5

6 7 8

2. Using 9 element vector

0 1 2 3 4 5 6 7 8
Non-AI technique
O O
• Using rules X

For calculations use following values to represent


- Blank- 0 (Zero)
- X- 1 (one) O 2 O O
X O 1 O
-O-2 (Two)
O O O

Vector representation

2 0 0 0 1 0 0 0 0
Non-AI technique
• System will prepare a rule base of 3^ 9 rules
like O O
X

Each 9 element vector is considered as base 3 number to


provide an index in rule base
2 0 0 0 1 0 0 0 0

index = 2 x38 + 0 x37 + 0 x36 + 0 x35 + 1x34 + 0 x33 + 0 x32 + 0 x31 + 0 x30
= 2 x38 + 1x34 = 2 x6561 + 1x81 = 13203 < 39 = 19683
Non-AI technique
• How to use index?

Index Vector V
1 [000,000,000]

3^9 […………………..]
Tic-Tac-Toe game tree

O O
………....
OO

O O X O
X
X ………....
Tic-Tac-Toe AI technique

Design two functions


1. Possible move generator
2. Node evaluator

• How to select the best possible move?- using


scores
Winning- 60
Blocking- 50
Else- No of rows+ cols+ diagonals blocked from winning our
opponent
Possible move generator
X O X-2
O-1
O O Next Turn X
X

2 1 0 1 0 1 0 2 0

4 X 9 element matrix
2 1 2 1 0 1 0 2 0

2 1 0 1 2 1 0 2 0

2 1 0 1 0 1 2 2 0

2 1 0 1 0 1 0 2 2
Find all possible moves from the given state and choose
best one if it is turn of player X

X O

O O

X
• 50,3, 3,3
Find all possible moves from the given state and
choose best one if it is turn of player O

X O

O X O

You might also like