A neural network evolution simulator built with Python and Pygame. Watch populations of creatures evolve brains that learn to navigate a 2D grid and survive selection pressures over generations.
Each creature has a genome — a list of genes that encode neural connections. These connections form a small brain that reads sensor inputs and produces movement actions. Every generation:
- Sense — Creatures read environmental data (position, nearest edges, obstacles, etc.)
- Think — The brain processes sensor inputs through weighted connections and internal neurons
- Act — Output signals drive movement (move X/Y, move forward, move random)
- Select — Only creatures in the survival zone reproduce
- Reproduce — Survivors' genomes are crossed over and mutated to create the next generation
Over time, natural selection favours brains that move creatures into the survival zone.
- Real-time visualization — 128x128 grid rendered with Pygame, creatures shown as colored circles
- Genome-based coloring — Similar genomes produce similar colors, so you can watch the population converge
- Adjustable parameters — Sliders for population size, genome length, internal neurons, steps per generation, mutation rate, and simulation speed
- Multiple selection criteria — Right Half, Left Half, Center Circle, Corners, Right Quarter
- Brain Viewer — Pause the sim and inspect 10 random creatures' neural networks with a visual map of sensors → neurons → actions, weighted arrows, and a plain-English explanation of their strategy
- Survival graph — Track survival rate over generations
| Sensor | Description |
|---|---|
| LOC_X / LOC_Y | Normalized grid position |
| BOUNDARY_DIST | Distance to nearest wall |
| AGE | Progress through the generation (0→1) |
| LAST_MOVE_DIR_X/Y | Previous movement direction |
| RANDOM | Fresh random value each step |
| NEAREST_EDGE_X/Y | Which edge is closer (left/right, top/bottom) |
| POPULATION_DENSITY | How crowded the nearby area is |
| BLOCKED_FORWARD | Whether the cell ahead is blocked |
| OSCILLATOR | Sine wave cycling over the generation |
| Action | Description |
|---|---|
| MOVE_X / MOVE_Y | Move left/right or up/down |
| MOVE_FORWARD | Continue in last movement direction |
| MOVE_RANDOM | Random movement |
| SET_RESPONSIVENESS | How strongly the creature reacts to brain output |
- Python 3.10+
- pygame-ce
- NumPy
pip install pygame-ce numpy
python main.py- Start — Begin the simulation with current settings
- Pause / Resume — Pause or resume the simulation
- Reset — Stop and clear everything
- View Brain — Inspect 10 random creatures' neural networks (pauses sim automatically)
- Selection dropdown — Choose the survival zone
- Sliders — Adjust population, genome length, neurons, steps, mutation rate, speed
├── main.py # Pygame UI, rendering, and main loop
├── simulation.py # Simulation orchestration, selection, reproduction
├── individual.py # Creature class, sensors, and actions
├── brain.py # Neural network built from genome
├── genome.py # Genome class, crossover, mutation
├── gene.py # Gene encoding/decoding, bit-level mutation
└── grid.py # 2D world grid management