0% found this document useful (0 votes)
8 views49 pages

Adversarial Search PPT

Chapter 5 discusses adversarial search in game playing, highlighting its importance in AI due to its reasoning challenges and the ability to compare against human players. It covers the characteristics of strategic games, the minimax algorithm, and the alpha-beta pruning technique to optimize search efficiency. The chapter emphasizes the complexity of game trees and the infeasibility of exhaustive search in games like chess, while also noting the potential for improved performance through effective move ordering.

Uploaded by

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

Adversarial Search PPT

Chapter 5 discusses adversarial search in game playing, highlighting its importance in AI due to its reasoning challenges and the ability to compare against human players. It covers the characteristics of strategic games, the minimax algorithm, and the alpha-beta pruning technique to optimize search efficiency. The chapter emphasizes the complexity of game trees and the infeasibility of exhaustive search in games like chess, while also noting the potential for improved performance through effective move ordering.

Uploaded by

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

Adversarial Search

Chapter 5

1
Game Playing

Why do AI researchers study game playing?

1. It’s a good reasoning problem, formal and


nontrivial.

2. Direct comparison with humans and other


computer programs is easy.

3
What Kinds of Games?
Mainly games of strategy with the following
characteristics:

1. Sequence of moves to play


2. Rules that specify possible moves
3. Rules that specify a payment for each
move
4. Objective is to maximize your payment
4
Games vs. Search Problems

• Unpredictable opponent  specifying a move


for every possible opponent reply

• Time limits  unlikely to find goal, must


approximate

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

computer The computer is


’s turn
Max. The opponent
opponent is Min.
’s
turn

leaf nodes At the leaf nodes, the


are utility function
evaluated is employed. Big value
means good, small is
Mini-Max Terminology
• move: a move by both players
• ply: a half-move
• utility function: the function applied to leaf nodes
• backed-up value
– of a max-position: the value of its largest successor
– of a min-position: the value of its smallest successor
• minimax procedure: search down several levels; at
the bottom level apply the utility function, back-up
values all the way up to the root node, and that node
selects the move.
9
Minimax
• Perfect play for deterministic games
• Idea: choose move to position with highest minimax value
= best achievable payoff against best play
• E.g., 2-ply game:

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?

• These nodes represent the opponent’s choice


of move.

• The computer assumes that the human will


choose that move that is of least value to the
computer.
22
Minimax algorithm
Adversarial analogue of DFS

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

– game length m≈100

– search space bm ≈ 35100 ≈ 10154

• The Universe:
– number of atoms ≈ 1078

– age ≈ 1018 seconds

– 108 moves/sec x 1078 x 1018 = 10104

• Exact solution completely infeasible 25


Alpha-Beta Procedure
• The alpha-beta procedure can speed up a
depth-first minimax search.
• Alpha: a lower bound on the value that a max
node may ultimately be assigned
v>

• Beta: an upper bound on the value that a


minimizing node may ultimately be assigned
v<
26
ma
x

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

No - this branch is guaranteed


to be worse than what max
already has
min

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); }

alpha = the highest value for MAX along the path


beta = the lowest value for MIN along the path
33
Alpha-Beta
MaxVal(state, alpha, beta){
if (terminal(state))
return utility(state);
for (s in children(state)){
child =
MinVal(s,alpha,beta); alpha =
max(alpha,child);
if (alpha>=beta)
return child;
}
return best child
(max); }

alpha = the highest value for MAX along the path


beta = the lowest value for MIN along the path
34
α=-
ma

α - the best value x β=
for max along the ∞
path β - the best value
for min along
the path α=-

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

α=- α=- α=-


mi
∞ 29 ∞
n β=- β=- β=-
29 37 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

α=- α=- α=-


mi
∞ 29 ∞
n β=- β=- β=-
29 37 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

α=- α=- α=- α=-


mi
∞ 29 ∞ 43
n β=- β=- β=- β=-
29 37 43 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

α=- α=- α=- α=-


mi
∞ 29 ∞ 43
n β=- β=- β=- β=-
29 37 43 75

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

• Good: Good moves ordered first


4 MAX
+ + +
4 3 MIN

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.

• Good move ordering improves effectiveness of pruning

• With "perfect ordering," time complexity = O(bm/2)


 doubles depth of search

• A simple example of reasoning about ‘which computations are


relevant’ (a form of metareasoning)

47
Node Ordering
Iterative deepening search

Use evaluations of the previous search for order

Also helps in returning a move in given time

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

You might also like