∑GATE DA Atlas

Adversarial Search — Minimax, Alpha–Beta Pruning and Expectimax

Games as search problems (deterministic, zero-sum, perfect information), game trees and the minimax algorithm, alpha–beta pruning traced step by step with the effect of move ordering, depth-limited search with evaluation functions, expectimax for games of chance, and a glimpse of Monte Carlo tree search.

Section 79 practice questions

Classical game playing considers two-player, turn-taking, deterministic, perfect-information, zero-sum games (chess, checkers, Go, tic-tac-toe). A game is a search problem with:

  • initial state, PLAYER(s)\text{PLAYER}(s) (whose move), ACTIONS(s)\text{ACTIONS}(s), RESULT(s,a)\text{RESULT}(s, a);
  • a terminal test and a utility for terminal states (e.g. +1+1 win, 00 draw, −1-1 loss for MAX).

MAX tries to maximise the utility; MIN tries to minimise it. Unlike ordinary search, the agent needs a strategy — a move for every possible reply.

Minimax

MINIMAX(s)={UTILITY(s)terminalmax⁡aMINIMAX(RESULT(s,a))MAX to movemin⁡aMINIMAX(RESULT(s,a))MIN to move\text{MINIMAX}(s) = \begin{cases}\text{UTILITY}(s) & \text{terminal}\\ \max_a\text{MINIMAX}(\text{RESULT}(s, a)) & \text{MAX to move}\\ \min_a\text{MINIMAX}(\text{RESULT}(s, a)) & \text{MIN to move}\end{cases}
Python
def minimax(state, maximizing):
    if is_terminal(state):
        return utility(state)
    values = [minimax(child, not maximizing) for child in successors(state)]
    return max(values) if maximizing else min(values)

A complete depth-first exploration: time O(bm)O(b^m), space O(bm)O(bm). Optimal against an optimal opponent (and never worse against a weaker one, in terms of the guaranteed value).

3 3 ≤2 2 3 12 8 2 4 6 14 5 2 MAXMIN red leaves are pruned: once C ≤ 2 < α = 3, MAX will never choose C
Minimax value 3; alpha–beta skips two leaves of C.

Alpha–beta pruning

Keep two bounds along the current path:

  • α\alpha — the best (highest) value MAX can already guarantee;
  • β\beta — the best (lowest) value MIN can already guarantee.

Prune a node's remaining children as soon as α≥β\alpha \ge \beta: at a MIN node when its value drops to ≤α\le \alpha; at a MAX node when its value rises to ≥β\ge \beta.

Python
import math

def alphabeta(state, maximizing, alpha=-math.inf, beta=math.inf):
    if is_terminal(state):
        return utility(state)
    if maximizing:
        v = -math.inf
        for child in successors(state):
            v = max(v, alphabeta(child, False, alpha, beta))
            alpha = max(alpha, v)
            if alpha >= beta:
                break                     # beta cut-off
        return v
    v = math.inf
    for child in successors(state):
        v = min(v, alphabeta(child, True, alpha, beta))
        beta = min(beta, v)
        if alpha >= beta:
            break                         # alpha cut-off
    return v
Move orderingLeaves examined
worst (weakest moves first)O(bm)O(b^m) — no savings
randomabout O(b3m/4)O(b^{3m/4})
perfect (best moves first)O(bm/2)O(b^{m/2}) — doubles the reachable depth

Good ordering heuristics: try captures and threats first, killer moves, iterative deepening (use the previous iteration's best move first), and transposition tables for repeated positions.

Imperfect real-time decisions

Real games are too deep to search to the end. Depth-limited search replaces the terminal test with a cut-off test and the utility with a heuristic evaluation function EVAL(s)\text{EVAL}(s), e.g. a weighted sum of features (material balance, mobility, king safety). Problems: the horizon effect (pushing an unavoidable loss beyond the depth limit) — mitigated by quiescence search (extend search in volatile positions).

Games of chance: expectimax

Add chance nodes whose value is the expected value of their children:

EXPECTIMAX(s)=∑rP(r) EXPECTIMAX(RESULT(s,r))at chance nodes.\text{EXPECTIMAX}(s) = \sum_r P(r)\,\text{EXPECTIMAX}(\text{RESULT}(s, r)) \quad\text{at chance nodes}.

Because values are averaged, the evaluation function's actual magnitudes matter (only its order matters in minimax). Pruning is harder, since bounds on averages need bounds on the utilities.

Beyond minimax

Monte Carlo tree search (used by AlphaGo) estimates move values by random playouts, balancing exploration and exploitation with the UCB1 rule; it works without a hand-made evaluation function and suits games with huge branching factors such as Go.

Quick revision

Practice questions

GATE-style questions: 3 one-mark and 6 two-mark. Wrong MCQs cost ⅓ of their marks in the real exam; MSQ and NAT have no negative marking. Attempt each before opening the solution.

Q1NAT2 marks

A two-ply game tree: the root is a MAX node with three MIN children B, C, D (evaluated left to right). The leaves (utilities for MAX) are B: 3, 12, 8 · C: 2, 4, 6 · D: 14, 5, 2.

The minimax value of the root is ______.

Q2NAT2 marks

A two-ply game tree: the root is a MAX node with three MIN children B, C, D (evaluated left to right). The leaves (utilities for MAX) are B: 3, 12, 8 · C: 2, 4, 6 · D: 14, 5, 2.

Alpha–beta pruning is applied with children examined left to right. The number of leaves that are not evaluated (pruned) is ______.

Q3MCQ1 mark

Compared with plain minimax, alpha–beta pruning

Q4NAT2 marks

A uniform game tree has branching factor b=10b = 10 and depth d=4d = 4. With perfect move ordering, alpha–beta examines b⌈d/2⌉+b⌊d/2⌋−1b^{\lceil d/2\rceil} + b^{\lfloor d/2\rfloor} - 1 leaves. That number is ______.

Q5MSQ2 marks

Which statements about game-tree search are correct?

One or more options are correct.

Q6NAT2 marks

MAX chooses between two moves leading to chance nodes. Move 1: outcome 2 with probability 0.5 and 8 with probability 0.5. Move 2: outcome 4 with probability 0.9 and 20 with probability 0.1. The expectimax value of MAX's position is ______.

Q7MCQ1 mark

During alpha–beta search, the remaining children of a MIN node can be pruned as soon as the MIN node's current value vv satisfies

Q8NAT1 mark

A complete game tree with branching factor 3 and depth 4 has how many leaves? ______

Q9MCQ2 marks

Chess is best described as a game that is