Connect Four AI

Connect Four AI

Same board, different ways to think. Play against classic search algorithms or a neural network trained through reinforcement learning.

Why this game?

The rules fit in a sentence: take turns dropping a piece into a column, and connect four horizontally, vertically, or diagonally. The decisions are less simple. A good move has to account for what comes next and what your opponent might do about it.

That makes Connect Four a useful place to explore a question: how does planning ahead compare with learning from experience? Minimax and alpha-beta search possible futures. The DQN agent uses a convolutional neural network to learn the value of moves from games against a mix of opponents.

From Pygame
to the web

The project started as a Python game with a Pygame interface. The desktop app brings together game mechanics, configurable search agents, and a PyTorch training loop with live results for each validation opponent.

This web version brings the game and a trained CNN to the browser. Choose both players, adjust search depth, and try the opponents for yourself. Training stays in the desktop app.

How the opponents work