Four in a row vs a real search engine
Your turn — drop a disc
0
Wins
0
Losses
0
Draws
Options

Play Connect 4 Online vs the Computer

Play the classic Connect 4 (Connect Four, four-in-a-row) directly against the computer — free, in your browser, with no download and no sign-up. Drop red discs into the blue 7×6 board and line up four before the AI does. This is a single-player game built around an honest AI opponent: Beginner deliberately makes mistakes you can punish, Medium plays a solid tactical game, and Hard runs an extremely strong search engine that thinks about a second per move. You can choose who goes first, undo your last exchange, and your wins, losses and draws are tracked per difficulty in your browser.

How the AI thinks

The opponent here is fast because the whole position fits in a register. The board is stored as bitboards: each player's discs live in a single 64-bit number, so testing "is there a four in a row?" takes just a handful of bit operations. On top of that the engine runs negamax with alpha-beta pruning: it plays out possible futures for both sides, scores the outcomes, and picks the move with the best guaranteed result, skipping branches that provably cannot matter. A transposition table remembers positions reached by different move orders so they are only analysed once, and iterative deepening lets Hard search as deep as its time budget allows — in our measurements, depth 15 in the opening and 19 or more in the midgame, examining on the order of a million positions per move. The whole engine runs locally in your browser (in a background worker thread, so the page stays responsive), and nothing is sent to a server.

One honest note: Connect 4 is a solved game — with perfect play from both sides, the first player wins by starting in the center column. Our Hard engine is extremely strong against human play, but we don't claim it is perfect. That's also your way in: see the tips below.

How to play Connect 4 — the rules

Tips to beat the AI

FAQ

Can I play Connect 4 online against the computer?

Yes — this page is Connect 4 played directly against the computer in your browser. There is nothing to download and no account to create: pick a difficulty, choose whether you or the AI moves first, and drop your first disc. It works on desktop and mobile.

How strong is the Connect 4 AI?

The Connect 4 AI's strength depends on the level. Beginner deliberately plays some random moves, so it can miss your threats. Medium plays a solid tactical game: it always takes an immediate win and blocks yours. Hard runs a bitboard search engine (negamax with alpha-beta pruning and a transposition table) with about a second of thinking time per move — in our measurements it reaches search depths of roughly 15 moves in the opening and 19+ in the midgame, examining on the order of a million positions per move. It is extremely strong, though we do not claim it plays perfectly.

How does the Connect 4 AI work?

The board is stored as bitboards — one 64-bit number per player — so checking for four in a row takes a handful of bit operations. The engine then runs a negamax game-tree search with alpha-beta pruning: it plays out possible futures for both sides, scores the resulting positions, and picks the move with the best guaranteed outcome. A transposition table caches positions reached by different move orders, and iterative deepening lets it search as deep as its time budget allows. Everything runs in your browser; nothing is sent to a server.

Can I go first in Connect 4?

Yes — you can go first by using the 'You start / AI starts' toggle before a new game. Going first matters in Connect 4: with perfect play from both sides the first player wins, which is why letting the AI move first makes every level noticeably harder. Switching the toggle starts a fresh game immediately with your new choice in effect.

What are the rules of Connect 4?

Two players take turns dropping discs into one of seven columns; each disc falls to the lowest empty cell in that column. The first player to line up four of their own discs in a row — horizontally, vertically or diagonally — wins. If all 42 cells fill with no line of four, the game is a draw.

Is there a two-player mode?

No — this version is deliberately single-player versus the AI, like every game on the LK Forge games hub. The AI is the point: three honest difficulty levels, from beatable to extremely strong. If you want to play against a friend, pass the device back and forth — this page is built specifically for testing yourself against the computer.

Is AI Connect 4 free, and does it work offline?

Connect 4 is completely free, with no download and no sign-up. The game and the AI engine run entirely client-side in your browser, so once the page has loaded it keeps working even without a connection. Your win/loss record is stored locally in your browser. More AI games: AI Chess, AI Checkers, AI Othello, AI Tic Tac Toe or AI Minesweeper.

More AI games on LK Forge