SnakePythonP5NeuralNet
August 31, 2026 ยท View on GitHub
A population of Snake controllers evolves through fitness-weighted parent selection, crossover, and mutation.
The simulation trains all configured snakes. The renderer shows at most the 10
highest-fitness living snakes. It uses the population index as a deterministic
visual tie-breaker. Change Settings.visibleSnakeLimit in settings.py to
adjust that limit.
Generation g uses food seed 2022 + g. Every snake receives the same food
sequence within that generation. The winning brain survives and competes again
on the next generation's new shared sequence.
Snake Lab
The game opens on a keyboard menu:
N: start a new random population.C: continue from the latest completed-generation checkpoint.H: open the Hall of Fame; use the arrow keys and Enter to load a brain.S: cross the top two Hall of Fame brains into a Super Snake founder.M: return to the menu from a running evolution.
Every completed generation overwrites .snake_champions/latest.npz and records
its metadata in latest.json. The Hall of Fame keeps only the best champion
from each evolutionary run, then ranks the best 10 distinct runs. Continue
resumes the loaded run ID; New and Super Snake create new run IDs. A Hall entry
receives a separate compressed genome in hall_of_fame.json. These runtime
artifacts are ignored by Git.
Run
Install uv and run:
uv run python sketch.py
uv creates an isolated environment and installs the pinned runtime
dependencies from pyproject.toml and uv.lock.
Test
uv run python -m unittest -v test_evolution_regressions.py
uv run pytest -q test_1.py
The regression suite checks the generation boundary, elite preservation, crossover, bidirectional mutation, and deterministic food reset.