Interactive Evolution Simulator
About This Simulation
This interactive application is a simplified model of evolution by natural selection, inspired by the video "I programmed some creatures. They Evolved." by David Randall Miller. You are observing a population of simple digital creatures, each with a unique genetic code (a genome) that defines the wiring of its simple neural network brain. The brain processes sensory information (inputs) to decide on actions (outputs), allowing the creature to navigate its world.
The core loop of the simulation demonstrates the fundamental principles of evolution:
- Live: Creatures exist for a limited time (300 steps), moving around the world based on the decisions of their brains.
- Selection: At the end of a generation, a fitness criterion is applied. Only the "fittest" creatures (e.g., those that reached a specific area) are selected to reproduce. The others "die" and are removed from the gene pool.
- Reproduce: The selected survivors pass their genomes to the next generation. Their genetic code is combined with another survivor's (crossover) and is subject to random changes (mutation).
Over many generations, you can witness the population adapting to its environment. Successful traits are passed on and refined, while unsuccessful ones are filtered out, leading to the emergence of complex and efficient strategies from very simple rules.
Core Concepts Explained
Inputs (The Creature's Senses)
Each creature's brain receives 5 distinct pieces of information from the environment on every step. These are the only things it "knows" about its world.
X-Position:
Its horizontal location on the screen.Y-Position:
Its vertical location on the screen.Age:
How many steps have passed in the current generation (from 0 to 300).Border Distance:
How close it is to the nearest wall.Oscillator:
A rhythmic signal that cycles over time, allowing the brain to potentially develop time-based behaviors.
Outputs (The Creature's Actions)
Based on its sensory inputs and the connections in its brain, a creature can perform 4 types of actions.
Move X:
The desire to move left or right.Move Y:
The desire to move up or down.Move Forward:
An impulse to continue moving in its current direction.Move Random:
An impulse to move in a random direction, which can help it get unstuck.
Why the 300-Step Limit?
The 300-step limit for each generation acts as a simulated lifespan. This is a crucial element of the selection pressure. Without a time limit, a creature could wander randomly and eventually find the goal by pure luck. By forcing them to succeed within a fixed timeframe, the simulation selects for efficiency. Creatures that develop brains capable of moving directly and purposefully towards the goal are far more likely to reproduce than those that meander aimlessly. This mimics the pressures in nature where organisms must find food, shelter, or mates within a limited time and with limited energy.
How to Use
- Start/Stop: Toggles the simulation.
- Reset: Resets the current scenario to Generation 0 with a new random population.
- Scenario Selector: Choose the environment and the goal for the creatures.
- Parameter Sliders: Adjust the core variables of the simulation. Note: Changing Population, Genome Length, or Internal Neurons will automatically reset the simulation to apply the changes.
Population:
Controls the number of creatures in each generation. Larger populations are more genetically diverse but require more processing power.Mutation:
Adjusts the probability that a gene will mutate. High rates introduce variety but can destabilize successful genomes. Low rates lead to slower, more stable evolution.Speed:
Sets the maximum movement speed for the creatures.Genome Len:
Defines the number of genes (neural connections) in a creature's brain. Longer genomes allow for more complex behaviors.Internal Neurons:
Sets the number of internal "thinking" neurons. More neurons allow for more complex information processing between sensors and actions.
- Play Demo: This button automatically runs a high-speed demonstration, cycling through each scenario to showcase how creatures adapt to different challenges.
- Audio Toggle: Turns the sound effects on or off.
- Mouse/Touch: Click or tap on the canvas to see the genome of the nearest creature displayed in the browser's console (Press F12 to open).
- Stats Display: Shows key metrics like the current generation, survival rate of the last generation, and the step in the current generation's lifespan.
Future Directions
This simulation is a starting point. Many features could be added to make it more complex and interesting, allowing for the evolution of even more sophisticated behaviors:
- More Genes & Neurons: Allowing for larger genomes and more internal neurons would give creatures a greater capacity for memory and complex decision-making, potentially leading to multi-step strategies.
- More Senses & Actions: Adding sensors for things like population density, proximity to other creatures, or the ability to see food would open up new evolutionary pathways. New actions could include emitting pheromones to communicate or dropping barriers.
- The "Kill" Neuron: Introducing predation, where creatures could evolve to hunt each other, would add a fascinating and complex layer of selection pressure, leading to co-evolution of predator and prey.
- Interactive Environments: Allowing users to draw their own barriers, create food sources, or define custom safe zones directly onto the canvas would make the simulation a true sandbox for evolutionary experiments.
- Environmental Dynamics: The environment itself could change over time. Food sources could deplete and regrow, or safe zones could move, forcing populations to continuously adapt rather than settling on a single optimal strategy.