Skip to content
Toolcroft

Connect Four - Play vs AI or a Friend

Games & Puzzles

Play Connect Four in your browser against a depth-limited AI or a friend. Choose Easy, Medium, or Hard, undo moves, and track scores saved on this device.

AI difficulty

Search depth up to 4

Red: 0Draw: 0Yellow: 0
AI game results: Easy: You 0, AI 0, Draws 0 · Medium: You 0, AI 0, Draws 0 · Hard: You 0, AI 0, Draws 0

Click New Game to start.

How to use this tool

  1. Choose "vs AI" or "2 Players" mode. In AI mode, choose a difficulty, then click New Game.
  2. Click a column to drop your disc - it falls to the lowest available row.
  3. Undo the latest move or turn exchange before the game ends; connect four in a row to win.

Rules

Connect Four is a two-player strategy game played on a 7-column, 6-row vertical grid. Players alternate dropping colored discs into any column. Discs fall to the lowest available row in the chosen column due to gravity. The first player to align four of their discs in a row - horizontally, vertically, or diagonally - wins. If all 42 cells fill without a winner, the game is a draw.

Controls

Choose vs AI or 2 Players, then click New Game. In AI mode, select Easy, Medium, or Hard before starting; a changed selection applies to the next game, and the current game keeps the difficulty it began with. Click a column to drop a disc into its lowest empty row. Before the game ends, Undo restores the position before your last move and, in AI mode, removes the AI reply too. In two-player mode it removes one move. Undo is disabled after a result is recorded, and New Game starts a fresh undo history.

Strategy tips

  • Control the center: the middle column (column 4) is the most strategically valuable. A disc there can participate in horizontal, vertical, and diagonal threats simultaneously.
  • Build two threats at once: set up positions where you have two separate winning moves. Your opponent can only block one.
  • Beware of even/odd traps: in Connect Four, the row number (odd or even) of the winning cell determines who gets the first chance to play there. Understanding which player controls the odd and even rows in key columns is the basis of advanced play.
  • Block early: if your opponent has three in a row with an open end, block immediately - there is rarely a threat worth prioritizing over defense at that stage.

AI difficulty

The built-in AI uses minimax with alpha-beta pruning and a center-first move order. Easy, Medium, and Hard use search depths of up to 3, 4, and 7 reply plies after evaluating a candidate AI move. Iterative deepening keeps the best fully searched result if a 20,000-node or 120-millisecond budget is reached, so the displayed depth is a maximum rather than a promise that every position reaches it. At all levels, the AI first takes an immediate win and blocks a single immediate winning column when possible. Otherwise, it scores non-terminal positions by center control and groups of two, three, or four connected discs. This search is a useful opponent, not perfect play or a proof of the best move.

Connect Four is a solved game

Connect Four was strongly solved by Victor Allis in 1988. With perfect play:

  • The first player always wins if they play the center column first.
  • The second player can force a draw only if the first player deviates from the optimal strategy.
  • The game has 4,531,985,219,092 possible game positions.

Despite being solved, the game remains interesting at non-expert levels because optimal play requires deep look-ahead that humans cannot reliably perform. The first move advantage is strong enough that serious competitive play uses pie-rule bidding (where the second player can "steal" the first player's opening move to balance the advantage).

Frequently asked questions

How do you win?

Connect four of your discs in a row - horizontally, vertically, or diagonally - before your opponent does.

Is the AI beatable?

The AI searches to depth 3, 4, or 7 on Easy, Medium, or Hard. A node and time budget can stop deeper searches early; it checks immediate wins and single-column threats at every level. It is not perfect.

What does Undo do?

Undo restores the position before your last move. In AI mode it also removes the AI reply if one has happened; in two-player mode it removes one move. Undo is unavailable after a game ends, so saved results are not reversed.

Browse all games & puzzles