Evolution Simulator

Project description:

This project is a simulation of evolution on a map with animals (“creatures”) and food. Evolution occurs with four attributes: speed, turn speed, size, and field of vision. This was my Java class final project. Uses the Princeton University StdLib for the window/visuals.

This project was largely inspired by The Bibites, by Leo Caussan. If you find this project at all interesting you should watch a video of The Bibites as it has much more depth than this.

Video description of the project (better visuals and explanations)

Evolution

For evolution to occur in a creature/environment three things are required:

  1. Something to change (genes)
  2. A way for that thing to be changed (mutations)
  3. A reason to change (hunger/energy)

In the simulation there are “creatures” and food pellets. The creatures move always move forward and turn towards food.

Creatures eat the food when they are in contact with it to gain energy. Creatures lose energy overtime based on the value of each of their genes/attributes and the costs of those attributes.

Food spawns near “food spawners” that slowly drift around the map to encourage speciation and also to encourage evolution of the speed and turn speed genes. The quantity of food on the map is controlled by the map size and food density variables.

When a creature has over some threshold of energy they reproduce and their child has their genes with a chance for mutation in each gene. Creatures also age and slow down so that evolution occurs faster.

Vision

For a creature to survive it needs to be able to see. Vision occurs in three steps:

  1. A list of food within the view distance is created (purple)
  2. The list is reduced to only what is within the creature’s field of vision (blue)
  3. The closest food pellet in the list is what the creature turns to (cyan)

Vision is affected by two genes, size and field of vision. Higher sizes increases the view distance (how far the creature can see) and higher field of vision gene values increase how wide of an angle the creature can see.

Simulation Analysis

Different statistics of the simulation are recorded in a CSV file every x steps (usually 1000). These values can be imported into spreadsheets (I use google sheets) to graph the change in gene values over time. The gene values are more coherent when normalized.

This graph was from a simulation on a map approx. 25x bigger than what I usually use. When the population becomes stable the graph shows a sine like cycle of highs and lows because when there are more creatures there is less energy per creature, so many die, and when there are few creatures they each gain more energy and reproduce.

Simulation Flaws

There are a lot of things I wish I had thought of or had time to add while working on the project. This is a list of some of them.

  • There are no physical or environmental barriers so speciation is difficult
  • Creatures only have one food source which also makes speciation more difficult (the ability to eat dead creatures or even to kill other creatures could solve this)
  • Evolution is only through gene values (no neural evolution or evolution of new parts)
  • Important variables are spread throughout multiple scripts and values are hard to understand/ambiguous (e.g. speed energy cost is usually 0.00045 [this is per tick])
    • It is tedious to find values that don’t make it to easy to survive and don’t immediately cause extinction.
  • The map can only be a square (this wouldn’t be hard to fix but I haven’t had a reason to)
    • The map also could have screen wrapped but I think it’s better if it doesn’t
  • The UI doesn’t have much information, most has to be read from the CSV file
    • A per creature UI panel could work, as well as an evolution overview with inbuilt graphs instead of data having to be exported
  • The simulation cannot be influenced/updated while running (outside of a few hotkeys)
  • The “camera” cannot be zoomed or scrolled so it is hard to see creatures clearly on especially small/large maps
  • Creatures are born directly rather than being laid as an egg which makes children immediately compete with their parents
  • and more…

Conclusion

I think overall this project was successful, especially since it was just for a school project. It successfully demonstrates evolution and the environment can be modified (somewhat at least) to create unique simulations that encourage evolution of different genes. Simulations can be analyzed to give insight on how a creature evolves to handle different situations. It can also be pretty fun to just watch.