🔴 Connect Four · AI

← Portfolio

You play against an opponent written from scratch using the minimax algorithm with alpha-beta pruning — the same family of algorithms behind chess engines. It memorizes no moves: each turn it explores the game tree a few thousand positions ahead and picks the best one. You are red, you move first.

Your turn

Settings

What the AI is thinking

Positions evaluated
Branches pruned
Thinking time
Position evaluation0

Positive = the AI is ahead, negative = you are.

🌳 How it works: the AI builds the tree of every possible continuation down to the chosen depth and assumes you both play optimally — minimax. Alpha-beta pruning cuts the branches that cannot change the outcome, reducing the positions to evaluate hundreds of times over. Positions with no clear win are scored with a heuristic: aligned windows of 4 cells are worth more, and the center column is valuable. Ordering the moves from the center outward makes pruning even more effective.