L06 (Adversarial Search) Ori
L06 (Adversarial Search) Ori
Course Code: CSC4226 Course Title: Artificial Intelligence and Expert System
Competitive environments, in which the agents’ goals are in conflict, giving rise to
adversarial search problems—often known as games.
In AI, the most common games are of a rather specialized kind—what game theorists call
deterministic, turn-taking, two-player, zero-sum games of perfect information (such as
chess).
This means deterministic, fully observable environments in which two agents act alternately
and in which the utility values at the end of the game are always equal and opposite.
Games a Search Problem
Game ends when either Max and Min have reached a terminal state
Max must develop a strategy that determines best possible move for
each move Min makes.
Tic-Tac-Toe Revisited
Example: Two-Ply Game
Time complexity?
O(bm)
Space complexity?
O(bm) (depth-first search, generate all actions at once)
O(m) (backtracking search, generate actions one at a time)
Game Tree Size
Tic-Tac-Toe
b ≈ 5 legal actions per state on average, total of 9 plies in game.
“ply” = one action by one player, “move” = two plies.
59 = 1,953,125
9! = 362,880
exact solution quite reasonable
Is There Another Way?
Take Chess on average has:
35 branches and
usually at least 100 moves
so game space is: 35100
It must not take too long ( trade off between accuracy and
time cost).
w1f1+w2f2+……wnfn
The deeper the search the more information is available to the program
the more accurate the evaluation functions
Iterative deepening – when time runs out the program returns the deepest
completed search.
Horizon problem:
Moves that are pushed deeper into the search trees may result
in an oversight by the evaluation function.
Pruning
What is pruning?
The process of eliminating a branch of the search tree
from consideration without examining it.
Why prune?
To eliminate searching nodes that are potentially
unreachable.
To speedup the search process.
Alpha-Beta Pruning
A technique to find the optimal solution according to a
limited depth search using evaluation functions.
Gets its name from the two variables that are passed
along during the search which restrict the set of
possible solutions.
Alpha-beta: Definitions
Alpha –
the value of the best choice so far along the path for MAX.
Beta –
the value of the best choice (lowest value) so far along the
path for MIN.
Implementation
Set root node alpha to negative infinity and beta to positive infinity.
Search depth first, propagating alpha and beta values down to all
nodes visited until reaching desired depth.
We will only pass the alpha, beta values to the child nodes.
Prune whenever ≥ .
Alpha-Beta Example
α=
α= -∞
3
3
β=
β= ∞
∞
α=
α= 33
β=
β= ∞1
α= -∞
3 1
β= 3
∞
α=
α=-∞
5 α= 3
β=
β=33 β= ∞
α=
α= -∞
2
3
β=
β= ∞
∞ 3 5 1
General alpha-beta pruning
Parent node of n
Or any choice point further up
Best-Case
each player’s best move is the left-most child (i.e., evaluated first)
in practice, performance is closer to best rather than worst-case
E.g., sort moves by the remembered move values found last time.
E.g., expand captures first, then threats, then forward moves, etc.
E.g., run Iterative Deepening search, sort by value last iteration.
If there is only one legal move, this algorithm will still generate an
entire search tree.
Overlooks moves that forfeit something early for a better position later.