Connect Four Solver — How Computer Connect 4 Solving Works
A Connect Four solver tells you the perfect move from any position. Here is how those programs work, who built the first one, and how to use ours in your browser.
Game-Theoretic Verdicts
For any position, a solver returns win, lose, or draw — plus the number of plies until the game ends with best play from both sides.
Solved Since 1988
Allis and Allen both proved that the first player wins from the center column. The proof has held for nearly four decades.
Tractable on Commodity Hardware
About 4.5 trillion positions sounds enormous, but alpha-beta search prunes most of the tree. A modern laptop can verify the proof in minutes.
What a Connect Four Solver Does
A Connect Four solver is a program that, given a legal board position and a side to move, returns the game-theoretic value of that position: a first-player win, a second-player win, or a draw. Stronger solvers go further. They report the exact number of plies until the terminal result, and they identify the best move — the one that achieves the optimal outcome in the fewest moves while denying the opponent any drawing or winning chances.
The output of a solver is not a heuristic. It is not a "score" in the chess engine sense where a number suggests an evaluation. A Connect Four solver reasons about the position all the way to the end of the game and reports a proven result. Either the side to move has a forced win, the opponent has a forced win, or perfect play from here is a draw.
The History of Computer Connect 4 Solving
Connect Four was solved twice in 1988. James Allen reached the result first by hand, with some computer assistance, late in 1988. Victor Allis published the same result a few weeks later as part of his master's thesis at Vrije Universiteit Amsterdam. The two researchers arrived at the same conclusion independently: the first player wins by opening in the center column, and the proof relies on a combination of strategic rules and tactical search.
Allis built his proof on a system he called the threat-based strategy. He showed that certain configurations of threats — particularly threats on odd rows for the first player and even rows for the second — are unavoidable once they are set up correctly. The proof covered every line out of the center opening and demonstrated that the first player can force a win in at most 41 moves.
In 1995, John Tromp strong-solved Connect Four. A weak solution gives the value of the starting position. A strong solution gives the value of every reachable position — a lookup table of around four and a half trillion entries, compressed using symmetry and subgame independence. With Tromp's database, the value of any board state in the game tree can be answered in constant time.
Solving Techniques
Alpha-Beta Pruning
Alpha-beta is the workhorse algorithm behind every serious Connect Four solver. It is a refinement of minimax that tracks two bounds — alpha for the maximizing side, beta for the minimizing side — and prunes any branch that cannot affect the final result. In Connect Four with good move ordering (try the center column first), alpha-beta cuts the effective branching factor down dramatically.
Transposition Tables
Connect Four positions can be reached through many move orders. A transposition table is a hash map keyed by the board state that caches the value of positions already evaluated. When the search arrives at a position it has seen before — even via a totally different line — it returns the cached value instead of recomputing. Transposition tables routinely cut search time by an order of magnitude.
Opening Books
The first eight to twelve plies of Connect Four are the most expensive to search because the tree is widest near the root. Opening books store precomputed values for every position reachable in those early plies. A solver consults the book first, and only falls through to live search once the position leaves book.
Endgame Databases
At the other end of the game, when only a handful of moves remain, retrograde analysis can build a complete database of positions and their values. Endgame databases let a solver bypass search entirely once the position contains enough discs.
What the play4row Solver Does
The play4row solver combines alpha-beta search with a transposition table at every difficulty level, and consults a precomputed solution database at maximum strength. At lower difficulty levels we limit the search depth so the engine plays at a human-realistic strength — beatable, but never blundering. At maximum difficulty the solver returns the provably best move in every position, and the per-column scores you see are exact plies-to-mate values, not heuristic evaluations.
The interface at /analyze shows you the same data the engine sees: the side-to-move evaluation in the bar on the left, the per-column verdicts above each column, and the best column highlighted. Click any column to play that move and watch the evaluation update.
Why Connect Four is Tractable
Compared to its better-known cousins, Connect Four is small. Chess has on the order of ten to the forty-fifth power positions. Go has even more. Connect Four has only about 4.5 trillion legal positions before symmetry. Symmetry on the seven-column board roughly halves that. Transposition cuts further. The result is a state space that fits comfortably on a laptop hard drive, and a search problem that finishes in minutes rather than centuries.
Frequently Asked Questions
What is a Connect Four solver?
A Connect Four solver is a program that takes any legal board position and computes its game-theoretic value — first-player win, second-player win, or draw — assuming both sides play perfectly from there. Strong solvers also tell you the best move and how many plies away the result is.
When was Connect Four solved?
James Allen and Victor Allis both solved Connect Four in 1988, working independently. Allis published his result inside a master's thesis at Vrije Universiteit Amsterdam. John Tromp later strong-solved the game in 1995 by computing the value of every reachable position.
What algorithms do Connect Four solvers use?
Modern solvers combine alpha-beta pruning, transposition tables, opening books, and endgame databases. Alpha-beta cuts off branches that cannot affect the result, transposition tables avoid re-evaluating positions reachable through different move orders, and opening books cover the first eight to twelve plies with precomputed values.
Why is Connect Four solvable on a laptop?
The state space is only about 4.5 trillion positions, and symmetry plus transpositions cut that further. With alpha-beta and a transposition table, a solver can prove the game-theoretic value of the empty board in a few minutes on modern hardware.
How does the play4row solver work?
play4row uses alpha-beta search with a transposition table and a precomputed solution database. At lower difficulty levels we limit the search depth so the engine plays at human strength. At maximum strength it consults the full solution and plays the provably best move every time.
Related Reading
For a non-technical overview of what "solved" means and the history behind it, see the Connect Four solver explainer. For a head-to-head comparison of the public Connect 4 solvers available today, see the best Connect 4 solver review.
Try the Solver
Drop into a position and watch the engine evaluate it move by move.