homework 5 - university of california, irvinewelling/teaching/271fall09/hw5_sol.pdf1.b tic-tac-toe...
TRANSCRIPT
Homework 5
Games
CompSci 171: Intro AI
1.a Tic-Tac-Toe – how many states?
Assume we always start with X:Empty: 01X: C(9,1) = 91X1O: C(9,1)C(8,1) = 722X1O: C(9,2)C(7,1) = 2522X2O: C(9,2)C(7,2) = 7563X2O: C(9,3)C(6,2) = 12603X3O: C(9,3)C(6,3) = 16804X3O: C(9,4)C(5,3) = 12604X4O: C(9,4)C(5,4) = 6305X4O: C(9,5)C(4,4) = 126Total: 1+9+72+252+756+1260+1680+1260+630+126 = 6046(This includes invalid board positions, e.g. a
board with a row of ‘X’ and another of ‘O’)
1.b Tic-Tac-Toe –depth of the complete game tree?
1stlevel: position of first X2ndlevel: position of first Y3rdlevel: position of second X4thlevel: position of second Y…Complete game: depth 9
Contains all the valid board positions from (a), assuming we always start with X
1.c Tic-Tac-Toe – game tree (depth 2)?
X
XXX
X X
X X X
(1) (2) (3) (4) (5) (6) (7) (8) (9)
Depth 1
1.c Tic-Tac-Toe – game tree (depth 2)?X
X
O
X
O
X OX O X
O
X
O
X
O
X
O
Depth 2
Depth 1(1)
1.c Tic-Tac-Toe – game tree (depth 2)?X
X
O
X
O
X OO X X
O
X
O
X
O
X
O
Depth 2
Depth 1(2)
1.c Tic-Tac-Toe – game tree (depth 2)?X
X
O
X
O
O XO X X
O
X
O
X
O
X
O
Depth 2
Depth 1(3)
1.c Tic-Tac-Toe – game tree (depth 2)?
X
X O
O
X
O
X
O
X X O X
O
X
O
X
O
Depth 2
Depth 1(4)
1.c Tic-Tac-Toe – game tree (depth 2)?
X
O X
O
X
O
X
O
X X O X
O
X
O
X
O
Depth 2
Depth 1(5)
1.c Tic-Tac-Toe – game tree (depth 2)?
X
O X
O
X
O
X
O
X O X X
O
X
O
X
O
Depth 2
Depth 1(6)
1.c Tic-Tac-Toe – game tree (depth 2)?
X
O
X
O
X
O
X
O
X
O
X
O
X X O X O
Depth 2
Depth 1(7)
1.c Tic-Tac-Toe – game tree (depth 2)?
X
O
X
O
X
O
X
O
X
O
X
O
X O X X O
Depth 2
Depth 1(8)
1.c Tic-Tac-Toe – game tree (depth 2)?
X
O
X
O
X
O
X
O
X
O
X
O
X O X O X
Depth 2
Depth 1(9)
1.d Tic-Tac-Toe – Evaluation of the positions at level 2
The linear evaluation function:
3*X2 + X1 – (3*O2 + O1)
For tree of depth 2, there is one X and one O
on the board. The linear evaluation function:
X1 – O1
1.d Tic-Tac-Toe – game tree (depth 2)?X
X
O
X
O
X OX O X
O
X
O
X
O
X
O
Depth 2
Depth 1(1)
X=2Y=1F=2-1 =1
F=2-2 F=2-1 F=2-3 F=3-2 F=2-2 F=3-2 F=2-2F=0 F=1 F=-1 F=1 F=0 F=1 F=0
min
1.d Tic-Tac-Toe – game tree (depth 2)?X
X
O
X
O
X OO X X
O
X
O
X
O
X
O
Depth 2
Depth 1(2)
F=-1 F=-1 F=1 F=-2 F= 0 F=-1 F=0 F=-1
1.d Tic-Tac-Toe – game tree (depth 2)?X
X
O
X
O
O XO X X
O
X
O
X
O
X
O
Depth 2
Depth 1(3)
F=0 F=1 F=1 F=-1 F= 0 F=0 F=1 F=0
1.d Tic-Tac-Toe – game tree (depth 2)?
X
X O
O
X
O
X
O
X X O X
O
X
O
X
O
Depth 2
Depth 1(4)
F=-1 F=0 F=-1 F=-2 F= 0 F=-1 F=0 F=-1
1.d Tic-Tac-Toe – game tree (depth 2)?
X
O X
O
X
O
X
O
X X O X
O
X
O
X
O
Depth 2
Depth 1(5)
F=1 F=2 F=1 F=2 F= 2 F=1 F=2 F=1
1.d Tic-Tac-Toe – game tree (depth 2)?
X
O X
O
X
O
X
O
X O X X
O
X
O
X
O
Depth 2
Depth 1(6)
F=-1 F=0 F=-1 F=0 F= -2 F=-1 F=0 F=-1
1.d Tic-Tac-Toe – game tree (depth 2)?
X
O
X
O
X
O
X
O
X
O
X
O
X X O X O
Depth 2
Depth 1(7)
F=0 F=1 F=0 F=1 F=-1 F=1 F=1 F=0
1.d Tic-Tac-Toe – game tree (depth 2)?
X
O
X
O
X
O
X
O
X
O
X
O
X O X X O
Depth 2
Depth 1(8)
F=-1 F=0 F=-1 F=0 F= -2 F=-1 F=-1 F=-1
1.d Tic-Tac-Toe – game tree (depth 2)?
X
O
X
O
X
O
X
O
X
O
X
O
X O X O X
Depth 2
Depth 1(9)
F=0 F=1 F=0 F=1 F= -1 F=1 F=0 F=1
1.d Tic-Tac-Toe – game tree (depth 2)?
X
XXX
X X
X X X
-1 -2 -1 -2 1 -2 -1 -2 -1
1.e Tic-Tac-Toe – pruned subtrees
101
-11010
-1-11
-20101
011
-10010
-10
-1-20
-10
-1
12122121
-10
-10
-2-101
0101
-1110
-10
-10
-2-1-1-1
0101
-1101
1.e Tic-Tac-Toe – pruned subtrees (L-R)
101
-11010
-1-11
-20101
011
-10010
-10
-1-20
-10
-1
12122121
-10
-10
-2-101
0101
-1110
-10
-10
-2-1-1-1
0101
-1101
-1
-1
1.e Tic-Tac-Toe – pruned subtrees (L-R)
101
-11010
-1-11
-20101
011
-10010
-10
-1-20
-10
-1
12122121
-10
-10
-2-101
0101
-1110
-10
-10
-2-1-1-1
0101
-1101
-1 -1
-1
1.e Tic-Tac-Toe – pruned subtrees (L-R)
101
-11010
-1-11
-20101
011
-10010
-10
-1-20
-10
-1
12122121
-10
-10
-2-101
0101
-1110
-10
-10
-2-1-1-1
0101
-1101
-1 -1
-1
-1
1.e Tic-Tac-Toe – pruned subtrees (L-R)
101
-11010
-1-11
-20101
011
-10010
-10
-1-20
-10
-1
12122121
-10
-10
-2-101
0101
-1110
-10
-10
-2-1-1-1
0101
-1101
-1 -1
-1
-1 -1
1.e Tic-Tac-Toe – pruned subtrees (L-R)
101
-11010
-1-11
-20101
011
-10010
-10
-1-20
-10
-1
12122121
-10
-10
-2-101
0101
-1110
-10
-10
-2-1-1-1
0101
-1101
-1 -1
1
-1 -1 1
1.e Tic-Tac-Toe – pruned subtrees (L-R)
101
-11010
-1-11
-20101
011
-10010
-10
-1-20
-10
-1
12122121
-10
-10
-2-101
0101
-1110
-10
-10
-2-1-1-1
0101
-1101
-1 -1
1
-1 -1 1 -1
1.e Tic-Tac-Toe – pruned subtrees (L-R)
101
-11010
-1-11
-20101
011
-10010
-10
-1-20
-10
-1
12122121
-10
-10
-2-101
0101
-1110
-10
-10
-2-1-1-1
0101
-1101
-1 -1
1
-1 -1 1 -1 0
1.e Tic-Tac-Toe – pruned subtrees (L-R)
101
-11010
-1-11
-20101
011
-10010
-10
-1-20
-10
-1
12122121
-10
-10
-2-101
0101
-1110
-10
-10
-2-1-1-1
0101
-1101
-1 -1
1
-1 -1 1 -1 0 -1
1.e Tic-Tac-Toe – pruned subtrees (L-R)
101
-11010
-1-11
-20101
011
-10010
-10
-1-20
-10
-1
12122121
-10
-10
-2-101
0101
-1110
-10
-10
-2-1-1-1
0101
-1101
-1 -1
1
-1 -1 1 -1 0 -1 0
1.e Tic-Tac-Toe – pruned subtrees (R-L)
101
-11010
-1-11
-20101
011
-10010
-10
-1-20
-10
-1
12122121
-10
-10
-2-101
0101
-1110
-10
-10
-2-1-1-1
0101
-1101
-1
-1
1.e Tic-Tac-Toe – pruned subtrees (R-L)
101
-11010
-1-11
-20101
011
-10010
-10
-1-20
-10
-1
12122121
-10
-10
-2-101
0101
-1110
-10
-10
-2-1-1-1
0101
-1101
-1 -1
-1
1.e Tic-Tac-Toe – pruned subtrees (R-L)
101
-11010
-1-11
-20101
011
-10010
-10
-1-20
-10
-1
12122121
-10
-10
-2-101
0101
-1110
-10
-10
-2-1-1-1
0101
-1101
-1 -1
-1
-1
1.e Tic-Tac-Toe – pruned subtrees (R-L)
101
-11010
-1-11
-20101
011
-10010
-10
-1-20
-10
-1
12122121
-10
-10
-2-101
0101
-1110
-10
-10
-2-1-1-1
0101
-1101
-1 -1
-1
-1-1
1.e Tic-Tac-Toe – pruned subtrees (R-L)
101
-11010
-1-11
-20101
011
-10010
-10
-1-20
-10
-1
12122121
-10
-10
-2-101
0101
-1110
-10
-10
-2-1-1-1
0101
-1101
-1 -1
1
-1-11
1.e Tic-Tac-Toe – pruned subtrees (R-L)
101
-11010
-1-11
-20101
011
-10010
-10
-1-20
-10
-1
12122121
-10
-10
-2-101
0101
-1110
-10
-10
-2-1-1-1
0101
-1101
-1 -1
1
-1-11-1
1.e Tic-Tac-Toe – pruned subtrees (R-L)
101
-11010
-1-11
-20101
011
-10010
-10
-1-20
-10
-1
12122121
-10
-10
-2-101
0101
-1110
-10
-10
-2-1-1-1
0101
-1101
-1 -1
1
-1-11-1-1
1.e Tic-Tac-Toe – pruned subtrees (R-L)
101
-11010
-1-11
-20101
011
-10010
-10
-1-20
-10
-1
12122121
-10
-10
-2-101
0101
-1110
-10
-10
-2-1-1-1
0101
-1101
-1 -1
1
-1-11-1-1-1
1.e Tic-Tac-Toe – pruned subtrees (R-L)
101
-11010
-1-11
-20101
011
-10010
-10
-1-20
-10
-1
12122121
-10
-10
-2-101
0101
-1110
-10
-10
-2-1-1-1
0101
-1101
-1 -1
1
-1-11-1-1-1-1
1.f Tic-Tac-Toe – Property of leaf values
The leaf values should be ordered from lowest
to highest from left to right.
2. Min-Max
3 8 7 1 5 8 10
3 1 8
8MAX
MAX
MIN
2.a First (MAX) player choice
Max: D = 83 1 8
2.b Which nodes would not need be examined
2
2Min:
Max:
Max:2
2.b Which nodes would not need be examined
3
3Min:
Max:
Max:3
2.b Which nodes would not need be examined
8
3Min:
Max:
8 > 3
Max:3
2.b Which nodes would not need be examined
8
3Min:
Max:
8 > 3
Max:3
2.b Which nodes would not need be examined
7
3Min:
Max:
7 > 3
Max:3
2.b Which nodes would not need be examined
7
3Min:
Max:
7 > 3
Max:3
2.b Which nodes would not need be examined
0
3Min:
Max:
0
Max:3
2.b Which nodes would not need be examined
1
3Min:
Max:
1
Max:3
3 > 1
2.b Which nodes would not need be examined
3Min:
Max:
1
Max:3
3 > 1
2.b Which nodes would not need be examined
3Min:
Max:
1
Max:3
3 > 1
2.b Which nodes would not need be examined
8
3Min:
Max:
81
Max:8
2.b Which nodes would not need be examined
8
3Min:
Max:
81
Max:8
2.b Which nodes would not need be examined
10
3Min:
Max:
81
10 > 8
Max:8
2.b Which nodes would not need be examined
10
3Min:
Max:
81
10 > 8
Max:8
2.b Which nodes would not need be examined
3Min:
Max:
81