Adversarial Search and Game Playing
Games as Search: Minimax and Game Trees · 15 min
A deterministic, two-player, zero-sum game of perfect information can be modeled as a search over a game tree: nodes are game states, edges are legal moves, and terminal nodes carry a utility value from the perspective of one player, say MAX, where MIN's utility is the negation. The minimax algorithm computes, for every node, the value MAX can guarantee assuming MIN always responds optimally: at a MAX node the value is the maximum of its children's values, at a MIN node it is the minimum, and at a terminal node it is simply the terminal utility. Formally, if s is a terminal state, MINIMAX(s) equals UTILITY(s); if s is a MAX node, MINIMAX(s) equals the maximum, over each successor state s′, of MINIMAX(s′); and if s is a MIN node, MINIMAX(s) equals the minimum over each successor's value. This recursive definition captures adversarial reasoning precisely — MAX must plan for the worst response MIN can make, not the response MAX would prefer MIN to make — and small deterministic games like tic-tac-toe are common teaching examples because their complete game trees are compact enough to compute by hand, letting a learner check the recursive equations directly against the definition rather than trusting an algorithm's output blindly.
Trace a small three-ply tree to see this concretely: MAX is to move at the root, which has two children (moves A and B), each a MIN node with two of its own children (terminal states with utilities). Suppose under move A the terminal utilities are 3 and 12, and under move B they are 8 and 2. MIN, moving second, will choose the lower value at each of its nodes — so under A, MIN picks 3 (not 12), and under B, MIN picks 2 (not 8). Backing these values up to the root, MAX now compares 3 (from A) against 2 (from B) and chooses move A, guaranteeing a value of 3 — even though B contains the single largest terminal value in the whole tree (8), MAX cannot obtain it because a rational MIN would never allow it. Even in this tiny four-leaf example, minimax's core discipline is visible: MAX evaluates each of its own options only in terms of the worst outcome MIN can force within it, never in terms of the single best outcome that might theoretically be reachable somewhere beneath that option.
This example illustrates why minimax reasons about the opponent's incentives rather than searching only for the learner's own best-case outcome: naive optimism (picking the branch with the largest terminal value anywhere beneath it) would have wrongly chosen move B, exposing the learner to whichever of B's outcomes MIN actually prefers rather than the favorable one. The formal roots of this idea trace back to Claude Shannon's 1950 paper 'Programming a Computer for Playing Chess,' which proposed that a chess program could evaluate positions with a numeric scoring function and search ahead through possible move sequences to choose a move, distinguishing an exhaustive 'Type A' strategy that examines all variations to a fixed depth from a more selective 'Type B' strategy that follows forceful lines (checks, captures, threats) deeper while cutting off quieter ones sooner — an early statement of the depth-versus-breadth trade-off that every subsequent game-playing program has had to confront.
Alpha-Beta Pruning and Evaluation Functions · 20 min
Minimax as described requires exploring the entire game tree, which is intractable for games like chess where the tree has an astronomically large number of nodes. Alpha-beta pruning computes exactly the same minimax value while skipping branches that cannot possibly affect the final decision. It maintains two bounds during the search — alpha, the best value MAX can guarantee so far along the current path, and beta, the best value MIN can guarantee so far — and prunes a branch the moment its value is proven irrelevant: at a MIN node, if a newly explored child's value falls at or below alpha, the remaining children are skipped, because MAX already has a better guaranteed option elsewhere and MIN would never let this line be reached anyway. The symmetric case applies at MAX nodes with respect to beta: if a child's value meets or exceeds beta, the remaining children can be skipped because MIN already has a better guaranteed alternative and would never steer play into this branch.
Trace this on the same tree as before: exploring move A first, MIN's node returns 3 (having compared 3 and 12), so alpha is now 3 at the root. Moving to move B's MIN node, its first child is explored and found to be 2. Since 2 is already at or below alpha (3), MAX can never prefer this branch over move A no matter what the second child of B turns out to be — so the second child is pruned without ever being evaluated. The final decision (move A, value 3) is identical to full minimax, but one leaf was never visited, and had the tree been far larger, entire deep subtrees beneath that pruned second child would have been skipped along with it. In the best case, when the strongest move at each node happens to be explored first, alpha-beta pruning lets a search reach roughly twice the depth of unpruned minimax within the same time budget, because the effective branching factor the search must expand is reduced substantially.
Even with pruning, most real games are too deep to search to termination, so practical programs apply a cutoff test at some depth limit and substitute an evaluation function — a heuristic estimate of a non-terminal position's value, such as weighted material counts in chess, where a queen might be weighted far more heavily than a pawn — in place of the true minimax value below that depth. This introduces risks: the horizon effect, where a damaging event just beyond the search horizon is delayed by shuffling moves rather than genuinely prevented, since the program cannot see far enough ahead to recognize the delay is futile; and unstable positions, where the position is still in flux (mid-capture-sequence, for instance) and a static evaluation would be misleading, which is why quiescence search extends the depth locally along forceful lines until the position settles enough for the evaluation function to be trustworthy.
Uncertainty in Games and Monte Carlo Tree Search · 15 min
Not every game is deterministic: backgammon involves dice rolls at every turn, and many card games hide information from players entirely. Games of chance are modeled by adding chance nodes to the game tree, at which the algorithm — now called expectiminimax — takes a probability-weighted average over the possible outcomes rather than a strict max or min, reflecting that the actual roll is outside either player's control and both players must plan for the distribution of possible dice outcomes rather than any single one. This changes the character of pruning too, since a single very high or very low outcome at a chance node is diluted by averaging against every other possible outcome weighted by its probability, so alpha-beta-style cutoffs are considerably less effective in stochastic games than in fully deterministic ones, and bounding the possible range of utility values becomes important for any pruning to remain useful at all.
For games with enormous branching factors or where no reliable evaluation function exists — such as Go, where the number of legal moves per position vastly exceeds chess — Monte Carlo tree search (MCTS) offers an alternative that needs no hand-crafted evaluation function at all. MCTS builds a search tree incrementally through repeated simulations, each consisting of four phases: selection, descending the already-built portion of the tree via a policy that balances exploring less-visited moves against exploiting moves already known to score well (commonly the UCB1/UCT formula, which adds an exploration bonus that shrinks as a node's visit count grows); expansion, adding one new node to the tree at the frontier reached by selection; simulation (or 'rollout'), playing the game out to completion from that new node using a fast, often random or lightly guided, policy; and backpropagation, updating win/visit statistics for every node along the path back to the root, so future selections at the root are informed by the accumulated results.
Browne et al.'s 2012 survey documents that this simulation-based approach proved successful across a wide range of domains within the method's first five years, notably including Go, precisely because it sidesteps the need for a strong static evaluation function — the accumulated statistics from many simulated playouts serve the same role instead, letting the tree's own visit counts and win rates stand in for hand-tuned position knowledge. As more simulations run, MCTS's move-value estimates converge toward the true minimax values, giving it an anytime character: it can be stopped after any number of simulations, however few or many the available time budget allows, and still return its current best estimate rather than needing to complete an entire fixed search first. This anytime property, together with its independence from a hand-crafted evaluation function, is one reason MCTS has become the standard approach for games where full-tree minimax search is computationally out of reach, and it illustrates a broader theme in adversarial search: as branching factors grow too large for exhaustive or near-exhaustive evaluation, sampling-based estimation becomes a practical substitute for exact computation.
Minimax Game Tree
A minimax tree in which alpha-beta pruning skips the dashed rightmost leaf: once its sibling (value 2) is already at or below the left branch's guaranteed value of 3, the MIN node's result can only get lower, so it can never beat 3 for MAX — the '?' leaf is safely skipped.
- Minimax never assumes the opponent will make a mistake — it computes the best outcome achievable against a worst-case, perfectly rational adversary.
- Alpha-beta pruning changes only how much of the tree is explored, never which move is ultimately chosen — it produces the identical decision as full minimax, faster.
- Monte Carlo tree search trades a hand-crafted evaluation function for statistics accumulated from many random simulated playouts, which is why it scales to games too complex for classical evaluation heuristics.
Recall Practice
Glossary
- Minimax
- An algorithm that computes the value a MAX player can guarantee in a two-player zero-sum game, assuming the MIN player always plays optimally in response.
- Alpha-beta pruning
- An optimization of minimax that skips branches provably irrelevant to the final decision, using tracked bounds (alpha and beta) on achievable values.
- Evaluation function
- A heuristic that estimates the value of a non-terminal game position, used when full search to game termination is infeasible.
- Expectiminimax
- An extension of minimax that adds chance nodes taking a probability-weighted average, for games involving randomness such as dice.
- Monte Carlo tree search (MCTS)
- A simulation-based search algorithm that builds a game tree incrementally through repeated selection, expansion, simulation, and backpropagation, without requiring a hand-crafted evaluation function.
- Horizon effect
- A weakness of depth-limited search in which a significant event just beyond the search cutoff is delayed rather than genuinely avoided.
Hand-Trace Minimax and Alpha-Beta on a Small Game Tree
This is a virtual, hand-traced exercise using a small supplied game tree (three plies, branching factor two, with given terminal utility values) — no software or real game engine is executed. The learner computes the minimax backed-up value at every node by hand, then re-traces the same tree applying alpha-beta pruning to identify and mark which branch is provably safe to skip, comparing the final chosen move and pruning decisions against a supplied worked solution.
Ready to test yourself?
5 questions on this module.