- Rust 90.4%
- JavaScript 6.9%
- HTML 2.7%
codex fixes: - cap inspects to 8/tick so a flooding viewer can't delay the sim - frontend only applies an inspect reply matching its own selection (replies are broadcast to all viewers) plan.md: mark Phase 1 + Phase 2 complete with verification summary. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbwTGyAQFYsVHee8LPSgRP |
||
|---|---|---|
| backend | ||
| frontend | ||
| .gitignore | ||
| plan.md | ||
| README.md | ||
Evolution — ecosystem & evolution simulation
A deterministic Rust ALife engine + zero-build HTML/Canvas viewer, decoupled over WebSocket. Creatures carry neural-net brains whose weights live in their genome — behavior is evolved, not scripted. The ecosystem runs on a closed energy loop (sunlight in, metabolic heat out), so carrying capacity and boom-bust cycles are emergent. Populations isolated in different biomes face different selective pressure and diverge.
See plan.md for the full architecture and design decisions.
What's real
- Evolved brains — 7-ray retina + interoception → recurrent MLP (966 weights in the genome) → motor outputs (turn, throttle, eat, attack, mate). No hardcoded seek/flee.
- Diploid genetics — 13 body loci with dominance + recombination, haploid brain weights with segment crossover, evolvable per-site mutation rate (mutator locus), MHC-like immunity vector.
- Closed energy loop — soil → plant → herbivore → carnivore → carcass → soil. Sunlight is the only inflow, metabolic heat the only outflow. Total energy is conserved every tick (tested).
- Allometric metabolism — Kleiber
mass^0.75basal cost + locomotion + sensory + neural upkeep, modulated per biome (desert punishes sprinting, tundra costs homeostasis). - Life history — birth → growth → maturity gate → sexual reproduction with egg provisioning; Gompertz senescence from an evolvable longevity locus (disposable-soma trade-off).
- Deterministic — one seeded RNG, fixed draw order, deferred births/deaths. Same seed → same run. Headless turbo mode fast-forwards; the WebSocket viewer is a read-only tap.
- Honest bootstrap — pure-random genomes, no safety net. When a population dies out the world auto-resets from a derived seed and increments a failed-attempt counter.
Biomes: Tundra · Desert · Rainforest · Volcanic (vertical bands).
Build & run
Requires a recent Rust toolchain.
Headless (evolve fast, print stats)
cd backend
cargo run --release -- --headless --seed 42 --ticks 200000 --every 20000
Prints pop / plants / carcasses / max-generation / resets | mean size per biome | total energy.
Two runs with the same --seed produce identical results.
Live (watch it in the browser)
# terminal 1 — the engine + WebSocket server (ws://127.0.0.1:8787)
cd backend
cargo run --release -- --seed 42
# terminal 2 — serve the static frontend
cd frontend
python3 -m http.server 8000
Open http://localhost:8000. You'll see creatures move, eat, reproduce, and die; the sidebar shows live population/generation/energy and per-biome stats. Spawn Disaster kills a slider-set fraction of the population — watch the population dip and recover.
Tests
cd backend && cargo test
Covers metabolism, genetics (gamete/fertilize/mutation bounds), brain forward pass, senescence monotonicity, energy conservation each tick, determinism (same seed → same state), and extinction reset.
Tuning
Energy balance is the live knob — all rates live as named consts in backend/src/config.rs.
The default regime shows large-amplitude grazer-plant boom-bust with occasional extinction+reset;
that's honest emergent ALife, not a bug. Edit K_*, PLANT_GROWTH_R, reproduction, etc. for
gentler or harsher dynamics.
Layout
backend/src/
config.rs consts (topology, metabolism K_*, energy rates) rng.rs seeded ChaCha8 + substreams
vec.rs Vec2 spatial.rs uniform grid + ray march
genome.rs diploid body + haploid brain, gamete/fertilize brain.rs MLP forward pass
sensors.rs retina + interoception biome.rs biomes + soil substrate
creature.rs metabolism, growth, senescence food.rs plants + carcasses
world.rs deterministic tick + closed-loop ledger + reset protocol.rs wire types
net.rs WebSocket viewer server main.rs headless | live CLI
frontend/
index.html canvas + dashboard main.js WS client + render loop
Phase 2 (layered on the running core): seasons, phenotypic plasticity, sexual selection + mate choice, disease/parasites → Red Queen, click-inspect + lineage tree, SoA/rayon/binary transport.