Skip to content

About

A Unity life-simulation where quails (“Keklik”) roam, eat/drink, age, mate, and produce offspring, with built-in CSV reporting and graphing support.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

5 Commits

Folders and files

Repository files navigation

🐦 LifeSimulator

A 2D artificial-life simulation built in Unity, where a population of Keklik (chukar partridges) is born, roams, eats, drinks, ages, mates and passes on its genes — letting you watch population dynamics and a tiny bit of natural selection emerge in real time. Every run exports a CSV report that can be turned into graphs.

Unity C# Python License

Cycle metrics

✨ Features

  • Autonomous agents — every Keklik thinks for itself (roams, forages, seeks a mate) with no central controller.
  • Needs-driven behaviour — hunger, thirst and age tick down over time; ignore them and the bird dies.
  • Genetics & reproduction — offspring inherit the average of both parents' traits, plus random mutation and a blended colour.
  • Emergent population dynamics — booms, crashes and shifting male/female ratios appear on their own.
  • Live HUD & controls — pause, fast-forward (up to 100×) and choose the starting population (10–1000).
  • Data export — per-cycle metrics are written to a CSV, then plotted with a Python script.

🧠 How it works

The Keklik (agent)

Each bird is a prefab made of cooperating components:

Component Responsibility
Keklik Lifecycle controller — initialisation, mating, reproduction, death
KeklikStats All stats as validated properties (clamping + warnings)
KeklikNeeds Hunger, thirst, pregnancy decay and aging
KeklikMovement Roaming and foraging for food/water within screen bounds
KeklikGens Serialises/deserialises a bird's genome to/from a string

Needs & survival

Needs are evaluated every 0.5 s:

  • Hunger / Thirst decay each tick (×1.5 faster while pregnant). Reaching 0 is fatal.
  • Aging adds +0.1 per tick; once Age passes a random MaxAge (50–100), the bird dies of old age.

Movement & foraging

A continuous RoamAround coroutine drives each bird:

  1. If food < 50% → look for the nearest Fruit within vision range and eat it.
  2. If water < 60% → look for the nearest Water source and drink (refills to full).
  3. Otherwise wander to a random point inside its vision range, clamped to the camera bounds.

Speed and vision range are capped at 10; vision range also drives the bird's detection collider.

Mating & genetics

Males continuously run a Mating coroutine. When a male is well-fed and hydrated (> 75%), it scans its vision range for a non-pregnant female that is also > 75% fed/hydrated. On a match:

  • the female becomes pregnant (gestation ≈ 10 s of simulated time),
  • a baby is then spawned at her position and inherits, via InitBabyFromParents:
    • averaged max-food/water, speed, vision, decay rates and max-age,
    • random variation on speed/vision (±0.5) and max-age (±5),
    • a blended skin colour (Color.Lerp between parents),
    • a random gender (males grow horns).

Death

KillKeklik removes the bird from the live registry, stops its coroutines and destroys it. Causes of death: starvation, dehydration or old age — all logged to the console.

🌍 World objects

Object Tag Role
Keklik Keklik The simulated bird (sprite + vision collider + horns for males)
Bush → Fruit Fruit Food. Fruit grows over time and can only be eaten when ripe, then regrows
WaterPit Water A drinking spot that refills thirst

🎮 Controls (in-game UI)

Button Action
Keklik Count Cycle the starting population: 10 → 50 → 100 → 200 → 500 → 1000
Start Spawn the population and begin the simulation
Speed Cycle the time scale: 1× → 3× → 5× → 10× → 20× → 30× → 50× → 100×
Pause Freeze / resume the simulation
Restart Reload the scene for a fresh run

A live HUD shows cycle number, population, average speed/range/max-age and the male/female split.

📊 Data & graphs

While running, Reporter snapshots the population every 0.5 s and appends a row to Assets/KeklikReport.csv every 10 s:

CycleNo, AvgSpeed, AvgRange, AvgMaxAge, MaleCount, FemaleCount, KeklikCount

Assets/Scripts/csvToGraphs.py turns that CSV into a 5-panel chart (cycle_metrics.png) using pandas and matplotlib.

Note: average values are written as (5,097) (parenthesised, comma-decimal); the Python script normalises them to 5.097 before plotting.

🗂️ Project structure

Assets/
├─ Scenes/SampleScene.unity     # the simulation scene
├─ Prefabs/                      # Keklik, Bush (Fruit), WaterPit
├─ Scripts/
│  ├─ Keklik.cs                  # lifecycle, mating, reproduction, death
│  ├─ KeklikStats.cs             # validated stat properties
│  ├─ KeklikNeeds.cs             # hunger / thirst / pregnancy / aging
│  ├─ KeklikMovement.cs          # roaming & foraging
│  ├─ KeklikGens.cs              # genome (de)serialisation
│  ├─ Spawner.cs                 # spawns the initial population
│  ├─ Fruit.cs                   # growable, consumable food
│  ├─ Reporter.cs                # per-cycle metrics + CSV export
│  ├─ EventSystem.cs             # UI controls + live HUD
│  └─ csvToGraphs.py             # CSV → graphs (pandas + matplotlib)
├─ KeklikReport.csv              # sample run output
└─ cycle_metrics.png             # sample generated chart

🚀 Getting started

Requirements: Unity 2023.2.11f1 (2D), and Python 3 with pandas + matplotlib for the graphs.

git clone https://github.com/UKBey/LifeSimulator.git
  1. Open the project in Unity Hub (Unity 2023.2.11f1 recommended).
  2. Open Assets/Scenes/SampleScene.
  3. Press Play, choose a population with Keklik Count, then hit Start.
  4. Watch the HUD; a KeklikReport.csv is written to the Assets/ folder.

To generate the graphs:

pip install pandas matplotlib
# edit INPUT_CSV / OUTPUT_PNG at the top of csvToGraphs.py to your paths
python Assets/Scripts/csvToGraphs.py

📄 License

MIT © 2026 Ukbe Taha Şahinkaya

👤 Author

Ukbe Taha Şahinkaya — GitHub · LinkedIn

About

A Unity life-simulation where quails (“Keklik”) roam, eat/drink, age, mate, and produce offspring, with built-in CSV reporting and graphing support.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages