A high-performance, parallelized 2D simulation of artificial life built with Rust and the Bevy engine. The simulation features autonomous entities ("cells") that evolve, interact, and communicate through neural networks.
- Neural Network Control: Each entity is powered by a Feed-Forward Neural Network (detailed below) that processes sensory data and dictates behavior.
- Life Cycle:
- Energy Management: All actions (movement, neural processing) consume energy.
- Energy Costs:
- Basal Metabolic Rate: 0.1 energy/sec (configurable) - cost of existing.
- Movement (Thrust): Up to 5.0 energy/sec - proportional to thrust intensity.
- Predation Attempt: 3.0 energy/sec - effort cost for attempting to eat (regardless of success).
- Reproduction: 50% of current energy - one-time cost to spawn offspring.
- Turning: Free - no energy cost for rotation.
- Signaling: Free - no energy cost for communication.
- Metabolism (The Sun Wave):
- Energy Source: A vertical "Sun Wave" represented by a soft Visual Gradient (layers of translucent yellow strips with vertical intensity variation).
- Adaptive Intensity: Under normal conditions, the wave provides 4.0 units/sec. If the population falls below 3,000, it boosts to 5.0 units/sec.
- Carrying Capacity (Blackout): If the population count exceeds the ecosystem's max population (default: 53,248), the Sun Wave enters a Blackout State (0.0 intensity) until the population drops back below the limit.
- Seasonal Variation: The sun's vertical focus shifts over a 600-second cycle (adjustable via the
SUN_CYCLE_SECONDSconstant), starting from the northern hemisphere and smoothly oscillating to the southern hemisphere and back. The entire sun wave visually moves up and down as a block of 16×8 segments, reaching from the world top to world bottom. - Vertical Gradient: Energy intensity depends on both horizontal proximity to the sun wave and vertical alignment with the current seasonal focus. The visual segments cluster around the sun's current position, clearly showing energy concentration zones. Energy calculations properly account for the toroidal world geometry in both horizontal and vertical directions.
- Social Energy Bonus: Bonded entities receive an energy multiplier equal to the bond energy setting times the number of bonds (e.g., 6 bonds × 1.5 = 9x energy bonus).
- Visual Indicator: The gradient's transparency reflects the energy intensity; during a blackout, the sun becomes completely invisible.
- Ocean Currents (Ripple Waves):
- Environmental Disruption: Random circular "ripple waves" that push entities outward from their centers.
- Frequency: Occur almost continuously every 0.5-2 seconds with random timing.
- Duration: Each ripple lasts 0.3-0.8 seconds and expands for 50-250 units in radius.
- Force: Applies 100-300 units/sec of outward force, decreasing with distance from center.
- Visual Indicator: Cyan-green circular rings that expand and fade as the ripple propagates.
- Predation (Eating):
- Mechanism: Entities can "eat" others to steal energy (Range: 4.0 units, Speed: 50 energy/sec).
- Attempt Cost: Attempting to eat costs 3.0 energy/sec (effort tax) regardless of success.
- Reproduction: Under the right neural conditions and energy surplus, entities can spawn children (costs 50% of current energy).
- Death: Entities are removed from the world when energy reaches zero.
- Social Bonding: Entities form physical and communicative "Bonds," creating complex multi-entity structures.
Reproduction is a core mechanism for evolution in Stevolve. When an entity reproduces, the following rules apply:
- Energy Split: The parent gives 50% of its current energy to the offspring.
- Neural Inheritance: The offspring inherits the parent's neural network weights and biases.
- Genetic Mutation: There is a 10% chance per parameter (
mutation_chance) for a mutation weight offset of up to 25% (mutation_rate). - Color Inheritance: Offspring inherit the BaseHue (color) of their parent with random mutations (±5°), creating visible evolutionary color lineages. Colors span the full spectrum (0-360°) with high saturation to ensure visual distinction even in statistical view modes.
- Social Bonding: Children are born with an active physical bond to their parent, enabling immediate communication and coordination.
- Positioning: Offspring are spawned directly behind the parent, facing the opposite direction.
Each entity possesses a unique, randomized feed-forward neural network that serves as its "brain." This brain controls all behavior based on the entity's surroundings.
- Layer 1 (Input): 3 sensory nodes.
- Layer 2 (Hidden): 5 processing nodes with
tanhactivation. - Layer 3 (Output): 5 action nodes with
tanhactivation.
- Vision: Detects the nearest entity within a 90-degree field of view (45° on either side).
- Range: Limited by the maximum vision distance.
- Normalization: Sensory input is a value from
0.0to1.0.0.0means an entity is touching the observer.1.0means no entity is detected within the cone or range.
- Resolution: The brain only receives data about the single nearest entity, creating a focused survival priority.
- Energy Level: The entity's current physical health/energy reserves.
- External Signal: The sum of values broadcasted by all currently bonded neighbors.
- Turn: Controls rotation (angle of movement). Cost: Free.
- Thrust: Controls acceleration (forward movement). Cost: Up to 5.0 energy/sec.
- Eat: Intention to steal energy from a target in front of the entity. Cost: 3.0 energy/sec (effort tax, regardless of success).
- Signal Out: A value between -1.0 and 1.0 broadcasted to all bonded neighbors (enabling social coordination). Cost: Free.
- Reproduce: Intention to spawn a child (requires significant energy). Cost: 50% of current energy.
- Simulation Toggle:
Spacebar: Pause/Unpause the simulation.
- Camera Controls:
WASDorArrow Keys: Pan the camera.+/-orMouse Wheel: Zoom in/out.
- Object Inspection:
Left Click: While paused, click on an entity to open a HUD displaying its properties (Position, Velocity, Energy, Neural Signals).- Network Size: Shows the total number of entities in the connected component (including the selected cell and all recursively bonded cells).
- Network Diagram: The zoomed-in visualization in the top-left shows a detailed map of the entire connected network - circles represent entities (selected entity in yellow, others in their hue color) and cyan lines represent bonds between them.
- View Modes: Use the radio buttons at the top to switch visualization modes. The hue (color) is always preserved from parent inheritance, while the brightness adjusts based on the selected metric:
- Energy: Hue preserved, brightness indicates current energy levels (dim at 0 energy, bright at 200+ energy).
- Eats: Hue preserved, brightness indicates successful predation events (dim at 0 kills, bright at 20+ kills).
- Spawns: Hue preserved, brightness indicates number of offspring produced (dim at 0 spawns, bright at 10+ spawns).
- Age: Hue preserved, brightness set to mid-level (reserved for future age tracking).
- Action: Entity color maps to its behavior this frame. Bright Red indicates a Successful Eat, while Bright Green indicates an Attempted (Failed) Eat. When not eating, entities visualize their External Signal: Yellow shades represent negative values and Blue shades represent positive values. In both cases, the brightness reflects the signal's absolute intensity (0.0 to 1.0).
- Color Lineages: The underlying hue (color) remains visible through ±5° per-generation mutations, allowing you to track family lines across the population regardless of brightness changes.
- Multi-Core Processing: Fully parallelized systems using Rayon and Bevy's parallel iterators, enabling 500%+ CPU utilization on high-core systems.
- Spatial Grid: Optimized collision detection and vision using a spatial partitioning grid to avoid O(N²) bottlenecks.
- Memory Efficiency: Reuses large data structures (like HashMaps in the brain system) via Bevy
Localstorage to minimize per-frame allocations.
cargo run --releaseThis will compile and run the simulation in release mode for optimal performance. The simulation window will open showing the artificial life world.
The simulation includes a real-time Settings Panel on the right side of the screen. You can adjust the following parameters:
- Metabolism: Base survival cost per second.
- Sun Power: Energy input from the Sun Wave.
- Mutation Rate: Intensity of neural changes per mutation.
- Mutation Chance: Probability of a neural parameter mutating during birth.
- Boost Pop: Population threshold below which the Sun Wave provides extra energy.
- Bond Energy: Energy multiplier per bond for socially connected entities (multiplied by number of bonds).
Note: Ocean wave parameters (frequency, strength, size) are currently fixed and not adjustable through the settings menu.
Use the [+] and [-] buttons to tune the ecosystem in real-time.
This project uses Bevy and can be built for Windows from Linux/macOS using Rust cross targets. Build on one machine and copy stevolve.exe to Windows (no Rust/Cargo required on the target).
On Windows:
rustup target add x86_64-pc-windows-msvc
cargo build --release --target x86_64-pc-windows-msvcOutput:
target/x86_64-pc-windows-msvc/release/stevolve.exe
- Install target:
rustup target add x86_64-pc-windows-gnu- Install Mingw (Linux example): Debian/Ubuntu:
sudo apt update
sudo apt install gcc-mingw-w64-x86-64Fedora:
sudo dnf install mingw64-gcc- Build:
cargo build --release --target x86_64-pc-windows-gnuOutput:
target/x86_64-pc-windows-gnu/release/stevolve.exe
- Copy the
.exeto Windows. - If GNU target, include required DLLs (may be system-provided or from
mingw):libgcc_s_dw2-1.dll,libstdc++-6.dll
- Run:
stevolve.exe
- Bevy uses system graphics drivers; ensure Vulkan/DirectX/OpenGL support is present.
- Fully static GPU stack is not generally possible; this is “minimal runtime dependency” packaging.
- For no toolchain on target: build on builder machine and ship final
.exe+ runtime DLLs.
The simulation can be compiled to run in web browsers using WebAssembly. This allows the simulation to run directly in the browser without requiring users to install Rust or any native dependencies.
-
Build the WASM package:
./build-wasm.sh
Or manually:
wasm-pack build --target web --out-dir pkg --dev
-
Serve the web application:
cd pkg python3 -m http.server 8000 -
Open in browser: Visit
http://localhost:8000in your web browser.
- Persistent Storage: Save/load functionality has been specially wired so that WASM applications interact directly with your system's native file dialogs.
- Cross-Platform: Runs on any modern web browser (Chrome, Firefox, Safari, Edge)
- No Installation Required: Users can access the simulation directly through their browser
- Performance: WebGL-accelerated rendering with hardware graphics support
All native controls work in the browser:
- Spacebar: Pause/Unpause simulation
- WASD/Arrow Keys: Pan camera
- Mouse Wheel: Zoom in/out
- Left Click: Select entity (when paused)
- S Key: Save simulation to system
.ronfile download - L Key: Load simulation via system file upload
- For best performance, use a modern browser with WebGL support
- The simulation runs at 60 FPS in browsers, similar to native performance
- Large populations (>5000 entities) may require a powerful device
- Saved
.ronfiles from a native simulation can be dynamically loaded into the browser, and vice versa!