Skip to content
All work

2025Deployed

Connect4 AI Agent

A Connect 4 agent that searches the game tree with minimax and alpha-beta pruning.

Stack
AI, Python, Game Theory

The problem

Connect 4 has over 4 trillion positions, so you can't search all of them. The agent has to look far enough ahead to play well inside a move-time budget.

Approach

Minimax with alpha-beta pruning skips the branches that can't change the outcome, so it searches several moves deeper for the same cost and plays a strong game within the time budget.

Decisions

  1. 01

    Alpha-beta pruning over plain minimax

    Plain minimax explores the whole tree to a given depth. Alpha-beta skips branches that can't beat what's already been found, which roughly doubles the depth reachable in the same time: the difference between a weak opponent and a strong one.

  2. 02

    Move ordering to make the pruning pay off

    Alpha-beta only prunes well if strong moves are tried first. Searching center columns before edges (they win more often in Connect 4) cuts far more branches than going left to right.

Results

Play it in the browser; the agent runs entirely client-side.

Try it