Artificial Intelligence: Adversarial Search
Artificial Intelligence: Adversarial Search
Adversarial Search
Adversarial Search
• Adversarial search problems ⌘ games
In the case of one player, nothing will prevent Max from winning
(choose the path that leads to the desired utility here 1), unless
there is another player who will do everything to make Max lose,
let’s call him Min (the Mean :))
Adversarial search: minimax
• Two players: Max and Min
• Players alternate turns
• Max moves first
• Max maximizes results
• Min minimizes the result
• Compute each node’s minimax value’s the best achievable util-
ity against an optimal adversary
• Minimax value ⌘ best achievable payo↵ against best play
Minimax example
Adversarial search: minimax
• Find the optimal strategy for Max:
8
>
< U tility(s) if Terminal-test(s)
maxa2Actions(s) minimax(Result(s,a)) if Player(s) = Max
>
: mina2Actions(s) minimax(Result(s,a)) if Player(s) = Min
The minimax algorithm
Minimax example
Minimax example
Minimax example
Minimax example
Minimax example
Properties of minimax
• Optimal (opponent plays optimally) and complete (finite tree)
• DFS time: O(bm)
• DFS space: O(bm)
– Tic-Tac-Toe
⇤ ⇡ 5 legal moves on average, total of 9 moves (9 plies).
⇤ 59 = 1, 953, 125
⇤ 9! = 362, 880 terminal nodes
– Chess
⇤ b ⇡ 35 (average branching factor)
⇤ d ⇡ 100 (depth of game tree for a typical game)
⇤ bd ⇡ 35100 ⇡ 10154 nodes
– Go branching factor starts at 361 (19X19 board)
Case of limited resources
• Problem: In real games, we are limited in time, so we can’t
search the leaves.
• Solution:
1. Replace terminal utilities with an evaluation function for
non-terminal positions.
2. Use Iterative Deepening Search (IDS).
3. Use pruning: eliminate large parts of the tree.
↵ pruning
= max(3, min(2, X, Y ), 2)
↵ pruning
= max(3, min(2, X, Y ), 2)
= max(3, min(2, X, Y ), 2)
=3
↵ pruning
= max(3, min(2, X, Y ), 2)
=3
Minimax decisions are independent of the values of X and Y .
↵ pruning
• Strategy: Just like minimax, it performs a DFS.
↵ pruning
• Strategy: Just like minimax, it performs a DFS.
• Parameters: Keep track of two bounds
– ↵: largest value for Max across seen children (current lower
bound on MAX’s outcome).
– : lowest value for MIN across seen children (current upper
bound on MIN’s outcome).
↵ pruning
• Strategy: Just like minimax, it performs a DFS.
• Parameters: Keep track of two bounds
– ↵: largest value for Max across seen children (current lower
bound on MAX’s outcome).
– : lowest value for MIN across seen children (current upper
bound on MIN’s outcome).
• Initialization: ↵ = 1, =1
↵ pruning
• Strategy: Just like minimax, it performs a DFS.
• Parameters: Keep track of two bounds
– ↵: largest value for Max across seen children (current lower
bound on MAX’s outcome).
– : lowest value for MIN across seen children (current upper
bound on MIN’s outcome).
• Initialization: ↵ = 1, =1
• Propagation: Send ↵, values down during the search to be
used for pruning.
– Update ↵, values by propagating upwards values of ter-
minal nodes.
– Update ↵ only at Max nodes and update only at Min
nodes.
↵ pruning
• Strategy: Just like minimax, it performs a DFS.
• Parameters: Keep track of two bounds
– ↵: largest value for Max across seen children (current lower
bound on MAX’s outcome).
– : lowest value for MIN across seen children (current upper
bound on MIN’s outcome).
• Initialization: ↵ = 1, =1
• Propagation: Send ↵, values down during the search to be
used for pruning.
– Update ↵, values by propagating upwards values of ter-
minal nodes.
– Update ↵ only at Max nodes and update only at Min
nodes.
• Pruning: Prune any remaining branches whenever ↵ .
↵ pruning
• If ↵ is better than a for Max, then Max will avoid it, that is
prune that branch.
• If is better than b for Min, then Min will avoid it, that is
prune that branch.
↵ pruning
↵ pruning
↵ pruning
↵ pruning
↵ pruning
↵ pruning
↵ pruning
↵ pruning
Move ordering
For a state s:
Expectiminimax(s) =
8
> U tility(s) if Terminal-test(s)
<
maxa2Actions(s) Expectiminimax(Result(s,a)) if Player(s) = Max
>
: P a2Actions(s) Expectiminimax(Result(s,a))
min if Player(s) = Min
r P (r) Expectiminimax(Result(s,r)) if Player(s) = Chance
Where r represents all chance events (e.g., dice roll), and Re-
sult(s,r) is the same state as s with the result of the chance event
is r.
Games: conclusion
• Games are modeled in AI as a search problem and use heuristic
to evaluate the game.
• Minimax goes all the way down the tree which is not practical
give game time constraints.