Simulated Evolution

An algorithm for simulating evolution in a web browser


Even food distribution

The simulation starts with plenty of food and few microbes. At first the genes are set randomly. The microbes do not have a prefered direction. They are aimlessly wandering around effectively remaining on the same spot due to running in small circles. In the beginning this is fine because there is plenty of food. No matter how clumsy a microbe is moving it will find enough food to reach the energy level needed to start procreating. More microbes are created and suddenly the parent is competing with the child for food. Both are at the same spot and both are hardly moving into any direction. The local food supply is rapidly dwindling and it is now advantageous to be able to move away from the competition. Microbes which are equipped with genes that allow for fewer direction changes suddenly have an competitive advantage. They spend fewer energy for changing their direction an they can reach yet untouched areas of the simulation domain.

Soon an equilibrium is reached and the population is more or less stable. Microbes travel longer distances in straight lines with an occasional change in direction. The simulation is now a typical predator-prey interaction similar to the Wator simulation.

Image 5: With evenly distributed food supply microbes quickly learn to move in straight line for small periods of time. This allows them to reach regions with more food and escape local competition.

The Garden of Eden

The next scenario is often called the "Garden of Eden" scenario. Food is spawning randomly across the map but there is a small rectangular region in the middle of the simulation domain with a drastically increased supply of food. Soon microbes reaching this region will exhibit a wildly spinning behavior to avoid leaving the food supply. A degeneration in the genom causes microbes to constantly change their directions. On average they remain at their position by wildly going in circles. The reason is simple: Only microbes unable of leaving the Garden of Eden will benefit from its unlimited food supply in the long term.

Outside the "Garden of Eden" there is still food spawning but to a lesser degree. Some microbes will adapt to survive there. Food is sparse there and again the microbes living there are forced to wander long distances in order to survive. In a way its like seeing two different specied evolve due to natural selection.

Image 6: The Garden of Eden. A degeneration in the genom causes microbes to constantly change their directions. On average they remain at their position by wildly going in circles. Only microbes unable of leaving the garden of eden will benefit from its unlimited food supply in the long term.

Line Runner

What happens if we push the "Garden of Eden" scenario to an extreme? Lets say by almost exclusively spawning food along a few horizontal and vertical lines. Some food will also spawn elsewhere but not much. At first the microbes resort to their most basic strategy: Reducing the number of direction changes and travel long distances in order to survive by increasing the chance of finding food elsewhere. This will go on for quite some time until one of the microbes accidentally finds a line full of food. It will wander along this line and receive a sudden boost of energy resulting in a drastically increased chance of procreation. The longer it travels along the line the greater the benefit. Soon it will leave the line again but it will also have created offspring that has a slightly higher probability to walk longer distances in a straight line than the rest of the population. This will continue for quite some time resulting in a gradual decrease in the ability to change the direction.

At some point in time one of the descendants will find a line again. The genome is now set up in a way that very few direction changes take place. The energy boost from finding the line will reduce the probability even more in some of its descendants. They will eventually loose the ability to move away from the line altogether. From this point on a new species of "Line Riders" will populate the line. Soon other lines will follow until the "Line Riders" become the dominant species in the simulation.

Image 7: Spawning food primarily along horizontal and vertical lines will eventually lead to the creation of a species of "Line Riders" that live on the linear food spawning areas.


The Javascript source code is available for download at GitHub.

The evolution simulator is part of the Javascript-Toys repository at GitHub. In order to run it a HTML 5 capable browser is needed. I recommend using a Javascript Debugger like Firebug (for Firefox Browser) in order to play with the code.


  1. “Evolution.” Wikipedia: The Free Encyclopedia. Wikimedia Foundation, Inc., Web. Date accessed (20 January 2015).
  2. "Simulated Evolution" Web Article by Michael Palmiter, Ph.D., Temple City, CA.
  3. "Computer-Kurzweil 2" Spektrum der Wissenschaft: Verständliche Forschung, 1992, ISBN 3-86025-030-2

You might also like: