Alpha-Beta Pruning in Connect Four

Definition

Alpha-beta pruning is an optimization for minimax search that skips branches of the game tree which cannot influence the final decision, dramatically reducing search time.

Explanation

Alpha-beta pruning is the optimization that turns minimax from a theoretical algorithm into a practical engine. Pure minimax searches every node in the game tree. Alpha-beta pruning cuts entire branches that the algorithm can prove are irrelevant to the final answer. The result is the same correct answer as pure minimax but with potentially exponential time savings.

The algorithm tracks two values during the search: alpha (the best value the maximizing player has found so far) and beta (the best value the minimizing player has found so far). When the search discovers a node whose value is provably worse than what the opposing player would already accept, the entire subtree below that node can be skipped. The skipped subtree contains nodes that the algorithm "proves" the opponent would never let the search reach, so calculating their values is wasted work.

The efficiency of alpha-beta pruning depends heavily on move ordering. If the algorithm explores the best moves first, it quickly establishes tight alpha and beta bounds, which lets it prune more aggressively for the remaining moves. If it explores in random order, the bounds stay loose and few branches get pruned. Strong engines invest significant effort in move ordering heuristics, often using shallow searches to estimate which moves should be explored first.

In Connect Four, alpha-beta pruning combined with a few other optimizations brings the search depth from 4 or 5 plies (with naive minimax) to 20 or more plies. This is enough to play perfectly in nearly any position, since 20 plies covers most middlegame and endgame positions completely. The remaining gap is filled by opening books (precomputed first 10-15 moves) and endgame tablebases (precomputed final 10-15 moves). The combination produces an engine that plays at perfect strength in real time on consumer hardware.

Example

During search, the engine finds that column 4 leads to a +1 outcome. It starts evaluating column 5, finds an opponent response that gives -1, and immediately stops searching column 5 because no value found there can exceed +1.

Related Articles

How the Engine Works

Put It Into Practice

Understanding alpha-beta pruning is one thing. Applying it is another.