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 many 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 defined 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. Therefore there are no distinct generations, 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 non-guaranteed survival you will get evolution, it is unavoidable and can be applied in any situation in which those factors coexist.

Source code: Github

Try it yourself: Trilobytes-Alpha-Release-003.7z

  1. Download and unzip the folder,
  2. Double click on "Trilobytes.exe".
View Image View Image View Image View Image View Image

Help

What Am I Looking At?

Each organism, or 'trilobyte', 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 trilobyte. Food particles are represented by green circles.

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

The right hand column is the "Inspector view" depending on the currently selected entity in the simulation, this view will have tabs that offer detailed information about the entity. If a Trilobyte is selected for example, not only will a table of its traits be displayed, but in the next tab the inner details of the neural network that controls it will be displayed. The neuron activation can even be viewed live as the simulation runs. Hover the mouse over the neural networks for more information.

The bottom panel contains a number of customisable graphs. These show, among other things, the distribution of energy in the simulation between various entity types, the average age of various entity types, the average movement speed of trilobytes, and the performance of the simulation itself.

The Genetics

A trilobyte'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 trilobyte parent contributes a single chromosome from each pair, so that a child receives two copies of each gene (for a-sexual reproduction, the single parent's genome is copied and treated like two genomes from separate parents).

Currently the following genes exist:

  • GenePigment: Contributes to the final colour of the trilobyte,
  • GeneBrain: Contains the complete description of the main neural network for the trilobyte,
  • 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 trilobytes 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,
  • GeneSenseLunarCycle: Adds a sense which tracks a global value, which oscillates in a regular pattern. This allows individuals to react to a shared source of information,
  • 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,
  • GeneEffectorSpringTail: Adds an effector that allows the entity to jump forwards, energy is stored up and then released in a single burst of movement,
  • GeneEffectorSpike: Adds an effector that places a spike on the swimmers body, this will damage any swimmers that collide with it,
  • GeneEffectorFilterMouth: Adds an effector that each tick consumes any entity below a threshold size,
  • GeneEffectorProboscisMouth: Adds an effector that each tick leeches energy from any trilobyte or egg that it collides with its tip. The quantity of energy leeched per tick is limited,

The Interface

The interface is currently very simple, left click and drag on an entity to move it, middle click & drag to pan around the simulation, mouse scroll wheel to zoom, and you can right click on any entity to select it. When an entity is selected, details about it will be displayed in the right panel. When a trilobyte is selected, an additional tab will be available on the right, the "Brain Inspector" view.

Note that there are invisible handles between each section of the user interface that can be used to adjust the sizes of the panels, the invisibleness is a bug in Qt, there is a plan to work around it by drawing a custom handle. For now the mouse will change from a pointer to a resize arrow when it is over a handle.

Development log

~ April 2021 ~

This update brings a big overhaul to the user interface. The inspector view on the right now has tabs, allowing any entity to be inspected, and opening up oppertunities to give further inspection views in the future. The Graphs view on the bottom now contains more graphs, allows them to be opened and closed and most importantly, gives a set of controlls to fine tune each graph independantly. There are also more settings on the left side, though this aspect of the GUI is definitely still in need of a large update.

Behind the scenes, there have been a large number of tweaks to how mutations work for genes, and now there are many more ways each gene can mutate. There are also new genes, and Effectors. The new mouthparts allow for optional predation, and spikes both environmental and growable add new dangers to evolve defences for.

Entities can now be moved around using the mousse to click and drag them.

The build system has been switched to use CMake, tests have been added, which uncovered a few bugs. Utility classes have also been moved into a seperate library.

The new build system has also made it easier to include third party libraries, including a json lib, so now genomes can be saved to file (loading Genomes from file to follow in a future update).

View Image View Image

Try it yourself: Trilobytes-Alpha-Release-003.7z

  1. Download and unzip the folder,
  2. Double click on "Trilobytes.exe".

~ December 2020 ~

Under the hood there have been a lot of tweaks to the genetics, improving the scope of what can mutate and evolve. Trilobytes also now have "health" which can if completely lost, cause a trilobyte to die. A trilobyte that died from lack of health will transmute any remaining energy into a collection of "MeatChunks", and while there isn't anything that interactes with them yet, the intent is to allow predation to be a viable survival strategy in future updates.

View Image

Try it yourself: Trilobytes-Alpha-Release-002.7z

  1. Download and unzip the folder,
  2. Double click on "Trilobytes.exe".

Major features:

  • Networks can now mutate their width and height, allowing senses and effectors more flexibility in their possible mutations,
  • Trilobytes now have a notion of their health, when below 100% they will expend energy to heal, when it reaches 0% they die,
  • If a trilobyte dies with more than 0 energy, the energy is converted into meat chunks, which slowly decay if uneaten,
  • Lunar cycle, as yet unused but will be an available sense going forward, hopefully allowing disparate trilobytes to coordinate behaviour,
  • Base metabolism, trilobytes now have a variable basic energy usage per tick, based on the size and complexity of their senses and effectors,
  • Graphs are now configurable,
  • New graphs, showing lunar cycle stage, average health, average metabolism, trilobyte generation number and simulation tick performance,

~ Late October 2020 ~

The next stage of the project was to create a distributable release. Once this had been achieved, it was evident that a more polished set of controls were needed. This update therefore not only allows you to download and tinker with the simulation yourself, but it also contains a big update to the user interface.

View Image View Image View Image View Image

Try it yourself: Trilobytes-Alpha-Release-001.7z

  1. Download and unzip the folder,
  2. Double click on "Trilobytes.exe".

Major features:

  • Distributable release (Windows only for now),
  • More graphs, with more conventional axes and better labelling,
  • Controllable simulation speed & framerate,
  • Buttons! Settings now more intuitive and easier to use,
  • Brain Inspector improvements and view options.

There are still a few major items planned:

  • The ability for trilobytes to eat each other,
  • Entities need to be movable and createable,
  • Rendering options, to enable/disable senses, the quad-tree, and food spawners,
  • Food spawners need to me movable, creatable and adjustable.
  • Settings:
    • Reset: Removes all entities, sets time to 0 and respawns the default feeders and a number of default trilobytes.
    • Spawn Food: A toggle switch, when pressed down (default) food will spawn in the simulation. When lifted, food will stop spawning.
    • Select Fittest: Searches the simulation for the trilobyte with the most living descendants and selects it.
    • Follow: Each tick the Universe's view is adjusted so the selected trilobyte is always in the centre.
  • Simulation:
    • The mouse can be used to pan (left mouse button, click and drag), zoom (scroll wheel), and select a trilobyte (right mouse button).
    • Pause: A toggle switch, the simulation will not progressed when this button is down.
    • Limit: A toggle switch, when pressed down, the simulation will not delay between ticks (default).
    • TPS: "Ticks per Second" The value in this box is the maximum number of simulation ticks to be computed per second. The limit is only applied if "Limit" (button to the left) is pressed down.
    • FPS: "Frames per Second" The value in this box is the number of times the simulation draws itself each second. A higher value will result in smoother animation. A lower value will allow ticks to be computed more rapidly.
  • Brain Inspector:
    • The mouse can be used to pan (left mouse button, click and drag), zoom (scroll wheel).
    • Reset View: Re-centres the view of the neural network, and scales it to fit the entire network in the area.
    • UpdateLive: When checked, this option will calculate what the selected trilobyte is sensing and re-draw the trilobytes brain each tick. Blue nodes have a positive value, red nodes have a negative value. Connections can also be positive or negative, wider connections have a larger value, transparent connections are not currently in use. Sometimes a node will grow larger than normal, this implies it has a value > 1.
  • Graphs:
    • Energy: The combined ammount of energy contained by all of a particular entity type. Currently the green line represents food pellet energy, and the blue line represents trilobyte energy.
    • Mean Age: The average age (in ticks) of a particular energy type. Again green for food pellets, blue for trilobytes.
    • Oldest: Tracks the age of the oldest entity for each type. An increasing diagonal line represents the continued aging of the current oldest entity. A drop implies that the oldest entity died and the age of the next oldest entity is lower.

~ Early 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 trilobyte has a fully simulated genome. Genes add abilities to the trilobyte, like senses, pigments or limbs,
  • Trilobytes 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 trilobytes (blue line),
  • The inner workings of a trilobyte's neural network can be observed live, including all of the sensory inputs and all of the effector outputs,
  • Trilobytes can be followed, and the most fit trilobyte 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 trilobytes to eat each other,
  • Entities need to be movable and create-able,