You are on page 1of 34

Adversarial Search

(Games)
Reading: Chapter 5
In which we examine the problems that arise when we try to plan
ahead in a world where other agents are planning against us.
Outline
• Minimax Algorithm
• α-β pruning
• Approximate, real-time decisions
• Expectimax
Minimax Algorithm
Games vs. search problems
• Environment characteristics
– Fully observable (Partially observable)
– Discrete
– Deterministic (Stochastic)
– Benign Adversarial
• "Unpredictable" opponent  specifying a
move for every possible opponent reply
• Time limits  unlikely to find goal, must
approximate

Game tree (2-player,
deterministic, turns)
Example: Trivial Game
• Lets consider a trivial game that ends after one move
each by MAX and MIN
• Tree is one move deep (2 ply game)
• Utilities in the terminal state (range from 2 to 14)
Minimax Algorithm
• Idea: choose the move to maximize/minimize minimax
value = best achievable payoff against best play
Example
Example continued
1. Which direction will the Max player
choose to go at node A?
2. What is the minimax value of node A?
3. In which order you visited the nodes to
compute the minimax value? (write the
nodes in that order)
Example Continued
1. node D.

1. node A will be 6.

1. Sequence :
K,S,T,L,E,M,F,B,U,V,N,O,G,W,X,P,Q,H,C,I,Y,Z,R,J,D,A.
Properties of minimax Algorithm
Minimax algorithm performs a complete depth-first
exploration of the game tree

• Complete? Yes (if tree is finite)


• Optimal? Yes (against an optimal opponent)
• Time complexity? O(bm)
• Space complexity? O(bm) (depth-first exploration)

• For chess, b ≈ 35, m ≈100 for "reasonable" games


 exact solution completely infeasible
• Next we are going to look at ways to improve the time
complexity

α-β pruning Algorithm
α-β pruning example
α-β pruning example
α-β pruning example
α-β pruning example
α-β pruning example
Properties of α-β
• Pruning does not affect final result

• Good move ordering improves effectiveness of pruning


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


 doubles depth of search
Example
Example Continued
This time apply alpha-beta pruning
• Which direction will the Max player choose
to go at node A?
• In which order you visited the nodes to
compute the minimax value using alpha
beta pruning? (write the nodes in that
order)
Example Continued
• The max player will choose to go to node D.
• Sequence : K,S,L,E,M,F,B,U,V,N,O,G,C,I,Y,Z,R,J,D,A.
Imperfect Real Time Decisions
Imperfect Real Time Decisions
Problem: In realistic games, cannot search to leaves!
• Minimax algorithm generates entire game search space
• Alpha-beta algorithm allows us to prune large parts of
search space
– Still has to search all the way to the terminal states

Solution:
-Replace utility function by heuristic/Evaluation function
-Replace terminal test by cut off test
Evaluation functions
Cutting off search
MinimaxCutoff is identical to MinimaxValue except
1. Terminal? is replaced by Cutoff?
2. Utility is replaced by Eval

4-ply lookahead is a hopeless chess player!


– 4-ply ≈ human novice
– 8-ply ≈ typical PC, human master
– 12-ply ≈ Deep Blue, Kasparov

– Deep Blue -> Some lines of search upto 40 ply


deep

Implementation
Expectimax
Example
Example
Summary
• Games are fun to work on!

• They illustrate several important points
about AI

• perfection is unattainable  must
approximate

You might also like