Skip to content
Kudos AI
Lire en français
Search and Games

Adversarial Search and Minimax

How a program plays a game against an opponent who is trying to beat it: the minimax value, why alpha-beta pruning reaches the same answer while examining fewer nodes, and a game tree pruned move by move.

6 min readKudos AI
Figure 5.2 worked twice: values backed up the tree, then the same tree under alpha-beta, cutting two leaves without moving the answer.

Searching for a route differs from playing a game in one decisive respect: in a game, someone else moves next, and they are trying to make you lose. You cannot plan a fixed sequence of actions, because your opponent's replies are not yours to choose. Adversarial search handles this by assuming the opponent plays as well as possible, and computing the best response to that.

A. The game tree

Two players, conventionally MAX (who moves first and maximises) and MIN (who minimises the same quantity). A game tree has the initial position at the root, one branch per legal move, alternating layers of MAX and MIN nodes, and terminal positions at the leaves carrying a utility - the payoff to MAX.

Because MIN's utility is the negation of MAX's, this is a zero-sum game: what one gains the other loses exactly. That is what allows a single number per leaf to describe the outcome for both.

B. The minimax value

The value of a node is defined recursively:

\textscMinimax(s)={\textscUtility(s)if s is terminal,max⁡a\textscMinimax(\textscResult(s,a))if s is a MAX node,min⁡a\textscMinimax(\textscResult(s,a))if s is a MIN node.\textsc{Minimax}(s) = \begin{cases} \textsc{Utility}(s) & \text{if } s \text{ is terminal},\\[4pt] \max_{a} \textsc{Minimax}(\textsc{Result}(s, a)) & \text{if } s \text{ is a MAX node},\\[4pt] \min_{a} \textsc{Minimax}(\textsc{Result}(s, a)) & \text{if } s \text{ is a MIN node}. \end{cases}

MAX picks the largest value among the children; MIN picks the smallest. Values propagate from the leaves up to the root, and MAX's best move at the root is the one leading to the child whose value equals the root's.

What the assumption buys, and what it costs. Minimax assumes the opponent plays optimally. Against an optimal opponent the value is exactly what MAX can guarantee, so it is a genuine worst-case guarantee, not a prediction. Against a weak opponent it is conservative: it may pass up a trap that a fallible opponent would fall into.

C. Working a tree by hand

A three-ply tree: the root is MAX, its three children are MIN nodes, each with three terminal children.

MIN nodeTerminal values
BB3, 12, 8
CC2, 4, 6
DD14, 5, 2

The MIN layer. Each MIN node takes the minimum of its children:

B=min⁡(3,12,8)=3,C=min⁡(2,4,6)=2,D=min⁡(14,5,2)=2.B = \min(3, 12, 8) = 3, \qquad C = \min(2, 4, 6) = 2, \qquad D = \min(14, 5, 2) = 2 .

The root. MAX takes the maximum:

\textscMinimax(root)=max⁡(3,2,2)=3.\textsc{Minimax}(\text{root}) = \max(3, 2, 2) = 3 .

MAX should move to BB, guaranteeing at least 3.

Note how little the large leaf values matter. The 1212 under BB and the 1414 under DD are never obtained, because MIN would never allow them - MIN moves to the 33 and the 22 respectively. Only the minima of each branch survive.

D. Alpha-beta pruning

Minimax examines every leaf, which is hopeless for real games - the tree grows exponentially with depth. Alpha-beta pruning computes the identical value while skipping branches that provably cannot affect it.

Two values are carried down the search, defined by Russell & Norvig as:

  • α\alpha - the value of the best (highest-value) choice found so far at any choice point along the path for MAX;
  • β\beta - the value of the best (lowest-value) choice found so far along the path for MIN.

The search prunes the remaining branches at a node as soon as the node's value is known to be worse than the current α\alpha (for MAX) or β\beta (for MIN).

E. Pruning the tree, step by step

Tracing the same tree left to right:

Node BB. Examine 33, 1212, 88. Nothing can be pruned - this is the first branch and MAX has no α\alpha yet. B=3B = 3, so the root sets α=3\alpha = 3: MAX can already guarantee 3.

Node CC. Examine the first leaf, 22. CC is a MIN node, so its final value is at most 22 - MIN can only go lower from here.

But MAX already has a guaranteed 3 elsewhere. A branch worth at most 2 will never be chosen over one worth 3, regardless of what the remaining leaves contain. So the leaves 44 and 66 are never examined. This is the prune.

Node DD. Examine 1414: value so far 1414, still above α=3\alpha = 3, no prune. Examine 55: value so far 55, still above 33. Examine 22: value 22. D=2D = 2.

Root. max⁡(3,2,2)=3\max(3, 2, 2) = 3 - the same answer as full minimax.

Alpha-beta examined 7 of the 9 leaves, pruning CC's second and third children.

Interactive: the leaves it never has to look at

MAX at the root, MIN below, twelve leaves.

3MAX3B3128≤2C246≤2D1452
Examined
7 / 9
Never examined
2
Root value
3
Move ordering:

2 of the twelve leaves were never evaluated, and the answer is identical to minimax’s. Note node D: it contains the largest leaf in the whole tree, 14, and it is worth 2, because MAX does not choose which leaf of D is reached - MIN does. A branch is worth what your opponent will allow, not what it contains. And note that a cut node’s figure is shown as at most a value rather than equal to it: the search stopped before finding out how much lower it went, which is exactly the work it saved.

Python

Runs in your browser. The first run downloads the Python runtime (~10 MB), then it is cached.

Running it prints value 3 from both methods, examined: [3, 12, 8, 2, 14, 5, 2] (seven leaves), and the two pruned leaves.

F. Why move ordering decides everything

Pruning depends on finding good moves early. If MAX's best move is examined first, α\alpha rises immediately and prunes aggressively. If it is examined last, there is nothing to prune against until the end.

With perfect ordering, alpha-beta examines roughly O(bm/2)O(b^{m/2}) nodes instead of O(bm)O(b^m) for branching factor bb and depth mm. That halved exponent means searching twice as deep in the same time - the difference between an amateur and an expert program.

Perfect ordering requires knowing the answer in advance, so real programs approximate it with heuristics: try captures first, try the move that was best at the previous shallower depth, and so on.

G. When the tree is too large regardless

Even halved, the exponent defeats games like chess or Go. Practical programs stop early and apply an evaluation function to non-terminal positions, estimating the utility rather than computing it.

This introduces two new problems worth naming. The horizon effect is the tendency to push an unavoidable loss just past the search depth, so it looks avoided when it is merely out of sight. And the evaluation function must be applied at quiescent positions - stopping in the middle of an exchange gives a badly wrong estimate, so search is extended until things settle.

Historically, alpha-beta search was conceived by John McCarthy in 1956; its correctness and time complexity were established by Knuth and Moore in 1975.

Key takeaways

  • Adversarial search assumes an optimal opponent, making the minimax value a worst-case guarantee.
  • MAX maximises, MIN minimises, and values propagate from the leaves to the root.
  • Our tree: MIN nodes 3,2,23, 2, 2; root value 33; MAX plays to BB.
  • Alpha-beta returns the identical value while skipping provably irrelevant branches - 7 leaves instead of 9 here.
  • α\alpha is MAX's best guarantee so far, β\beta is MIN's; a branch is cut once it cannot beat them.
  • Move ordering determines the benefit; perfect ordering roughly halves the effective depth exponent.

What's next

Minimax assumes strict opposition. Most real strategic situations are not zero-sum - players may both gain or both lose, and "optimal play" needs redefining. That generalisation is Game Theory and Nash Equilibrium.

References & further reading

  • Stuart Russell, Peter Norvig, Artificial Intelligence: A Modern Approach, Pearson (3rd edition), 2010· Kudos AI reference library

Copyrighted works are cited for reference only and are not hosted here; please consult the publisher for access.

Related reading

6 min readSearch and Games

Classical Planning: Schemas, Relaxations and Graphs

Why planning gets its own representation rather than being a footnote to search, how deleting parts of an action description produces a heuristic for free, and what a planning graph notices that per-goal heuristics systematically miss.

Artificial IntelligenceSearch & Planning
8 min readSearch and Games

Classical Search: From Breadth-First to A*

Turning a problem into a state space and letting an algorithm walk it: what completeness and optimality actually cost, why memory rather than time defeats breadth-first search, and the two conditions on a heuristic that make A* provably optimal.

Search & PlanningArtificial Intelligence
7 min readSearch and Games

Game Theory and Nash Equilibrium

Strategic reasoning when players are not strictly opposed: dominant strategies, the prisoner's dilemma worked from its payoff matrix, Nash equilibrium, Pareto optimality, and why equilibrium and efficiency can conflict.

Game TheoryArtificial IntelligenceMathematics
← Back to all articles