About the Game

This is an experiment where you play tic-tac-toe against an AI that learns through evolution. The game starts with a completely untrained neural network. After each match, the AI trains for several generations, and you play against whichever network has emerged with the best fitness score. It's satisfying to watch it go from clueless to competent.

The AI uses NEAT (NeuroEvolution of Augmenting Topologies), a genetic algorithm for evolving neural networks. Instead of training with backpropagation like most modern AI, NEAT maintains a population of networks (100 by default) and randomly mutates them across generations. Networks that perform well survive and reproduce; bad ones get culled. Amazingly, this actually works! The AI typically reaches solid play around 150-200 generations.

How It Works

Each "match" is actually two games: one where the AI goes first, one where you go first. This keeps things fair since the first player has an advantage. After your match, the AI trains in the background using web workers so it doesn't freeze your browser. Your progress is automatically saved to IndexedDB, so you can close the page and come back later without losing your training progress.

Behind the scenes, the AI isn't just playing against you. It uses a Swiss tournament environment with Glicko-2 rating calculations (like chess ratings). Before each tournament, networks face a standardized gauntlet:

  • A Minimax AI with perfect play
  • A "Sleeper AI" that makes random opening moves before switching to optimal strategy

This diverse training ensures the AI experiences a wider variety of game scenarios. The board is also canonicalized (normalized for symmetries), reducing the effective state space from 5,478 to just 765 unique configurations — making learning much more efficient.

Settings & Controls

If you don't want to play 20 matches waiting for the AI to get good, bump up the Generations per Match setting. At 100 generations per round, the AI evolves much more between games. You can also toggle Use Best Opponent to always play against the all-time best network instead of the current generation's leader.

The Algorithm dropdown lets you try different NEAT variants:

  • NEAT: The classic algorithm, perfect for this game
  • HyperNEAT: Generates network topology based on geometric patterns
  • ES-HyperNEAT & DES-HyperNEAT: Advanced variants with spatial structure awareness

Fair warning: ES-HyperNEAT and DES-HyperNEAT are computationally expensive. They'll work, but expect your CPU fan to spin up. These algorithms shine on more complex problems. Tic-tac-toe is honestly too simple to benefit from the more robust networks these algorithms generate.

You can even hot-swap algorithms mid-training without losing your population data. The system will save your old population and start a fresh one with the new algorithm settings.

Why Tic-Tac-Toe?

It's the perfect sandbox. The game is solved (perfect play always draws), so we know exactly how good the AI can get. It's simple enough that evolution happens quickly, but complex enough that a random network can't win by accident.

Around 500 generations, you'll notice fitness plateaus as the AI achieves near-optimal play. At that point, most games end in draws.

Learn More