Four In A Row
Record: 0W / 0L / 0D
Tap a column to drop your disc. First to line up four — across, down or diagonally — wins. On desktop, keys 1–7 pick a column.

Connect Four

The classic four-in-a-row game against a computer opponent. Take turns dropping discs into a seven-column, six-row grid — they fall under gravity to the lowest free slot in whichever column you choose. The first player to line up four of their own discs horizontally, vertically or diagonally wins, and if the entire grid fills without either side completing a line, the game ends in a draw.

How to play

Tap or click any column to drop your disc there; a small indicator hovers above the board showing which column you're about to drop into before you commit. On desktop you can also press keys 1 to 7 to pick a column directly without moving the mouse. Undo takes back your last move and the AI's reply together as a pair, putting you back on your own turn exactly as it was before, rather than leaving you to face a board state that never happened in a normal game. Your win, loss and draw record is saved on your device and shown both on the start screen and at the end of every match, so it accumulates across sessions rather than resetting each time you play.

The AI is a real search, not a script

The computer opponent uses negamax with alpha-beta pruning — a genuine game-tree search algorithm that looks ahead several moves and assumes you'll play well in response, rather than following a fixed list of canned responses to specific board shapes. It evaluates each candidate move by scoring how many of its own three-in-a-rows and two-in-a-rows are still open versus how many of yours are, with extra weight given to control of the centre column, which sits at the heart of the most possible four-in-a-row lines on the board. Two implementation details make it play like a person rather than a machine going through the motions:

It searches centre columns first, in the order 4, 3, 5, 2, 6, 1, 7. In Connect Four the centre column is worth roughly twice an edge column in terms of how many winning lines pass through it, and searching it first lets alpha-beta pruning discard far more of the remaining branches early — delivering the same lookahead depth for a fraction of the computational work, which is what keeps the AI responsive even on a phone.

Its win scores are depth-adjusted, so a win available right now scores higher than the identical win reachable four moves later. Without that adjustment, a search treats all wins as equally good and will happily wander around for several turns before finally taking a win it could have taken immediately — which reads to a human opponent as the computer inexplicably missing the kill shot, even though technically it was still "winning" the whole time.

Difficulty

Easy looks two moves ahead and deliberately plays a random legal move about a third of the time, regardless of whether that move is actually good — so it makes genuine strategic mistakes rather than merely being short-sighted about deep threats. Medium searches four moves deep, plays soundly, and will reliably punish obvious blunders like leaving an open three-in-a-row unblocked. Hard searches six moves deep, sees most traps and forced sequences coming well in advance, and will actively set up double threats against you rather than only reacting to threats you create.

Strategy

Take the centre column early whenever it's open — it's part of more possible four-in-a-row lines than any other column on the board, so early control of it pays off across the whole game rather than just locally. Watch for double threats: a single move that creates two separate, independent ways to win on your next turn cannot be blocked by any one reply, since the opponent can only stop one of the two. Setting one of these up deliberately is how most well-played games are actually decided, far more often than a single obvious three-in-a-row. Be careful about which squares you hand your opponent, too — dropping a disc into a column always gives whoever plays next the square directly above it, so playing underneath a spot your opponent needs for their own line is a common, avoidable mistake worth watching for on every single move, not just when a win is imminent.

Why the AI feels different at each level

Because difficulty here changes both the search depth and, on Easy, the rate of genuinely random moves, the three levels don't just feel like the same opponent playing slightly worse — they feel like different opponents entirely. Easy will occasionally hand you a win outright by ignoring a threat it could see, which makes it a fair match for a first game or for playing casually. Medium plays a clean, sensible game without setting elaborate traps, which suits most players looking for a real contest. Hard plans several moves ahead and is genuinely difficult to beat without understanding double threats and centre control yourself, making it the level worth returning to once the basics feel comfortable.