Adversarial search deals with competitive environments where agents have conflicting goals. Used in two-player zero-sum games like chess, checkers, tic-tac-toe.
Zero-sum game: One player’s gain is the other’s loss.
| Term | Meaning |
|---|---|
| MAX player | Wants to maximize the utility |
| MIN player | Wants to minimize the utility |
| Terminal state | End of game |
| Utility function | Numeric value of terminal state |
| Ply | One level in game tree |
Minimax computes the optimal strategy for MAX assuming MIN plays optimally.
function MINIMAX-VALUE(state):
if TERMINAL-TEST(state):
return UTILITY(state)
if MAX's turn:
return max over successors of MINIMAX-VALUE(successor)
if MIN's turn:
return min over successors of MINIMAX-VALUE(successor)
MAX
/ \
MIN MIN
/ \ / \
+1 -1 0 +1
MAX chooses: max(min(+1,-1), min(0,+1))
= max(-1, 0)
= 0
| Property | Value |
|---|---|
| Complete? | Yes (finite game tree) |
| Optimal? | Yes (against optimal opponent) |
| Time Complexity | O(b^m) |
| Space Complexity | O(bm) |
Problem: Exponential time — chess has ~35^80 nodes. Cannot search entire tree.
Improves minimax by pruning branches that cannot affect the final decision.
function ALPHA-BETA(state, α, β, player):
if TERMINAL(state):
return UTILITY(state)
if player = MAX:
v = -∞
for each successor s:
v = max(v, ALPHA-BETA(s, α, β, MIN))
α = max(α, v)
if α ≥ β: break ← β cutoff
return v
if player = MIN:
v = +∞
for each successor s:
v = min(v, ALPHA-BETA(s, α, β, MAX))
β = min(β, v)
if β ≤ α: break ← α cutoff
return v
MAX (α=-∞, β=+∞)
/ \
MIN(3) MIN
/ | \ / \
3 5 2 [pruned]
After left subtree: α=3
At right MIN node: first child = 1 < α=3 → prune rest
| Ordering | Nodes Examined |
|---|---|
| Worst case | O(b^m) — no pruning |
| Random | O(b^(3m/4)) |
| Best case | O(b^(m/2)) — effective branching factor √b |
Best case: With perfect move ordering, alpha-beta searches twice as deep as minimax in the same time!
A CSP is defined by:
Goal: Find assignment of values to variables satisfying all constraints.
Variables: WA, NT, Q, NSW, V, SA, T
Domains: {Red, Green, Blue}
Constraints: Adjacent regions must have different colors
WA ≠ NT, WA ≠ SA
NT ≠ Q, NT ≠ SA
Q ≠ NSW, Q ≠ SA
NSW ≠ V, NSW ≠ SA
V ≠ SA
Solution: WA=Red, NT=Green, Q=Red, NSW=Green, V=Red, SA=Blue, T=Red
function BACKTRACKING(assignment, csp):
if assignment is complete: return assignment
var = SELECT-UNASSIGNED-VARIABLE(csp)
for each value in ORDER-DOMAIN-VALUES(var, csp):
if value consistent with assignment:
add {var=value} to assignment
result = BACKTRACKING(assignment, csp)
if result ≠ failure: return result
remove {var=value} from assignment
return failure
Arc Consistency (AC-3):
X → Y is arc consistent if for every value in Domain(X),
there exists a value in Domain(Y) satisfying the constraint.
Short Answer (2 marks each)
Long Answer (8 marks each)
Think & Apply
Leaf values (left to right): 3, 5, 2, 9, 1, 4, 8, 6