Skip to content
Kudos AI

Minimax and Alpha-Beta Pruning

Propagating values up a game tree under an optimal-opponent assumption, and cutting branches that provably cannot change the answer.

IntermediateModule 130 min · 120 XP
Figure 5.2 worked twice: values backed up the tree, then the same tree under alpha-beta, cutting two leaves without moving the answer.

In a two-player, zero-sum, perfect-information game, both players know everything and one player's gain is the other's loss. MAX wants a large final utility; MIN wants a small one. Optimal play against a perfect opponent has an exact definition, and it is computed bottom-up.

The minimax value

MINIMAX(s)={UTILITY(s)if s is terminal,max⁡aMINIMAX(RESULT(s,a))if MAX moves at s,min⁡aMINIMAX(RESULT(s,a))if MIN moves at s.\text{MINIMAX}(s) = \begin{cases} \text{UTILITY}(s) & \text{if } s \text{ is terminal},\\ \max_{a} \text{MINIMAX}(\text{RESULT}(s,a)) & \text{if MAX moves at } s,\\ \min_{a} \text{MINIMAX}(\text{RESULT}(s,a)) & \text{if MIN moves at } s. \end{cases}

Read it as an assumption about the opponent: MAX assumes MIN will always reply with the worst move for MAX. The value is what MAX can guarantee even against perfect play - a lower bound you cannot be argued out of, not a prediction of what a weak opponent will do.

Worked example

The standard two-ply tree. A MAX root has three MIN children, whose leaves are

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

Back up the MIN nodes. Each takes the minimum of its leaves:

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

Back up the MAX root. It takes the maximum of its children:

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

The minimax value is 3\mathbf{3}, and the optimal move is the one leading to BB.

Note the trap in node DD: it contains the largest leaf in the entire tree, 1414. It is worth 22, because MAX does not get to choose which leaf of DD is reached - MIN does, and MIN will take the 22. A branch is worth what your opponent will allow, not what it contains.

Alpha-beta pruning

Minimax examines every node, which is O(bm)O(b^m) and hopeless for real games. But you do not need to see every node to know the root value.

Suppose MAX has already established that BB guarantees 33. Now examine CC and find its first leaf is 22. Node CC is a MIN node, so its final value is at most 22 - MIN can always take that 22, and further leaves can only lower it. Since 2<32 < 3, MAX will never choose CC. The remaining leaves of CC cannot change the root value, so they need not be examined at all.

That is the entire idea, tracked with two bounds: α\alpha, the best value MAX can already guarantee, and β\beta, the best MIN can already guarantee.

What pruning changes. Applied to a standard minimax tree, alpha-beta returns the same move as minimax would, while pruning away branches that cannot possibly influence the final decision. It is exact, not approximate: the value is identical, only the work differs. Anyone describing it as a faster approximation has misunderstood it.

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.

Move ordering

Pruning depends entirely on examining good moves early. If the best move is searched first, α\alpha rises immediately and later branches are cut quickly. With perfect ordering the effective branching factor falls from bb to about b\sqrt{b}, letting a search go roughly twice as deep in the same time. With worst-case ordering nothing is pruned and you have paid minimax's full cost.

This is why real engines invest heavily in ordering heuristics before deepening the search.

Before the quiz

Be able to back values up a small tree, state that alpha-beta returns the identical value while examining fewer nodes, and explain why DD is worth 22 despite containing 1414. See Adversarial Search and Minimax.

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.

Unlock the full path

This first lesson is free. Enrol to take the mastery quiz, earn XP, and unlock every module, with more interactive, runnable examples throughout.