Connect 4 Solver

Play it, or find out what a position is really worth — proved, not guessed.

Runs in your browser Free · no account

Setting up the board…

About the Connect 4 Solver converter

Connect 4 is not a game of opinion. It was solved in 1988, and with perfect play from both sides the first player wins — but only by opening in the middle column. Every other opening throws that away.

So this does not score a position out of ten or tell you what it "prefers". It searches to the end of the game and reports what is actually true: this column wins in nine, that one draws, that one loses. Where it cannot finish in the time it has, it says so rather than dressing a guess up as an answer.

What it means for a game to be solved

A solved game is one where the result from any position is known with certainty, assuming both players play as well as it is possible to play. Connect 4 was solved independently by James Allen and Victor Allis in 1988, and the answer is that the first player wins.

That is a much stronger statement than "the first player has an advantage". It means there is a reply to everything the second player can try, and it ends in four in a row every time. The catch is that it only holds if the first move is the middle column: open anywhere else and a perfect opponent draws with you, or beats you.

How a verdict is worked out

The board is small enough to fit in a single number. Each of the seven columns gets one bit per row plus a spare on top, which is forty-nine bits in total — one number holding the stones of whoever is about to move, another holding every stone on the board. Four in a row then comes out of three shifts and an AND rather than a scan of the grid, and the spare bits are what stop the top of one column joining the bottom of the next.

On top of that sits an ordinary search that tries every move, then every reply, and so on to the end, with two things that make it finish this side of forever. Columns nearest the middle are tried first, because central stones sit on more lines and so the best move is usually found early, which lets everything worse be discarded without being looked at. And positions already seen are remembered, since the same shape is reached by many different orders of play.

Why the numbers count down

A verdict of "win 9" means the win arrives nine moves from now with best play on both sides. A faster win scores higher than a slower one, which is what makes the solver finish games instead of shuffling about in a position it has already won.

It cuts the other way when the position is lost. Faced with nothing but losses it picks the slowest, because a game that lasts eleven more moves gives an imperfect opponent eleven more chances to go wrong — which, against anybody who is not a computer, is the whole game.

When it says it does not know

A wide-open board is the hardest position there is: the search has the most to get through and the fewest settled squares to prune against. Given a couple of seconds it will not always get to the bottom of one, and when that happens it says so rather than returning a number that looks like a proof.

Positions from the middle of a game onwards are a different matter — with a dozen or more stones down, most are settled outright in the time available. That is the opposite of the usual arrangement, where an engine sounds most confident at the start and hedges later.

What to do with it

Play a game against the solver and take a move back when something goes wrong: the verdicts will show you exactly which move lost it, which is usually not the one that felt like the mistake. That is a quicker way to learn where the game is decided than reading about it.

Or set a position up and study it. Every column carries its own verdict, so you can see at a glance that three of them throw the game away and one holds it, which is the sort of thing that is very hard to see by staring at a board.

Frequently asked questions

Who wins Connect 4 with perfect play?

The first player, but only by opening in the middle column. Opening one column either side of the middle is a draw with perfect play, and the outer four columns lose.

Is the opponent actually unbeatable?

It plays the proven best move whenever its search settles the position, which from the middle of a game onwards it usually does. In the opening it often cannot get to the bottom of things in a few seconds, so it plays the best it has found rather than a proof. Beating it is a real achievement by the endgame and quite possible early on.

What does "win 9" on a column mean?

That dropping there wins the game nine moves from now, counting both players, if everybody plays as well as possible. A smaller number is a quicker win.

Why does it sometimes say it could not settle a position?

Because it ran out of time rather than out of board. A nearly empty position has an enormous number of continuations; a position with a dozen stones down usually has few enough to search to the very end. It is deliberately explicit about the difference.

Does it send my game anywhere?

No. The whole thing runs in your browser, with the search on a background thread so the board stays responsive while it thinks.

Can I play against another person?

Yes. Switch to two players and the board simply passes between you, with the verdicts still shown if you want them or hidden if you do not.