Connect 4 is one of the few games from a toy shelf that mathematicians and programmers have solved completely. Both sides can play it perfectly, and the result of that perfect play is known. This page explains what that means, who did it, and what the answer is for your first disc.
What "solved" means
A game can be solved to three different depths.
- Ultra-weakly solved: we know who wins from the start, but not how to do it.
- Weakly solved: we know who wins from the start, and we have a strategy that achieves it against any defence.
- Strongly solved: we know the correct result of every position that can occur, no matter how the game got there.
Connect 4 was weakly solved in 1988 and strongly solved in the years that followed. The distinction matters, because a weak solution only helps if the game goes the way the strategy expects. As soon as someone leaves that path, you need a result for the new position, and that is what a strong solution gives you.
Two solutions in fifteen days
On 1 October 1988 James D. Allen posted a message to the newsgroup rec.games.programmer: the first player can win. His method was a brute-force program that checked about six billion positions. Fifteen days later, on 16 October, Victor Allis announced his own solution, found independently.
Allis's route was very different. He wrote a program called VICTOR, which relies on nine strategic rules. Each rule is proven to be correct, and each shows that some group of four cannot be completed by the opponent. When the rules together close every group, the position is decided without searching. Where they cannot do that, the program searches with a method called conspiracy-number search, and it stores the results in a database of about half a million positions. The work was his master's thesis at the Vrije Universiteit Amsterdam, dated October 1988. In the thesis he notes that Allen's message appeared only a few days before the final text was printed, and that Allen's variations confirmed his results.
His rules include the odd-and-even logic that strong players still use today. The page about odd and even threats explains how it works. If you would like to read the original, the thesis is available as a PDF on John Tromp's site.
What the solution says
For the standard board of seven columns and six rows, the answer is this.
| First disc | Result with perfect play |
|---|---|
| Column 4, the middle | the first player wins |
| Columns 3 and 5 | draw |
| Columns 2 and 6 | the second player wins |
| Columns 1 and 7 | the second player wins |
With the first disc in the middle and perfect play from both sides, the first player completes four at the latest on the 41st disc of the game. That is the 21st and last disc red can place, since each side has 21 discs for the 42 cells. A perfect defence does not stop the loss, it only makes the loss arrive as late as possible.
The page about openings goes through this table move by move. In our game, the Master level on the classic board relies on an opening book and an exact solver, so it does not give away a win or a draw.
From weak to strong: John Tromp
John Tromp, who worked at the CWI research institute in Amsterdam, wanted a complete answer. He compiled a database with the theoretical result of every position with eight discs on the board. According to his own account it took about 40,000 hours of computer time on workstations of the institute. With that database and a solver, any position of the game can be evaluated in seconds.
A part of that database, the 67,557 positions with eight discs where nobody has won yet and the next move is not forced, was donated in 1995 to the UCI Machine Learning Repository, where it is available for machine-learning experiments. The game is also a popular benchmark for programmers: the solver code from Tromp's page became the integer benchmark called Fhourstones.
A different question is how many positions there are. The count for the standard board is 4,531,985,219,092, a number that Stefan Edelkamp and Peter Kissmann had already determined in 2008. Tromp writes that he had started the same count himself, and that when he searched for the final number he found that Edelkamp and Kissmann already had it.
Other board sizes
Tromp's solver has also been used on boards of other sizes. In this table, "1st" means that the first player wins with perfect play, "2nd" that the second player wins, and "draw" a draw. The width is in the columns, the height in the rows.
| Height \ Width | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|
| 7 | draw | draw | 1st | draw | 1st |
| 6 | draw | draw | 2nd | 1st | 2nd |
| 5 | draw | draw | draw | draw | 1st |
| 4 | draw | draw | 2nd | draw | 2nd |
The row for height 6 and the column for width 7 hold the standard board, a first-player win. The 7×7 board is a draw, which is the reason why it behaves differently in the variant described on the 7×7 page. Tromp's page also records that 9×6 is a second-player win, a result finished in November 2005 after about 2,000 hours of computation, and that 8×8 is a second-player win, finished in 2015. These results are for four in a row, so they say nothing about our five in a row variant, which is a different game.
For a detailed look at the numbers, see John Tromp's Connect Four page.
What it means for players
A solved game sounds as if the game is finished. It is not, for three reasons.
- The solution cannot be memorised. It is a table of many millions of positions. Even the first few moves branch into more lines than a person remembers.
- The first player still has to find every move. The win is theoretical, and a single mistake gives it away, as the common mistakes show.
- The second player has chances. Against a first player who does not play perfectly, the second player can win. The solution tells you where a line leads if both sides are perfect, and no more than that.
The solution does tell you something useful for practice. It tells you which opening move is correct, and it tells you that an odd threat for the first player and an even threat for the second player are the ones that matter. The rest you learn by playing.