EcoSim

C++17SDL2ImGui

Real-time evolutionary ecosystem simulation where autonomous creatures with 90 unique genes compete, reproduce, and evolve across 22 climate-driven biomes.

90
Genes
22
Biomes
8
Chromosomes
4
Dominance Patterns
10
Archetypes
CGVC
Published
01

The World

Procedural generation with real climate science, not just Perlin noise.

EcoSim world map

Each simulation constructs a complete planetary surface from scratch. Seven stages in sequence, each building on the last:

  1. Heightmap synthesis: layered Perlin noise produces continental masses with realistic coastlines and mountain ranges
  2. Latitude banding: horizontal position sets base temperature, colder at poles, warmer at the equator
  3. Elevation lapse rate: temperature drops with altitude at ~6.5°C per 1,000m, the real atmospheric lapse rate
  4. Rain shadow modelling: prevailing winds deposit moisture on windward slopes, leaving leeward regions arid
  5. Precipitation distribution: combined moisture from wind patterns and elevation creates varied rainfall zones
  6. Whittaker classification: temperature + precipitation maps every tile to one of 22 biomes using real climate boundaries
  7. Flora seeding: plants spawn with biome-appropriate traits, establishing the initial food web
Whittaker Biome Classification Matrix
Arid
Dry
Moderate
Wet
Saturated
Hot 30°C+
Hot Desert
Savanna
Savanna
Tropical Forest
Tropical Rainforest
Warm 20-30°
Hot Desert
Savanna
Grassland
Tropical Forest
Tropical Rainforest
Temperate 10-20°
Steppe
Grassland
Temperate Forest
Temperate Forest
Temperate Rainforest
Cool 0-10°
Steppe
Shrubland
Temperate Forest
Temperate Rainforest
Temperate Rainforest
Cold -10-0°
Cold Desert
Taiga
Boreal Forest
Boreal Forest
Alpine Meadow
Frozen <-10°
Ice Sheet
Tundra
Tundra
Glacier
Glacier
The same algorithms that classify Earth's ecosystems classify this one. Temperature from latitude + elevation lapse rate. Precipitation from wind patterns + rain shadow. Biome from the Whittaker matrix above.
02

The Genetics Engine

The crown jewel. Not hardcoded species, but emergent traits from continuous gene values.

90 genes · 13 categories · 8 chromosomes · 4 dominance patterns
EcoSim Genome Inspector
90 genes · 8 chromosomes · 13 categories
C1Morphology
C2Sensory
C3Metabolism
C4Locomotion
C5Behavior
C6Reproduction
C7Environment
C8Combat
Chromosome 1
Morphology & Defense
14 genes
max_size0.5 – 10.0
Upper bound on body growth. Larger bodies deal more damage but cost more energy to maintain.
combat_damage1.2/dayapex_predator
color_hue0 – 360°
Body colour as hue angle. Breeding creates colour clustering as populations diverge into species.
species_identity
fur_density0.0 – 1.0
Insulation for cold biomes. High fur = slash vulnerability but enables burr seed transport (zoochory).
temp_toleranceslash_defenseborealis
hide_thickness0 – 5 mm
Blunt force resistance. Thick hides absorb impact but slow movement and cost energy.
blunt_defense0.8/dayfortis
horn_length0.0 – 1.0
Primary piercing weapon for herbivore defense. Costs energy to grow and maintain.
pierce_damagetank_herbivorecornuatus
scale_coverage0.0 – 1.0
Overlapping scales deflect piercing but are vulnerable to blunt force.
pierce_defensearmored_grazersquamatus
body_spines0.0 – 1.0
Passive contact damage to attackers. Defines the spiky defender archetype.
contact_damagespiky_defenderspinosus
fat_layer0.0 – 1.0
Energy reserve and thermal insulation. Enables famine survival and cold climate habitation.
energy_reservecrassus
Simulation active4 dominance patterns · 13 gene categories

Every organism carries a full genome of 90 genes organised across 8 chromosomes, each gene a continuous floating-point value between 0 and 1. There are no species definitions. No creature type enums. What an organism is emerges entirely from what its genes produce.

Diet type illustrates this perfectly. Rather than storing "herbivore" or "carnivore" as a flag, the simulation calculates diet from digestion gene values. A creature with high plant digestion and low meat digestion becomes functionally herbivorous, not because it was labelled that way, but because its genes make plant-eating efficient and meat-eating wasteful.

// Genome sample: digestion genes
plant_digestion: 0.82
meat_digestion: 0.15
fungi_digestion: 0.03

// Classification derived at runtime
plant_ratio = 0.82 / (0.82 + 0.15 + 0.03) = 0.82
plant_ratio > 0.7 Classification: Herbivore

Four dominance patterns govern inheritance: complete dominance, incomplete dominance, codominance, and epistasis. When two organisms reproduce, their chromosomes undergo crossover and mutation, producing offspring that are genuinely novel combinations, not clones, not random.

Universal energy budget: every gene has a maintenance cost. An organism can't be good at everything. Large bodies cost more energy. Thick armour slows movement. Sharp claws require calories. Evolution is forced to make tradeoffs.
EcoSim creature inspector
03

Creature Intelligence

State-machine AI driven by needs, with gene-controlled pathfinding.

Each creature runs a hierarchical state machine that selects behaviour based on current needs: hunger, energy, reproductive urge. The priorities shift dynamically as internal states change.

RestRecover energy when stamina drops below threshold
HuntTrack and pursue prey using sensory range genes
FeedConsume food sources based on diet capabilities
MateSeek compatible partners when reproductive urge peaks
ZoochoryDisperse seeds while moving through the environment
MovementNavigate terrain with gene-driven route preferences

Pathfinding uses A* search, but with a twist: the environmental_sensitivity gene controls how much terrain cost matters in route calculation. Creatures with high sensitivity stick to familiar, low-cost terrain. Creatures with low sensitivity take direct paths regardless of obstacles. This means pathfinding strategy itself evolves. Cautious navigators and bold chargers emerge from the same algorithm with different gene values.

The AI system was originally a 2,420-line monolithic class. Extracting it into a modular Strategy pattern, one class per behaviour dispatched by the state machine, was one of the project's most significant refactors. Each behaviour became independently testable and tuneable.

04

Combat & Predation

Rock-paper-scissors damage mechanics where shape determines type and size determines magnitude.

Shape genes determine damage type. Size genes determine damage amount. A small creature with piercing attacks and a large creature with blunt attacks occupy completely different combat niches, even at similar overall power levels.

Three damage types interact against three defence types in a rock-paper-scissors triangle:

Attack ↓ / Defence →ShellScalesFur
Blunt1.5×1.0×0.5×
Piercing0.5×1.5×1.0×
Slashing1.0×0.5×1.5×
EcoSim combat stats

This creates evolutionary arms races. When shell-armoured herbivores dominate, blunt-attacking predators gain an advantage. As blunt predators spread, fur-defended prey outcompete shelled ones. The cycle continues indefinitely, preventing any single body plan from permanently winning.

05

The Plant Kingdom

Often overlooked in ecosystem sims. Not here.

Plants are fully simulated organisms with their own genomes, not just static food sources. They compete for light and space, reproduce, and evolve dispersal strategies. Six emergent methods arise from gene combinations:

WindLightweight seeds carried by prevailing wind patterns
Animal-FruitNutritious fruit entices creatures to eat and carry seeds
Animal-BurrHooks and barbs attach to fur for passive transport
ExplosiveSeed pods build tension then burst, launching seeds outward
GravityHeavy seeds fall and cluster near the parent plant
VegetativeRunners and rhizomes spread clonally through the soil

Zoochory is the most interesting. Fruit-dispersed seeds are consumed along with the fruit, pass through the creature's digestive tract, and are deposited elsewhere; genuinely simulated endozoochory. Burr-dispersed seeds attach to creatures with fur and detach as they move, favouring long-distance transport by active animals.

Plants also evolve chemical defences (toxins, thorns) and creatures evolve corresponding resistances. This produces coevolutionary arms races independent of the predator-prey dynamics, a second axis of evolutionary pressure running in parallel.

06

Emergent Behaviour

All systems combine. Predator-prey oscillations. Speciation. Extinction events.

When all the systems run simultaneously, complex ecological dynamics emerge without being programmed. Predator and prey populations oscillate in classic Lotka-Volterra cycles. Populations isolated by mountain ranges diverge genetically, producing allopatric speciation. Sudden climate shifts trigger mass extinction events followed by adaptive radiation as survivors fill empty niches.

The simulation generates scientific names for emergent species based on their phenotype: diet, size, defence, and distinguishing features:

Carnopredax titan dentatus
Large apex predator with prominent teeth
Herboscutum grandis cornuatus
Armored herbivore with horn-like structures
Omniflexus minor vulgaris
Small, common generalist omnivore
How Scientific Names Are Constructed
Carnopredax titan dentatus borealis
Carnopredax
Genus
Carno = meat_dig > 0.7
predax = aggression > 0.7
titan
Species (Size)
Body size ≥ 2.5 units
Scale: minimus → titan
dentatus
Epithet (Trait)
tooth_sharpness > 0.5
Most distinctive feature
borealis
Climate
Tundra/Taiga adapted
fur > 0.7, fat > 0.6

Ten creature archetypes recurrently evolve across different simulation runs, convergent evolution emerging from selection pressure alone:

Apex Predator Ambush Hunter Pack Predator Armoured Herbivore Speed Herbivore Burrower Generalist Omnivore Scavenger Filter Feeder Parasite
07

The Paper

An early version of EcoSim was published at the Computer Graphics and Visual Computing (CGVC) conference as part of my BSc dissertation at Bangor University. The paper covers the foundational genetics engine, world generation, and emergent dynamics.

The current version is vastly more complex than what was published. The genetics system has grown from a handful of traits to 90 genes across 13 categories, the combat system, plant coevolution, scent communication, and classification systems were all added since. The paper represents where it started; everything above shows where it went.

View on Google Scholar