A real-time 2D ecosystem simulation where autonomous agents — herbivores, omnivores, and carnivores — compete for food, water, and survival across four seasons. Every creature is driven by a small neural network brain that it inherits (and mutates) from its parent, so the population slowly evolves over time without any hand-written rules for individual behaviour.
→ Read the full simulation report
| Spring | Summer |
|---|---|
![]() |
![]() |
| Autumn | Winter |
|---|---|
![]() |
![]() |
- Neural-network-controlled agents — each creature has a tiny 6-8-5 feedforward brain. Inputs are proximity to food, predators, and water plus internal energy/thirst/health levels. Outputs drive steering, fleeing, and social behaviour.
- Four seasons that cycle automatically and affect plant growth rates, metabolism, and thirst drain.
- Disease spread — one creature starts infected; the infection transmits on contact with a probability proportional to proximity and time. Infected individuals recover or die.
- Emergent evolution — on reproduction the brain weights and physical traits (speed, size, field of view) are mutated slightly. Over many generations faster prey, sharper predators, and better foragers accumulate.
- Real-time statistics panel — live population graph, mortality breakdown, and averaged trait stats per dietary group.
- Video recording — pass
--record output.mp4to pipe every rendered frame throughffmpegand save a compressed H.264 file automatically.
| Dependency | Version tested | Purpose |
|---|---|---|
| raylib | 5.x | Window, rendering, input |
| g++ / clang++ | C++17 | Compiler |
| ffmpeg (optional) | 6.x | Video recording only |
Install on Ubuntu/Debian:
sudo apt install libraylib-dev ffmpegOn macOS with Homebrew:
brew install raylib ffmpegmakeThe binary is placed at ./lifu.
To clean build artefacts:
make clean./lifuRecord a full season cycle to a video file:
./lifu --record output.mp4| Key | Action |
|---|---|
1 |
1× speed |
2 |
2× speed |
3 |
5× speed |
4 |
10× speed |
5 |
20× speed |
Q |
Quit |
The world is divided into fixed 50 × 50 px cells. Every update tick, all living agents and plants index themselves into the grid. Perception queries for each agent then only iterate over the 3×3 neighbourhood of cells around the agent's position, keeping the per-frame cost close to O(n) rather than O(n²) even with hundreds of agents.
Each Brain is a plain 3-layer network (no backprop, no gradient descent):
inputs [6] → hidden [8] (LeakyReLU) → outputs [5] (Sigmoid)
Inputs:
- Normalised proximity to nearest food source
- Normalised proximity to nearest threat
- Normalised proximity to nearest water
- Current energy ratio
- Current thirst ratio
- Current health ratio
Outputs control: food-seeking drive, flee drive, water-seeking drive, social flocking drive, random-walk noise intensity.
On reproduction the parent pays an energy cost and produces one offspring. The child inherits all trait values but each weight and bias has a 12 % chance of being perturbed by ±0.2, and continuous physical traits (speed, size, FOV, max age) are scaled by a factor drawn uniformly from [0.85, 1.15]. There is no crossover — this is a purely mutation-based evolutionary scheme.
A season lasts 70 simulated seconds and cycles Spring → Summer → Autumn → Winter. Each season applies multipliers to:
- Flora spawn rate (
×2.0spring down to×0.35winter) - Metabolic cost per tick (
×0.85spring up to×1.5winter) - Thirst drain rate (
×0.7spring,×1.6summer peak)
The background tile colours and plant colours are also changed to reflect the season visually.
One herbivore is flagged as infected at startup. Infected agents:
- Lose 2.5 HP/s
- Move at 65 % of their normal speed
- Transmit the infection to any agent within
size + other.size + 3 pxat a rate of0.007probability per frame (at 60 fps this is roughly 0.42 %/frame) - Recover automatically after 20 s of infection, gaining a 18 s immunity window
Recording is done by opening an ffmpeg subprocess via popen and piping raw RGBA frames directly from raylib's LoadImageFromScreen() on every rendered frame. The recording stops automatically once a full four-season cycle has elapsed.
- Primer — Natural Selection — the core idea of watching evolution happen in real time: https://www.youtube.com/watch?v=f7vH2Li9KOw
- Simulator Evolution — ecological dynamics between predator and prey populations: https://www.youtube.com/watch?v=dyvqH7v6V0E
- Piping frames to ffmpeg — the recording technique using
popento stream raw video: https://www.youtube.com/watch?v=0To1aYglVHE
MIT License. See LICENSE for the full text.



