Work Home lab & side projects

A snake game where two AIs compete and improve

My snake AI started as a neural network I trained on a Raspberry Pi 5. Now it plays in the browser against a pathfinder, and both tune themselves in a league that keeps training on the visitor's device.

Play the snake game

Snake league: two learners and a judge An evolution strategy tunes the Pathfinder and population-based training tunes the Double DQN. Both play the same seeded games, a judge scores them on score and efficiency and learns the balance between the two, and a champion is replaced only when a challenger beats it. Each learner can borrow from the other. One league, two learners Pathfinder tuned by evolution Double DQN tuned by PBT Same seeded games identical food order Judge score + efficiency, learned mix Champions kept until beaten borrow
Two learners, one judge: both play the same games, and only a better champion is kept.

Results

37first DQN's best score, before it forgot
75league rounds trained offline so far
98%of the board the Pathfinder fills on average

The problem

My first DQN, trained on a Raspberry Pi 5, climbed from a score of 1 to 37 over about 2,200 games, then forgot it over the next several thousand. A plain pathfinder played better, but it never got any smarter.

What I did

  • A Double DQN rebuilt from the Pi version, with a bigger replay memory and steadier exploration, after the first network forgot what it had learned.
  • A Pathfinder that runs a breadth-first search to the food every move and checks it can still reach its own tail before eating.
  • A league where an evolution strategy tunes the Pathfinder and population-based training tunes the DQN settings. Both play the same games and are scored for food collected and path efficiency.
  • A judge adjusts the weight of score and efficiency within limits that keep both measures in use.
  • Training that runs offline on 12 worker threads or in the visitor's browser, on the graphics card through WebGPU when that's faster.

What I took from it

The Pi network lost performance after its best run. The league keeps a champion and replaces it only after a challenger does better on the same games, which limits that kind of regression.

Privacy