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.
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
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
Back up the MIN nodes. Each takes the minimum of its leaves:
Back up the MAX root. It takes the maximum of its children:
The minimax value is , and the optimal move is the one leading to .
Note the trap in node : it contains the largest leaf in the entire tree, . It is worth , because MAX does not get to choose which leaf of is reached - MIN does, and MIN will take the . A branch is worth what your opponent will allow, not what it contains.
Alpha-beta pruning
Minimax examines every node, which is 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 guarantees . Now examine and find its first leaf is . Node is a MIN node, so its final value is at most - MIN can always take that , and further leaves can only lower it. Since , MAX will never choose . The remaining leaves of cannot change the root value, so they need not be examined at all.
That is the entire idea, tracked with two bounds: , the best value MAX can already guarantee, and , 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.
- Examined
- 7 / 9
- Never examined
- 2
- Root value
- 3
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, rises immediately and later branches are cut quickly. With perfect ordering the effective branching factor falls from to about , 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 is worth despite containing . 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.