A high‑performance, headless C# ecosystem simulator that models predator–prey dynamics using genetic algorithms and streams live state to a browser UI via SignalR. Built as part of my preparation for Software Engineering Degree applications, this project focuses on algorithmic efficiency, data visualization, and modern headless architecture.
- Headless Architecture: C# simulation engine runs independently from the HTML5 Canvas frontend.
- SignalR Real‑Time Streaming: Live frames are pushed directly to the browser (no file I/O jitter).
- Dual‑Species Evolution: Genetic traits mutate across speed, sight, metabolism, and reproduction.
- Predator AI: Includes adaptive hunting logic and cannibal mode under starvation.
- Algorithmic Efficiency: Custom spatial hashing enables O(1) neighbor lookups.
- Data Pipeline: Statistics exported to CSV with Chart.js visualizations + Python analytics.
Naive neighbor detection is O(n²), which is impractical at scale. This simulator uses spatial hashing to reduce lookup to ~O(1).
The project evolved from a WinForms UI to a headless + web architecture, where the C# engine acts as a fast computation core, and the browser receives live frames over SignalR.
Live sim view in browser plus historical graphs:
index.html– live HTML5 canvas viewExports/population_over_time.html– population trendsExports/critter_data_over_time.html– trait evolutionExports/predator_data_over_time.html– predator adaptation
Current (Stream-based WebSockets(HTML5 + SignalR))
https://github.com/user-attachments/assets/02d7dddd-4ec5-4a3e-bc12-e3de2647de99
Previous (File based json) https://github.com/user-attachments/assets/f572b674-0209-487c-bc96-823249f29f60
Previous (Winforms) https://github.com/user-attachments/assets/bf675d37-6fd8-48d3-8529-52602ea6620f
This project runs in GitHub Codespaces or local VS Code.
- Clone the repository and open in VS Code.
- Ensure .NET 10 SDK is installed.
- Press F5 (or Run/Debug).
- The simulation starts and hosts a SignalR server.
- Open
http://localhost:5000to view the live simulation.
(Optional) Run Python scripts in /Analytics for deeper CSV analysis.
The project includes 35 xUnit tests covering genome mutation, energy policies, and spatial hashing. CI runs on GitHub Actions.
- Core/ – Simulation engine, genomes, policies, statistics
- Entities/ – Critter, Predator, FoodPellet
- Environment/ – World + spatial hashing
- UI/ – HeadlessRunner + SignalR frame streaming
- Analytics/ – Python scripts for CSV processing
- Exports/ – CSV logs and HTML charts
Design patterns used:
- Strategy Pattern (energy policies)
- Template Pattern (genome abstraction)
- Observer Pattern (event-driven spawning)
- Delta‑compression for frame updates (reduce payload size).
- Parallelize
Tick()for large populations. - Add seasonal dynamics and terrain variations.
- Expand to additional species types.
- C# 12 / .NET 10
- SignalR (real‑time WebSocket streaming)
- HTML5 Canvas & JavaScript
- Python 3 (Pandas, Matplotlib)
- Chart.js
- xUnit
- GitHub Actions CI/CD