A modular artificial life simulation with neural network brains, sexual reproduction, cannibalism, emergent evolution, and a real-time GUI dashboard.
- Neural network brains — 6→6→4 feedforward neural net drives all organism decisions (movement, aggression, mating). 70 evolvable weights in the genome.
- Sexual reproduction — organisms mate with genetically similar partners, performing crossover of both trait genes and neural network weights.
- Cannibalism — organisms with 2× energy of a nearby organism can eat it, gaining 50% of its energy.
- Death consequences — dead organisms drop food (corpse nutrients), creating nutrient cycling. Death causes tracked (starvation, old age, cannibalized).
- Emergent evolution — fitness emerges from survival and reproduction, not hardcoded rules.
- Genetic encoding — 8 trait genes (speed, vision, metabolism, reproduction threshold, mutation rate, lifespan, size, aggression).
- Realistic aging — telomere-like mutation load degrades lifespan across generations.
- Species clustering — distance-threshold clustering assigns species IDs by genome similarity.
- Real-time GUI — tkinter dashboard with live canvas, statistics, matplotlib graphs, and controls.
- CSV/JSON logging — all metrics saved for post-analysis.
/usr/local/opt/python@3.13/bin/python3.13 -m venv .venv
source .venv/bin/activatepip install -r requirements.txtpython main.pypython main.py --headlessalgomain/
├── main.py # Entry point
├── config.py # Configuration dataclass
├── requirements.txt
├── src/
│ ├── neural_net.py # Feedforward neural network (6→6→4)
│ ├── genome.py # Genome: trait genes + NN weights + mutation
│ ├── organism.py # Organism: NN decisions, mating, cannibalism
│ ├── environment.py # 2D toroidal world, food, spatial indexing
│ ├── simulation.py # Main engine loop
│ ├── controller.py # Thread-safe simulation control
│ ├── analytics.py # Metrics tracking & logging
│ └── gui.py # tkinter + matplotlib dashboard
└── logs/ # Auto-created CSV/JSON output
Edit config.py or use the GUI sliders:
| Parameter | Default | Description |
|---|---|---|
world_width × world_height |
1200×800 | World dimensions |
initial_population |
100 | Starting organism count |
max_population |
2000 | Population cap |
food_spawn_rate |
8.0 | Base food items per tick |
base_mutation_rate |
0.05 | Per-gene mutation probability |
cannibalism_energy_ratio |
2.0 | Attacker needs 2× victim energy |
mating_distance |
10.0 | Max distance for mating |
nn_weight_mutation_rate |
0.1 | NN weight mutation probability |
| Button | Action |
|---|---|
| ▶ Start | Begin a new simulation |
| ⏸ Pause | Pause the simulation loop |
| 🔁 Resume | Resume from paused state |
| ⏹ Stop | Cleanly terminate, save logs |
| ⏭ Step | Advance one tick (when paused) |
Each organism has a small neural network (6 inputs → 6 hidden → 4 outputs) that processes sensory information and outputs decisions:
Inputs: nearest food distance/angle, nearest organism distance/angle, energy ratio of neighbor, own energy ratio.
Outputs: movement angle, speed factor, aggression level (attack/flee), mate desire.
Weights are stored in the genome and evolve through mutation and crossover.
If an organism's energy exceeds 2× a nearby organism's energy AND its neural net aggression output is high AND its aggression gene is positive, it eats the victim. The predator gains 50% of the victim's energy.
Two organisms can mate if they're close enough, both have sufficient energy, their genomes are similar (same species), and neither is on mating cooldown. The child gets crossover of both parents' traits AND neural network weights.
Dead organisms drop food at their death location (corpse → nutrients). This creates nutrient cycling — deaths feed the ecosystem, making carnivorous strategies viable.
Death causes are tracked: starvation, old age, cannibalized.
- Every reproduction increments the parent's mutation load
- Mutation load reduces effective lifespan:
effective_lifespan = base * (1 - 0.02 * load) - Death probability follows a hockey-stick curve — safe until 60% of lifespan, then rapidly increasing
Logs are saved to logs/:
metrics_*.csv— per-tick population, genetics, aging, evolution, kills, matingsfinal_state_*.json— final snapshot with death causes and best organism genome
- Avida — digital evolution system
- Tierra — self-replicating organisms
- Conway's Game of Life — emergent patterns