What is This Simulation?
This is an evolutionary neural network simulation where creatures controlled by small feedforward neural networks
learn to survive and find food. Each creature senses the world through numeric inputs, and its neural network outputs
movement accelerations every frame.
Continuous evolution: there are no discrete generations. Reproduction and replacement happen continuously
as the simulation runs. The most successful creatures (higher fitness / longer survival) tend to contribute more offspring
over time, while mutation and crossover introduce variation.
๐ง Neural Network Architecture
Each creature's brain is a feedforward neural network with:
- 12 Input Neurons - Sensory information about the environment
- Hidden Layer(s) - Configurable via Brain Designer (default: 12 โ 8)
- 2 Output Neurons - Control acceleration (X/Y)
The network uses TensorFlow.js for computation and processes inputs every frame to determine the creature's acceleration.
(Mating is influenced indirectly via movement; there is no explicit mating output neuron.)
Neural Network Inputs (12 total)
1. Vision Direction (-1 to 1): Weighted direction of visible food. -1 = food on left, 0 = center/no food, 1 = food on right.
2. Food Distance (-1, 0 to 1): -1 = no food in vision cones, 0 = collision boundary, 1 = at vision limit.
3. Creature Direction (-1 to 1): Direction to closest visible creature. -1 = left, 0 = center/no creature, 1 = right.
4. Creature Gender (-1, 0, 1): Gender of detected creature. -1 = same, 1 = opposite, 0 = none.
5. Creature Is Mate (0 or 1): Whether the detected creature is the current mate. 1 = is mate, 0 = not mate or no creature.
6. Creature Distance (0 to 1): Normalized distance to detected creature. 0 = collision boundary/none, 1 = vision limit.
7. Boundary X (-1 to 1): Normalized X position relative to center. -1 = left edge, 0 = center, 1 = right edge.
8. Boundary Y (-1 to 1): Normalized Y position relative to center. -1 = top edge, 0 = center, 1 = bottom edge.
9. Vel X: Normalized X velocity component (relative to max speed).
10. Vel Y: Normalized Y velocity component (relative to max speed).
11. Energy (0 to 1): Current energy level normalized by max energy.
12. Mate Energy (0 to 1): Energy level of the current mate (0 if none).
Neural Network Outputs (2 total)
๐ฏ Simulation Mechanics
- Food: Creatures gain energy by eating food. Energy is required to survive.
- Energy Decay: Creatures lose energy over time. They must find food to survive.
- Collisions: Colliding with walls or other creatures causes energy loss. Mates don't take damage from normal collisions, but do take damage if stuck pushing against each other.
- Same-sex collisions: Same-sex collisions apply a stronger energy penalty than opposite-sex collisions. A sneak attack is a same-sex hit from behind and applies +25% extra penalty to the victim compared to head-on.
- Mating: Creatures can form pairs. When bonded and eligible, they can produce offspring over time. The brain does not "press a mate button" - it only moves; mating emerges from movement + rules.
- Evolution (continuous): When creatures die (or when the sim needs to refill the population), they are replaced by offspring produced from successful parents via crossover + mutation. This happens continuously rather than in discrete generations.
- Fitness: Primarily based on time alive (frames lived) - this is the most important factor. Also includes smaller bonuses for food eaten, energy level, and exploration. Survival is prioritized above all else.
๐งฌ Mutation & Genetics
- Crossover (brains): Offspring brains are created via weighted crossover. The Gene Transfer Ratio is the probability each weight comes from the fitter parent (the rest comes from the other parent).
- Mutation (brains): After crossover, the offspring brain is mutated by iterating over the model weights. Each weight value mutates with probability Mutation Rate and is nudged by small random noise (kept intentionally small to reduce volatility).
- Mutation (vision genes): Vision distance + vision angle are treated as genes and can mutate on reproduction. Mutations are clamped to the configured min/max ranges.
- Mutation (color genes): RGB color genes can mutate on reproduction; colors are used for visualization (family outline/arrow cues).
- Architecture changes: Changing hidden layers in Brain Designer affects newly created brains. Existing creatures keep their current architecture.
๐ฎ UI Controls & Options
Top Controls:
- Pause: Pause/resume the simulation
- Reset: Restart the simulation with a new random population
- Background: Choose the canvas background color (saved in your browser)
- Show Vision: Toggle visibility of creature vision cones
- Brain Designer: Configure hidden layers for newly created brains
- Speed Slider: Control simulation speed (0.05x to 1.5x)
Statistics Panel:
- Population Slider: Adjust number of creatures (1-30)
- Alive: Number of living creatures
- Best Fitness / Avg Fitness: Fitness derived from living creatures
- Mated Pairs: Current mated pairs (all-time unique pairs in parentheses)
- Sneak attacks vs Head On: Same-sex sneak attacks vs head-on collisions, plus sneak rate (%)
- Avg frames per collision (same-sex): Average time between same-sex collision events (higher = less frequent)
- Crowding (nearby): Average neighbors within a radius (cheap spatial estimate)
- Food Collected: Total food eaten by currently living creatures
- Time (frames): Continuous-mode frame counter
- Oldest Living: Age of the oldest living creature (Select to monitor it)
- Oldest High Score: Longest lifespan achieved in this session
- Total Creatures Lived: Total creatures created in this session
- Average/Median Age (frames): Average/median age of currently living creatures
- Living Family Groups: Unique lineages/clans currently represented
- Active Creature / Monitoring: Select a creature to view live neural network diagram
Settings Panel:
- Energy Decay Rate: Energy lost per frame
- Collision Energy Penalty: Base energy cost applied on collisions
- Creature Skin: Visual style (Classic, Alien, Pet Rock, Bug)
Evolution Settings:
- Gene Transfer Ratio: Percent of brain weights inherited from the fitter parent during crossover (50-95%)
- Mutation Rate: Not directly controlled by a slider in visual mode; it is auto-adjusted based on fitness stagnation during the run.
Creature Settings:
- Max Speed: Maximum movement speed (1-10)
- Energy Per Food: Energy gained from eating (50-500)
- Exploration Noise: Random movement component (0-50%)
Mating System:
- Mating Enabled: Toggle mating system on/off
- Mating Distance: Maximum distance for mating (50-200)
- Buff Type: Bonus type for mated pairs (Energy Regen, Speed Boost, Fitness Bonus, Vision Range)
- Buff Strength: Bonus magnitude (5-50%)
- Mate Evaluation Frequency: Frames between mate candidate evaluations (5-30)
๐ฑ๏ธ Interactions
- Click on a creature: Select it to view its neural network diagram and statistics
- Neural Network Overlay: Shows the selected creature's input and output values as a small bar chart on the canvas
๐ก Tips
- Watch the neural network diagram to see how creatures process information
- Fitness is primarily based on survival time - creatures that live longer are more successful
- The sim injects some โrandomโ creatures (mutated/cloned from top families) when refilling the population (e.g., low population / extinction recovery) to keep exploration alive
- Mutation rate auto-adjusts based on stagnation; if learning stalls, mutation increases to explore more
- Mated pairs are more likely to pass genes, promoting successful strategies
- Creatures learn to balance survival, food gathering, energy conservation, and mating
- Continuous breeding: population evolves without discrete generations
- Use the "Oldest Living" Select button to monitor the longest-surviving creature