Connect Four

Drop discs on a 7×6 board and line up four to win.

Difficulty
Wins0
Draws0
Losses0
Moves0

Tap any column and your disc falls to the lowest empty cell. Line up four discs in a row, a column or a diagonal to win; a full board is a draw. Press 1 to 7 to drop in that column, move the cursor with the arrow keys and press Enter. On touch, tap a column, or swipe sideways to aim and swipe down to drop. Changing the level starts a new round.

FAQ

How do I play Connect Four?
You and the computer take turns dropping discs into one of the seven columns, and each disc falls to the lowest empty cell. The first side to line up four discs in a row, a column or a diagonal wins. A full board with no line of four is a draw.
What do the three levels change?
Easy picks columns at random and only blocks about half of the immediate threats, which suits learning the rules. Normal runs a four ply search and covers every chance you have to complete four. Hard deepens the search to six plies with alpha-beta pruning and a positional weight table.
How many moves does Undo take back?
One undo removes both the AI reply and your last disc, handing the move back to you. Undo is locked once the round is decided or the board is full, so start a new round instead.
Where is my win and loss record kept?
Every finished round updates the win, draw and loss counters, and the record is saved in your browser's local storage, so it survives a refresh. In private browsing modes that block local storage the game still runs, only the record is not kept.

How to use

  1. Pick a level

    Easy plays at random and misses some blocks, normal searches four plies ahead, and hard searches six plies with alpha-beta pruning. Changing the level starts a fresh round at once.

  2. Drop into a column

    Tap any cell in a column and your disc falls to the lowest empty row. While the AI is thinking the status line shows a short note, and extra taps are ignored until it answers.

  3. Line up four

    Four of your discs in a row, a column or either diagonal wins the round, and the winning line is highlighted. A full board with no line of four is a draw.

  4. Use undo wisely

    One undo removes both the AI reply and your last disc, handing the move back to you. Undo is locked once the round is decided, so start a new round instead.

  5. Keyboard and touch

    Press 1 to 7 to drop into that column, move the cursor with the left and right arrow keys, then press Enter. On touch you can tap a column, or swipe sideways to aim and swipe down to drop.

About this tool

Connect Four is played on a grid of seven columns and six rows. Two players take turns dropping discs into a column, and gravity pulls each disc down to the lowest empty cell. The first side to line up four discs in a row, a column or a diagonal wins. A full board with no line of four is a draw. Because discs stack from the bottom up, the lower half of the board carries far more value than the top. The centre column touches more winning lines than any other, which is why strong players open there. Quiet discs two rows down often decide what happens two moves later.

This version pits you against a computer opponent that always moves second. The three levels differ in how far ahead they look. Easy picks columns at random and only sometimes blocks an immediate threat. Normal runs a four ply search, and hard runs a six ply search with alpha-beta pruning and a positional weight table. The HUD keeps track of wins, draws and losses, and the record is stored in your browser. Every calculation happens on the page, with no network requests and nothing uploaded.

How it works

Connect Four was solved in 1988. Perfect play by the first player wins, provided the opening disc goes in the centre column. The proof came from a layered analysis that classified every position as a win, a draw or a loss. It leaned on threat sequences and parity arguments rather than a raw scan of the game tree. The board holds more than four trillion distinct positions, far too many to memorise, so human players work with a handful of principles instead. The result still matters for casual play. It explains why the first disc carries so much weight. One early slip can hand the round to a patient opponent.

The AI in this version runs a negamax search with alpha-beta pruning. The evaluation function walks all 69 windows of four cells and scores partial lines for both sides. A weight table adds extra value to cells near the centre. Deeper levels look further ahead: normal examines four plies and hard examines six, with a node budget that keeps replies quick on modest hardware. Pruning works only as well as the move order. The engine always tries the centre columns first and works outward. That ordering cuts the positions it actually visits to a small fraction of the raw tree.

When to use it

  1. Ten minutes to spare

    A round of Connect Four usually takes a minute or two, and the rules fit in one sentence. There is nothing to install and no account to create, so the game opens straight into play. Winning and losing both feel light, which makes it a good way to reset between two tasks.

  2. Practising deduction with kids

    Gravity gives this game one more layer of cause and effect than Tic Tac Toe. Children can see how a support disc lifts the next move into place. The easy level misses blocks now and then, so young players win often. The normal level waits for the day they want a fair fight.

  3. Watching a search think

    Connect Four is a classic exercise for game tree search: small enough to check by hand, large enough to need pruning. Switch to the hard level and watch it cover your threats, then compare its choices with the evaluation and pruning steps in the source. It reads better than pseudocode.

Tips & tricks

  • Open in the centre column, which takes part in more winning lines than any other.
  • Before you build, count the cells where the opponent could complete four on the next move.
  • Drop support discs under your own lines so one quiet move serves attack and defence.
  • Watch for moves that create two threats at once, since a single block cannot cover both.

Things to watch

  • Chasing your own line

    Stacking discs for your own line feels productive, but an unblocked threat ends the round. Scan the opponent discs before every move and cover any cell that completes four. The best cells defend and attack at the same time, and they are usually worth taking first.

  • Gifting a support disc

    A careless drop right above an opponent line lifts their disc into position. Look at the cells below your landing spot before you commit. If your disc raises a diagonal or a column for the other side, choose another column and let them do their own lifting.

  • Missing a double threat

    One disc can open two winning cells at once, and a single block cannot cover both. Build through the centre so two lines share a future disc, then wait for the reply. Most rounds turn on exactly this kind of early double point.

Related Tools