Strategy guides › Four in a Row
How to beat the Four in a Row bot on every level
Two empty squares in column 6, one directly above the other, both of them winning squares for you, and the Hard bot to move. It searches seven moves deep, and it is already lost: whichever column it picks, you win within three of your moves. Getting there took eleven discs, and you can play them in the same order every time.
That last part is the secret of this page. Our Four in a Row bot has no dice in it. Given the same position, it always plays the same move. So a line that beats it once beats it forever, and below are three of them, one per level, each found by playing the bot’s own code against a deeper search.
The first player wins, and the centre is why
Four in a Row was solved in 1988, independently by James D. Allen and Victor Allis: with perfect play, the first player wins, and the winning first move is the centre column. Start in any other column and perfect defence holds the draw or better. You will not play perfectly, and neither does our bot, but the solution tells you where the value of the board lives.
You can see it by counting. The board has 69 possible lines of four. Each square sits on some of them, and the counts below come straight from the line list in our game code.
A disc in the middle of column 4 takes part in thirteen possible fours; a corner disc in three. Every centre disc you own is a disc the opponent cannot use, and the bot knows it too: its scoring adds a bonus for each of its own discs in the centre column, and when it opens a game it always plays there.
Odd rows, even rows and the waiting game
Most Four in a Row games between careful players are not decided by a four you build in the open. They are decided at the end, when the board is nearly full and someone is forced to drop a disc directly under the opponent’s winning square. That is zugzwang: any move you make hurts you.
Allis’s analysis turns this into a rule of thumb about rows, counted from the bottom. If neither side can play elsewhere, the columns fill up in turn, and the first player ends up dropping discs onto odd rows (1, 3, 5) while the second player gets the even ones. So a threat on an odd row is worth a lot to the first player, because sooner or later the second player will have to fill the square beneath it. The second player wants threats on even rows. A threat on the “wrong” row for you is still useful, but it rarely wins on its own. John Tromp’s Four in a Row page has the history and the full solution.
The strongest pattern of all ignores parity: two of your threats stacked directly on top of each other in the same column. Your opponent cannot block the lower one without handing you the upper one. That is how the Hard line below wins.
How each bot thinks
We read the search in our code. All three levels are the same alpha-beta minimax with a simple scoring of open lines; only the depth changes. Easy looks one move ahead: it scores the board after its own move and never asks what you will reply. Normal looks four moves ahead (two of its own, two of yours). Hard looks seven moves ahead. None of them uses randomness, and the first-game opener is always you; after a finished game, the opener alternates.
Easy’s one-move horizon means it does not block. It will happily build its own three in a row while you stack four in column 1. Normal blocks anything it can see coming within four moves, so you beat it with a double threat: two winning squares that are both playable at once. Hard sees seven moves, so the trap has to be set further back than that, which is what the stacked threat does.
Winning lines, level by level
We played the bot’s own move function against a deeper search of ours (eight moves, same scoring), from every combination of our first two or three moves, and kept the shortest wins with you moving first. Columns are numbered 1 to 7 from the left. Only your moves are listed; the bot’s replies in brackets are what it will play, every time.
Easy, 4 moves. 1 (4), 1 (5), 1 (3), 1. Four in column 1. The bot spends its moves building 3-4-5 on the bottom row, which would have beaten you next turn.
Normal, 10 moves. 4 (2), 4 (4), 4 (2), 2 (2), 4 (4), 6 (7), 6 (6), 3 (5), 5 (3), 7. Your ninth disc, in column 5, makes two threats on row 2, in columns 3 and 7, both playable at once. The bot blocks column 3; you finish in column 7.
Hard, 14 moves. 4 (4), 3 (2), 4 (2), 3 (3), 5 (6), 4 (4), 2 (2), 5 (5), 5 (2), 6 (4), 3 (3), 5 (3), 6 (5), 6. The game is decided at your eleventh disc.
When we let the bot open instead, our eight-move search still beat Hard after 13 of the 49 two-move starts we tried, but those games run to 38 discs or more. Playing second, aim for the same thing: a stacked pair, or a lone threat on an even row and the patience to wait for the board to fill.
Practice
Load Hard and play the 14-move line once, slowly, watching each yellow reply land where the list says. Then play it again and stop at the position in the diagram: try to see the stacked threat before you drop the disc that makes it. The next time you build three in a row, ask the better question — not “can they block it?” but “what is directly above the square they must block?”
In Four in a Row, the square that matters most is the one nobody can afford to fill.