Connect Four vs AI

Four genuine difficulty levels. Easy is beatable by a 6-year-old. Impossible uses minimax to depth 12 and will not lose from a winning position. Pick your level and see how you do.

Your turn (Red)Move 0
You
AI
Click any column to drop your first piece
1
2
3
4
5
6
7

Keys: 1-7 drop piece - R reset - click column to play

What each difficulty level means

🟢

Easy

Depth 2

The AI thinks 2 moves ahead and randomly skips about 40% of its defensive moves. Ideal for children aged 5 to 8 learning the game. It will not instantly punish your mistakes, giving you time to think.

Tip: Any opening wins. Try building in the centre and watch the AI miss threats.

🟡

Medium

Depth 5

The AI searches 5 moves ahead and blocks immediate threats reliably. It evaluates positions based on piece count and centre column control. A genuine test for casual adult players.

Tip: Centre column + building two threats at once (a fork) will beat Medium most of the time.

🔴

Hard

Depth 8

Minimax to depth 8 with a strong evaluation function that weights centre control, threat creation, and piece connectivity. Wins the majority of games against casual adults. A real challenge even for experienced players.

Tip: You need to create forks and exploit odd vs even row threats. See the strategy guide.

🔵

Impossible

Depth 12

Minimax with alpha-beta pruning to depth 12. Connect Four is a solved game - with perfect play the first player always wins. At this depth, the AI approximates perfect play and will not lose from any winning position.

Tip: If you go first: play centre column every time and follow the strategy guide. If AI goes first on Impossible, you cannot win with perfect AI play.

How the AI actually works

The AI runs a minimax search with alpha-beta pruning. It builds a tree of all possible future positions up to the specified depth, then picks the move that leads to the best position assuming both players play optimally.

Alpha-beta pruning dramatically speeds up the search by discarding branches that cannot affect the final result. This lets depth 8 and depth 12 run in under a second in your browser with no server needed.

The position evaluation function rewards centre column control (the centre column touches more winning lines than any other), piece connectivity, and threat count. It heavily penalises positions where the opponent has three in a row with an open fourth cell.

Questions about the AI

Can you beat the Impossible AI?

Not if the AI goes first with perfect play. Connect Four is solved - the first player always wins with optimal play. If you go first on Impossible, you have the theoretical advantage and can win by playing centre column and following the strategy guide.

Why does the Hard AI sometimes make weird-looking moves?

At depth 8, the AI sometimes appears to ignore an obvious threat because it has found a deeper line where winning that way leads to a worse overall position. These are not mistakes - they are deliberate sacrifices. At Hard and Impossible, the AI is thinking further ahead than most human opponents.

Does the AI use a pre-computed opening book?

No - all moves are calculated in real time via minimax search. This means the AI's thinking time varies slightly depending on how complex the current position is, but it always finds the best move within its depth limit.