Four in a Row Game Online - Play vs AI

Drop discs to connect four in a row before your opponent. Play against a smart AI with Easy, Medium and Hard levels and keep a running win-loss tally.

Runs in your browser. No data leaves your device.

About this tool

Connect Four against a CPU on the standard 7-column, 6-row board. You play red and always move first; the CPU plays yellow. Drop discs into columns; the first to line up four horizontally, vertically or diagonally wins, and a full board is a draw.

Features
  • Three CPU levels: Easy searches 2 moves deep and plays a casual move 35% of the time, Medium 4 deep with 10% casual moves, Hard 7 deep and never plays casually
  • At every level the CPU always takes an immediate win and blocks your immediate win; casual moves avoid handing you a win directly on top
  • Minimax with alpha-beta pruning, centre-first move ordering and a window-based evaluation that favours the centre column
  • The CPU search runs in a Web Worker, so the page never freezes; its reply takes at least 400ms
  • Winning four discs are highlighted; drop animation for each disc
  • Running tally of your wins, CPU wins and draws, saved on the device
How to use it
  1. Choose Easy, Medium or Hard (changing it starts a new game).
  2. Tap or click a column to drop your red disc.
  3. Wait for the CPU's yellow disc, then play again.
  4. Connect four to win; Play Again starts the next game.
Inputs
  • Tap or click a column
  • Mouse hover shows a preview of where the disc will land
  • Keyboard: Left/Right or 1-7 choose a column, Enter or Space drops
Outputs
  • Turn / result status
  • Win-loss-draw tally across games
Limits and notes
  • Single player against the CPU only; there is no two-player mode
  • The tally is shared across difficulty levels
  • Saved in localStorage: tally (overtooled:four-in-a-row:tally) and difficulty (overtooled:four-in-a-row:difficulty); a game in progress is not saved
Keyboard shortcuts
  • Left / Right: choose column
  • 1-7: choose column directly
  • Enter / Space: drop in the chosen column
  • Esc: hide the result card to view the board

Frequently Asked Questions

How does Four in a Row work?

The CPU uses minimax with alpha-beta pruning on the 6x7 board, in a Web Worker so the page never freezes. Easy searches 2 moves ahead and plays a casual move 35% of the time, Medium 4 ahead with 10% casual moves, and Hard 7 ahead with none. At every level it takes an immediate win and blocks yours. Positions are scored by every 4-cell window plus a bonus for the centre column.

Can I play against another person?

No. Four in a Row is single-player against the CPU: you play red and always move first, the CPU plays yellow. Choose Easy, Medium or Hard. Your wins, losses and draws are tallied on this device.

How smart is the AI?

The AI uses a minimax algorithm to evaluate moves and can be quite challenging. It looks ahead several moves to block your winning combinations while building its own.

What are winning strategies?

Control the center column, build multiple threats simultaneously, and try to create a setup where you can win in two directions at once. Forcing your opponent to block one threat while you complete another is the key to winning.