Four in a Row

Saved games stay in this browser only.

About the game

Four in a Row needs about thirty seconds of explanation and a lifetime to master. Two players take turns dropping a coloured disc into one of the seven columns of an upright grid. The disc falls to the lowest free slot, and the first player to line up four of their own discs, horizontally, vertically or diagonally, wins. If the grid fills up before that happens, the game is a draw.

The strategy hides in the way the discs stack. Every disc you drop also decides what your opponent can reach next, because the slot above it opens up for them. A threat low in the grid is easy to see, but a pair of threats that sit one above the other is a trap that is nearly impossible to stop. Good players build those traps, and they also look out for them before the other side does.

Kenrick wrote this version in TypeScript, drawing the grid and the falling discs on a canvas. The computer player uses the minimax search with alpha-beta pruning, looking several moves ahead and scoring each position with a fixed rule, so it is a solid opponent that is not perfect. This version keeps the modes that run on a single device and leaves out the author's online mode.

Playing it here

Click Play, choose a mode in the window that opens and press Start game. In the first mode you play the red discs against the computer and move first; in the second two people share the mouse or the touchscreen, with a name each; in the third you simply watch two computer players. Click on the grid, in the column you want, to drop a disc. The line at the top announces every move, and when the game ends you can play again or go back to the mode window with End game. Nothing is saved between visits.

Controls

Input Action
click or tap a column drop your disc into it
1 to 7 drop your disc into the first to the seventh column (left to right)
Play again start a new game with the same settings
End game go back to the mode window

A few things worth knowing

The middle column is worth the most. More lines of four pass through the centre of the grid than through the edges, so it is usually a strong first move.

Look for the double threat. One line of three is easy to block. Two lines of three that need different slots at the same time are not.

Never hand over the slot above. Before you drop a disc, check what its slot opens for your opponent: a winning move on top of yours is the most common way to lose.

Credits and licence

Four in a Row was created by Kenrick, who published it as the open-source project "c4". The game is released under the MIT licence; the licence text is linked from this page. This version has been changed by FredyGames: the online mode was removed and the visible names were adjusted.