ChaosSim is a small grid-based ecosystem simulator written in .NET 8. It demonstrates a SOLID-friendly separation of concerns, allowing you to explore chaotic population dynamics by combining composable update rules.
ChaosSim.sln
├─ ChaosSim.Domain // Entities, value objects, and rule abstractions
├─ ChaosSim.Application // World state implementation, rules, and simulation engine
├─ ChaosSim.Infrastructure // Infrastructure services (e.g. randomness)
└─ ChaosSim.Console // Console host with a reference scenario
Key abstractions live in the domain project (GridCell, Individual, SpeciesDefinition, IWorldUpdateRule, etc.), while the application layer builds on them with a mutable world state, mutation context, and reusable simulation pipeline.
dotnet run --project ChaosSim.Console
The console host seeds two species across a 10x10 world, then executes 25 ticks using the default rule set (resource regeneration → foraging → movement → reproduction → metabolism). Each tick prints summary statistics and a subset of recorded events so you can observe emergent behaviour.
WorldBuilderprepares environment cells, species, and seed individuals.SimulationPipelineFactorywires rules into aSimulationRunner.- Each rule implements
IWorldUpdateRuleto mutate the world throughIWorldMutationContext:ResourceRegenerationRulereplenishes cell resources.ForagingRulelets individuals consume resources.MovementRuleguides individuals towards richer cells.ReproductionRulespawns offspring when energy thresholds are exceeded.MetabolismRuleapplies energy costs and ageing.
SimulationRunnerproducesSimulationTickResultsnapshots that aggregate state and events.
- Additional species traits: introduce predation, territoriality, or environmental resistances.
- New rules: add weather events, disasters, or disease spread by creating more
IWorldUpdateRuleimplementations. - Visualisation: project the snapshots into interactive dashboards (e.g. Blazor, MAUI) or export data for plotting.
- Persistence: capture snapshots to disk for replay or analysis.
- AI experiments: plug in optimisation loops that adjust traits and measure fitness over many runs.
- Use a deterministic
RandomSourceseed (already supported) for repeatable scenarios. - Validate individual rules in isolation by constructing small
WorldStateinstances and invoking the rules directly. - Consider approval or snapshot tests to monitor emergent behaviour when tweaking parameters.
Happy experimenting!