All games
🔴

Perfect Information

Connect Four

Bitboard alpha-beta with transposition table.

2 players2 solversStrong
Alpha-BetaHeuristicImport stateReplayBest move
Board
Tap a column to drop a disc for the player to move. Long-press (or right-click) a column to remove its top disc.
Red to move

Deep dive

How BoardSolve plays Connect Four

Connect Four was first solved in 1988 by Victor Allis (and independently by James D. Allen): the first player wins with perfect play by starting in the center column. BoardSolve ships a modern bitboard negamax engine in the same lineage.

Algorithm

Positions are encoded as a pair of 64-bit bitboards (one per player) following Pascal Pons' convention, which lets win detection, move generation and symmetry checks run in a handful of bitwise operations.

The search is a negamax with alpha-beta, anticipated-loss pruning (a move that creates an immediate threat for the opponent is cut), iterative deepening on a null-window, and a transposition table keyed by the canonical position key.

Move ordering is center-first (columns 3, 2, 4, 1, 5, 0, 6) — empirically the strongest static ordering, since central squares participate in the most four-in-a-row lines.

Opening book

An opening book stored in public/c4-book.json caches exact scores (in the Pons convention: positive = win for the side to move, magnitude = distance to the end) for early positions so the UI returns instantly.

References & further reading

  1. Allis, L. V. (1988) . M.Sc. thesis, Vrije Universiteit AmsterdamFirst published proof that Connect Four is a first-player win.
  2. Pons, P. (2015–) . blog.gamesolver.orgTutorial series whose bitboard representation and ordering BoardSolve follows.
  3. Tromp, J. Reference position counts and 8-ply database used to sanity-check the engine.
  4. Edelkamp, S. & Kissmann, P. (2008) . KI 2008, LNCS 5243