TroyDev

Animal Evolution Simulation

This projects aims to model animal evolution through natural selection. It does this by simulating an environment in which animal like entities grow and reproduce, while competing for food.

In normal genetic algorithms there are distinct stages or generations:

  1. Generate a random population.
  2. Test them all using a fitness function.
  3. Select a fit portion of the population, based on the fitness function.
  4. Create the next generation from the fit individuals, usually by copying them and adding small mutations to some.

In this program however there is no fitness function and there are no set generations. Instead the fitness of an individual can be considered to be how many offspring it manages to have. There is no equivalent to generations because, as in real life, some creatures will outlive others and successfully have offspring before or after each other.

In any situation where you have variation in a population, inheritable traits, mutation and variable survival you will get evolution, it is unavoidable and can be applied in any situation in which those traits all exist together.

Source code: Github

View Image View Image View Image View Image View Image

Help

What Am I Looking At?

Each organism, or 'swimmer', is represented by a coloured circle. The open circles represent senses that detect other entities within their area. The straight line points directly forwards and detects a single entity touching it, the closest to the swimmer. Food particles are represented by green circles.

Each swimmer can only detect items within the range of its senses.

The right hand column contains a graph. The axis are rotated 90 degrees clockwise, which means the (0, 0) is the top left, the y-axis runs along the top, and the x-axis runs down the left edge. The green line represents the energy contained by all existing food pellets, the blue line represents the energy held by all existing swimmers. There is no fixed quantity of energy however there is a limited spawn rate for food pellets. As swimmers become more efficient at finding food, they should eat the pellets more quickly, and waste less energy, shifting the balance of energy further from green to blue.

The bottom panel contains an inspector, this allows a selected entity to be analysed. The boxes along the top represent each of the sensory inputs a swimmer has, the middle big box is its brain, and the box along the bottom is its tail (or tails if it has evolved more than one!). The colour of a node represents its value, red is negative, blue is positive, the transparency denotes the size of the value. The values are usually between -1 (opaque red) to 1 (opaque blue), however if a value is bigger the node gets drawn larger. The connections can also be positive or negative. The width represents the size of the connection and the transparency represents the current usage of the connection.

The Genetics

A swimmer's genetics are quite complex. A genome can contain one or more chromosomes, which in turn can contain one or more genes. Chromosomes exist in pairs, like in real life eukaryotes. When combining genomes, each swimmer parent contributes a single chromosome from each pair, so that a child recieves two copies of each gene (for a-sexual reproduction, the single parent's genome is copied and treated like two genomes from seperate parents).

Currently the following genes exist:

  • GenePigment: Contributes to the final colour of the swimmer,
  • GeneBrain: Contains the complete description of the main neural network for the swimmer,
  • GeneSenseTraitsInArea: Adds a circular sense that detects all other entities within an area,
  • GeneSenseTraitsRaycast: Adds a line sense that detects the single nearest entity that is colliding with the line,
  • GeneSenseTraitsSelf: Adds a sense that measures certain aspects of the swimmers own state,
  • GeneSenseTraitsTouching: Adds a sense that detects all entities colliding with a single point,
  • GeneSenseMagneticField: Adds a sense that indicates the angle to (0, 0) and the distance to it,
  • GeneSenseRandom: Adds a sense that detects a low pass filtered number. The filter helps the value to change more gradually,
  • GeneSenseSine: Adds a sense that detects a constantly oscillating number, based on a sine wave
  • GeneEffectorTail: Adds an effector that allows the entity to move forwards, and turn left or right.

The Interface

The interface is currently very simple, left click & drag to move, scroll to zoom. All simulation options are listed in the top left:

  • Entities: The total number of entities in the simulation (food pellets, swimmers & swimmer eggs),
  • Swimmers: The total number currently living swimmers,
  • Paused (space): The sim can be paused and resumed by pressing the 'space' key,
  • Spawn Food (F): The food spawners can be toggled on and off py pressing the 'f' key,
  • Respawn (R): If all swimmers die, 'r' can be pressed to spawn 15 new swimmers, with default genetics,
  • Reset Graph (G)): Removes all points currently plotted on the graph,
  • Select Fittest (K): Selects the swimmer with the most living offspring,
  • Auto Select Fittest (A): Each tick, the fittest swimmer is selected automatically, toggling this also toggles 'Track Selected',
  • Track Selected (T): The view is updated to constantly follow the currently selected swimmer,
  • - N ticks old: The Number of simulated ticks that the selected swimmer has been alive (Note that dead swimmers can remain selected and will not age once dead),
  • - Laid N eggs: The number of eggs the currently selected swimmer has laid,
  • - Descendants N/M: The number of currently alive descendants of the currently selected swimmer / the total number of descendants the currently selected swimmer has ever had (stops updating once the swimmer has died),
  • - Energy N mj: The energy level of the currently selected swimmer, if this falls below zero the swimmer will die.

Development log

~ October 2020 ~

While this is the first build that has been documented on this website, it is actually roughly the fourth major iteration of this project. I may retroactively document some older versions, however the pipeline for new features is quite big, so there should be plenty of future content.

View Image View Image View Image View Image View Image

Major features:

  • Each swimmer has a fully simulated genome. Genes add abilities to the swimmer, like senses, pigments or limbs,
  • Swimmers can combine their genomes to reproduce sexually, or they can reproduce a-sexually,
  • A graph documents the total energy contained within all food pellets (green line) and all swimmers (blue line),
  • The inner workings of a swimmer's neural network can be observed live, including all of the sensory inputs and all of the effector outputs,
  • Swimmers can be followed, and the most fit swimmer can automatically be selected each time it changes.

This build is also notably lacking many things, next priorities include:

  • An executable! So far the only way to run this is to build it yourself,
  • Buttons! The GUI needs fleshing out, especially if I start distributing an executable,
  • The ability for swimmers to eat each other,
  • Entities need to be movable and create-able,