About This Solver
This is a perfect Connect 4 solver — it can find the optimal move for any position on a standard 7×6 board. Given any sequence of moves, the engine will tell you whether the current position is a win, draw, or loss, and by how many moves.
How to Use
- Click any column (or the arrow above it) to drop a disc.
- Click Show Solution to see the score for every column.
- Switch to vs AI mode to play against the unbeatable engine.
- Use Undo to take back the last move.
- Use New Game to start over.
Score Meaning
| Score | Meaning |
|---|---|
| +N | Current player wins in N moves (positive = win) |
| 0 | Draw with perfect play from both sides |
| -N | Current player loses in N moves (negative = loss) |
More precisely, a score of +N means the current player can guarantee
a win, finishing the game in at most (43 - N) / 2 total moves from now.
A score of -N means the opponent wins in at most (42 - N) / 2
moves even with perfect play.
The Engine
The solver uses the Negamax algorithm with Alpha-Beta pruning, a Transposition Table, Iterative Deepening, and smart Move Ordering heuristics. This combination allows it to solve any position in milliseconds.
The C++ engine was written by Pascal Pons and is published under the GNU AGPL v3 license. Read the full step-by-step tutorial at blog.gamesolver.org.
Algorithm Steps
- Min-Max search
- Alpha-Beta pruning
- Move exploration order (center-first)
- Bitboard representation
- Transposition table (hash map)
- Iterative deepening
- Anticipate losing moves
- Better move ordering (score-based)
- Optimized transposition table
- Lower-bound transposition table