Adversarial Search PPT
Adversarial Search PPT
Chapter 5
1
Game Playing
3
What Kinds of Games?
Mainly games of strategy with the following
characteristics:
5
Two-Player
Opponent’s Game
Move
Generate New
Position
Gam ye
e s
Over
? n
Generate o
Successors
Evaluate
Successors
Move to Highest-Valued
Successor
no Gam
yes e
Over
? 6
Games as Adversarial Search
• States:
– board configurations
• Initial state:
– the board position and which player will move
• Successor function:
– returns list of (move, state) pairs, each indicating a legal
move and the resulting state
• Terminal test:
– determines when the game is over
• Utility function:
–gives a numeric value in terminal
states (e.g., -1, 0, +1 for loss, tie, win)
7
Game Tree (2-player, Deterministic,
Turns)
computer
’s turn
opponent
’s turn
10
ma
x
mi
n
ma
x
mi
n
11
© Patrick
ma
x
mi
n
ma
x
mi
n
12
© Patrick
ma
x
mi
n
ma
x
mi
n
13
© Patrick
ma
x
mi
n
ma
x
mi
n
14
© Patrick
ma
x
mi
n
ma
x
mi
n
15
© Patrick
ma
x
mi
n
ma
x
mi
n
16
© Patrick
ma
x
mi
n
ma
x
mi
n
17
© Patrick
ma
x
mi
n
ma
x
mi
n
18
© Patrick
ma
x
mi
n
ma
x
mi
n
19
© Patrick
ma
x
mi
n
ma
x
mi
n
20
© Patrick
ma
x
mi
n
ma
x
mi
n
21
© Patrick
Minimax Strategy
• Why do we take the min value every other
level of the tree?
23
Properties of Minimax
• Complete?
– Yes (if tree is finite)
• Optimal?
– Yes (against an optimal opponent)
– No (does not exploit opponent weakness against suboptimal opponent)
• Time complexity?
– O(bm)
• Space complexity?
– O(bm) (depth-first exploration)
24
Good Enough?
• Chess:
– branching factor b≈35
• The Universe:
– number of atoms ≈ 1078
mi
n
ma
x
mi
n
27
ma
x
mi
n
ma
x
mi
n
28
ma
x
mi
n
ma
x
mi
n
29
ma
x
mi
n
ma
x
mi
n
30
© Patrick
ma
x
mi
n
max
Do we need to
check this node?
min
?? 3
1
ma
x
mi
n
max
X 3
2
Alpha-Beta
MinVal(state, alpha, beta){
if (terminal(state))
return utility(state);
for (s in children(state)){
child =
MaxVal(s,alpha,beta); beta =
min(beta,child);
if (alpha>=beta)
return child;
}
return best child
(min); }
α=-
ma ∞
x β=
∞
α=-
mi
∞
n β=8
4
35
α=-
ma
∞
α - the best value x β=
for max along the ∞
path β - the best value
for min along
the path α=-
∞
min β=
∞
α=-
ma 29
x β=∞
α=- α=-
mi
∞ 29
n β=- β=∞
29
36
α=-
ma
∞
α - the best value x β=
for max along the ∞
path β - the best value
for min along
the path α=-
∞
min β=
∞
α=-
ma 29
x β=∞
α=- α=-
mi
∞ 29
n β=- β=-
29 37
37
α=-
ma
∞
α - the best value x β=
for max along the ∞
path β - the best value
for min along
the path α=-
∞
min β=
∞
α=-
ma 29
x β=∞
β <=
α
mi α=-
∞
α=-
29
prun
n β=-
29
β=-
37
e!
X 38
α=-
ma
∞
α - the best value x β=
for max along the ∞
path β - the best value
for min along
the path α=-
∞
min β=-
29
α=- α=-
ma 29 ∞
x β=∞ β=-
29
X 39
α=-
ma
∞
α - the best value x β=
for max along the ∞
path β - the best value
for min along
the path α=-
∞
min β=-
29
α=- α=-
ma 29 ∞
x β=∞ β=-
29
X 40
α=-
ma
∞
α - the best value x β=
for max along the ∞
path β - the best value
for min along
the path α=-
∞
min β=-
29
α=- α=-
ma 29 43
x β=∞ β=-
29
X 41
α=-
ma
∞
α - the best value x β=
for max along the ∞
path β - the best value
for min along
the path α=-
∞
min β=-
29
α=- α=-
ma 29 43
x β=∞ β=-
29
β <=
α
mi α=-
∞
α=-
29
α=-
∞
α=-
43
prun
n β=-
29
β=-
37
β=-
43
β=-
75
e!
X X 42
α=-
ma
43
α - the best value x β=∞
for max along the
path β - the best value
for min along
the path α=-
∞
min β=-
43
α=- α=-
ma 29 43
x β=∞ β=-
29
X X 43
α=-
ma
43
α - the best value x β=∞
for max along the
path β - the best value
for min along
the path α=-
43
min β=∞
α=-
ma
43
x β=∞
α=- α=-
mi
43 43
n β=- β=5
21 8
X X 44
α=-
ma
43
α - the best value x β=∞
for max along the
path β - the best value
for min along
the path α=- β <=
43
min β=- α
46
prun
e!
ma
x
α=-
43 X
β=∞
mi
n
α=-
43
α=-
43 X
β=- β=-
21 46
X
X X X X X X45
Bad and Good Cases for Alpha-Beta Pruning
• Bad: Worst moves encountered first
4 MAX
+ + +
2 3 4 MIN
+----+----+ +----+----+ +----+----+
6 4 2 7 5 3 8 6 MAX
+--+ +--+ +--+ +-+-+
4 +--+ +--+ +--+ +--+ +--+--+
6 5 4 3 2 1137 4 5 2 3 8 2 1 61 2 4
2 MAX
+--+
+ +--+
+ +--+
+ +--+
+ + +
+ + +
4 42 6 6 x 88 x 3 2 x x
2 x x
• +-+-+
If we can order moves, we can get more benefit from alpha-beta pruning
1 21
Properties of α-β
• Pruning does not affect final result. This means that it gets the
exact same result as does full minimax.
47
Node Ordering
Iterative deepening search
48
Good Enough?
• Chess: The universe
– branching factor b≈35 can play chess
- can we?
– game length m≈100
– search space bm/2 ≈ 3550 ≈ 1077
• The Universe:
– number of atoms ≈ 1078
– age ≈ 1018 seconds
– 108 moves/sec x 1078 x 1018 = 10104 4
9