Four in a Row

Public domain classic

Drop discs and line up four before the computer does.

Four in a Row

At a glance

Board
7 columns by 6 rows. Line up four of your gold discs across, down or on a diagonal
Players
You against the computer, and you always drop first
Difficulty
Easy, Normal and Hard. Normal is set when the page opens
Controls
Tap or click a column. With a keyboard, Left and Right move the marker above the board and Enter drops. Esc pauses
Score
A win scores 100 plus one point for every slot still empty. A draw scores 50 and a loss 0
Saves
Your best score, in this browser only
Cost
Free, no account

How this Four in a Row plays

  • A disc drops to the lowest empty slot of the column you choose. A tap anywhere in a column counts, from just above the board down to the bottom row. A full column ignores the tap.
  • The disc takes about 0.4 seconds to fall, or 0.08 seconds if your device asks for reduced motion. Taps during the fall, and during the computer's turn, are ignored. Once your disc lands the computer waits about a third of a second, then drops its own.
  • Four of one colour in an unbroken line, across, down or on either diagonal, ends the game at once, and the winning four are ringed in white. A line never wraps from one side of the board to the other.
  • If all 42 slots fill with no four, the game is a draw.
  • With a mouse, a glowing disc above the board shows which column you are pointing at before you click.

How the computer plays

  • It searches ahead with minimax and alpha-beta pruning. After its own drop, Easy also looks at your reply, Normal looks three drops further and Hard five.
  • Where a search line stops, it scores every group of four slots in a row. A group holding only its discs adds 1, 12 or 100 for one, two or three of them. A group holding only yours takes off 1, 15 or 130, so your threats weigh a little more than its own. Each disc in the middle column is worth 6 to whoever owns it.
  • A four found in the search outranks everything else, and a quicker four beats a slower one.
  • It tries the columns from the middle outwards and keeps the first of any equal scores. There is no randomness: the same position always gets the same reply at the same level.

In the rule test the three levels chose on the same 60 positions. Easy and Normal picked different columns in 8 of them, Normal and Hard in 16, and Easy and Hard in 17. In the test positions where one disc would finish a four, every level completed its own and blocked yours. Dropping random columns against it, the test lost all 20 games at each level. The slowest Hard choice took under 0.2 seconds.

What the shape of the board means for you

This board holds 69 different lines of four. The test counted how many of them touch each column: 15 for each edge column, 27 for the next ones in, 39 for the next and 51 for the middle column. A slot near the centre belongs to as many as 13 lines, a corner slot to only 3.

  • The middle column touches the most lines, and the computer adds 6 points for every disc there, so expect it to want that column as well.
  • A slot can only be filled from below. A winning slot with an empty slot under it has to wait, and whoever drops into the slot beneath hands the other player the one above.
  • Two threats at once. Each turn places one disc, so two different winning slots that can both be filled next turn cannot both be blocked.
  • Easy sees one reply. It checks your answer to its drop and nothing after that, so a trap two drops deep is outside its search.

For a game where you claim boxes instead of lines, try Dots and Boxes.

Known limits

  • No undo.
  • Picking a level during a game throws the board away and starts a new one.
  • A loss scores 0 however close it was, so only a win or a draw can raise your best score.
  • In a 1280 by 720 browser window the game area is 848 pixels high, taller than the window, so scroll a little or use Fullscreen.
  • On a 390 by 844 phone screen each slot is 47 pixels wide, and in our check the cookie notice lay over the Play button until it was answered.
  • Moving to another tab pauses the game.
  • With storage blocked the game still plays but forgets your best score.

How it was built and checked

AI tool
Codex
First committed
2026-10-14, in a batch of 10 classic games
Size
One HTML file of 172 lines, no game libraries
Rounds of changes
1 at build, from the build record. Changed once since, on 2026-11-11: Normal searched as deep as Hard, so those two levels made the same moves. Normal now looks three drops past its own instead of five
Checked at build
A syntax check and two targeted rule checks: a first disc landing on the bottom row, and four in a line across the bottom row. By its own account the build report did not verify how the game draws in a real browser, real touch screens, or how strong the computer feels
Checked since
2026-11-11: a new rule test (1,924 checks covering drops, full columns, all 69 lines of four, wins, losses, a full-board draw, the three levels on 60 positions, 60 games against random play, and taps and keys through the real pointer and key code), and an automated browser check of the local build at 1280 by 720 and 390 by 844. At desktop size it pressed Play, dropped discs by clicking columns and one with the arrow keys and Enter, played on until the computer made four, and pressed Play Again. At phone size it answered the cookie notice, chose Easy from the level menu, tapped columns until the game ended, and started again
Played on a phone
2026-11-11, a full game on a real phone before this page went live

Embed Four in a Row on your site

Free to embed. Please keep the credit link.

<div style="position:relative;padding-top:75%;max-width:640px"><iframe src="https://aivibecodedgames.com/games/four-in-a-row/" title="Four in a Row (free browser game)" style="position:absolute;inset:0;width:100%;height:100%;border:0" loading="lazy" allow="fullscreen" allowfullscreen></iframe></div>
<p><a href="https://aivibecodedgames.com/play/four-in-a-row/">Play Four in a Row free</a> on AI Vibe Coded Games</p>

How it was vibe coded

ToolCodex
Rounds of changes: 1
First committed2026-10-14

The opening prompt

Make the classic drop-disc game, 7 columns by 6 rows, you versus the computer. Animated falling discs, highlight the winning four, draw detection, hover preview of the drop column. Computer uses minimax depth 6 with alpha-beta, Easy (depth 2) and Hard toggle. Do not call it Connect Four anywhere.

What we learned

  • The prompt asked for Easy at depth 2 and a Hard toggle at depth 6. The build added a Normal setting between them but gave it the same search depth as Hard, so Normal and Hard dropped into the same columns. Having each level pick a column for the same positions in a test shows this at once.

Game controls

  • Tap or click a column to drop a disc
  • Left/Right arrows plus Enter also work

The game brief includes touch controls for phones.

Open the game on its own

More games