AI Snake — neuroevolving a snake
The classic Snake, but played by an evolving neural network instead of a human. Watch a population learn to eat without cornering itself.
Snake is a classic reinforcement-learning problem. I was curious whether pure neuroevolution could crack it — no reward shaping, no ready-made strategy, just selection and mutation.
Snake is harder than the dino: the networks quickly learn to eat, but then trap themselves with their own body. The key turned out to be the inputs — the network has to “feel” the free space around it, not just the direction to the food.
At first I fed the network the absolute coordinates of the head and the food — it didn’t generalize and only worked on one layout. Switching to relative sensors (rays cast outward) made the behavior meaningful.
Eat without cornering yourself
The same neuroevolution engine as the dino, but the task is qualitatively harder: the snake needs not reaction but the seeds of planning — otherwise it eats and immediately crashes into its own tail.
Like the other AI demos, the simulation runs in an isolated sandbox iframe — the heavy loop doesn’t block the main page.