Ever wondered how a Connect 4 bot decides where to play? Here’s what’s happening inside our Four in a Row AI, explained without the maths.
1. It looks ahead
The computer imagines every move it could make, then every reply you could make, then its next move, and so on. Each layer of moves is called a “ply”. The Hard level looks many plies ahead.
2. It scores positions
At the end of each imagined line, it gives the position a score: big plus for a win, big minus for a loss, and smaller scores for things like discs in the middle or lines of three.
3. It assumes you play your best (minimax)
The computer picks the move that is best for it, assuming you’ll always reply with the move that’s worst for it. This is called minimax.

4. It skips moves it doesn’t need to check
A trick called alpha-beta pruning lets it ignore lines that can’t change its decision. Checking middle columns first makes this much faster.
How the levels differ

| Level | What the AI does |
|---|---|
| Easy | Doesn’t look ahead: takes a win it can see, usually blocks yours, and otherwise plays near the middle |
| Medium | Looks a few moves ahead, always takes wins and blocks threes |
| Hard | Looks deep ahead and uses solver knowledge in many positions |
Think you can beat it? Play the computer.
Keep reading
- Play Four in a Row vs the Computer
- How to Beat the Computer at Four in a Row
- Is Four in a Row Solved?
More in Four in a Row Solver: Is Four in a Row Solved? · How the Four in a Row AI Works · Analyse Your Four in a Row Games
Back to Four in a Row Solver · Play the game now