Minimax and Alpha–Beta Pruning
Trace through a depth-3 minimax game tree, observing how alpha-beta pruning skips branches.
By Riano · Published · Updated · Report a correction
Worked Example
Consider a zero-sum game tree of depth 3 with 8 terminal leaves. The root node is a MAX player. Depth 1 nodes belong to the MIN player, and depth 2 nodes belong to MAX. Let the leaf scores from left to right be: 3, 5, 6, 9, 1, 2, 0, -1.
With standard Minimax:
- The left MAX node at depth 2 sees leaves
3, 5. It chooses the maximum:5. - The second MAX node at depth 2 sees leaves
6, 9. It chooses the maximum:9. - The MIN node at depth 1 (left child of root) sees options
5, 9from its children. It chooses the minimum:5. - The third MAX node at depth 2 sees leaves
1, 2. It chooses2. - The fourth MAX node at depth 2 sees leaves
0, -1. It chooses0. - The MIN node at depth 1 (right child of root) sees options
2, 0. It chooses0. - The MAX root node sees options
5, 0. It chooses5.
With Alpha-Beta pruning, we track bounds [α, β] for each node:
- The search explores the left side of the tree. The left MIN node receives its first child value
5, and sets its upper boundβ = 5. - The next MAX node at depth 2 evaluates its first leaf,
6. This updates its lower boundα = 6. - Since
α (6) ≥ β (5), the MIN node will never choose this MAX node. The algorithm prunes the remaining leaf (9) and skips evaluating it. - Similarly, on the right half of the tree, the right MIN node evaluates its first child (which returns
2), setting itsβ = 2. - The MAX root has a lower bound
α = 5(from the left side). Sinceα (5) ≥ β (2), it prunes the rest of the right subtree.
Experiment
You can try this interactive simulation at Minimax and Alpha-Beta Pruning. Use the Leaf scores input to test different scenarios.
- Enter comma-separated integers such as
-1,0,2,1,9,6,5,3in the Leaf scores input. - Toggle the Pruning checkbox on or off to compare the evaluated leaves.
- Click Finish: with pruning on this input gives root 5, seven evaluated leaves and one pruned leaf. With Pruning off, Finish gives the same root 5 from eight evaluated leaves. Reset rewinds without changing the input.
- Use the Step button to watch the depth-first search traverse the tree, and note that when Pruning is enabled, branches are marked with an "X" once
α ≥ βis met.
Limitations
This visualization uses a fixed, complete binary tree of depth 3 and synthetic terminal utility values. This view also cuts at equal bounds: a tied alternative cannot improve the root utility, and the root keeps its left choice. A returned cutoff bound is not an exact value for that skipped subtree. Real game-playing AI (like those for Chess or Go) would not reach terminal states so quickly; instead, they use depth-limited search and heuristic static evaluation functions for non-terminal leaves. Additionally, modern engines enhance Alpha-Beta pruning with techniques like move ordering, iterative deepening, and transposition tables, which are not depicted here.
References
This algorithm and the theoretical basis for bounds are detailed here:
Experience it interactively
Adjust parameters, observe in real time, and build deep intuition with Riano’s interactive Minimax and Alpha–Beta Pruning module.
Try Minimax and Alpha–Beta Pruning on Riano →