J

 
#Evolution Simulator
View on GitHub

Evolution Simulator (working title) is a long-term project that I've been working on (and off) for a couple of years. The intention of this project is best summarised as:

A simulation of a rich and detailed environment where creatures must learn to survive. Through mutation and reproduction, species must evolve to be successful in their environment, to be able to avoid dangers, and to ensure the survival of their species. They must learn to find plants and how to hunt for food - or how to succesfully evade being eaten!

All creatures and plants contain a set of genes which defines how they look. In the case of creatures, additional genes that determine how they act in situations like hunting, foraging and nesting through the use of neural networks.

While this project is still in progress, there are several aspects which are largely complete, which I will cover in below sections.

Game Engine

When deciding what game engine to use, my first thought was Unity as I have a good amount of experience in it, and it would be quick to get something up and going. The thing that put me off using Unity was that I felt there was a lot of parts of the engine that I just didn't need, and with this being a simulation, that it might contain unnecessary overhead (for example, the graphics in the simulation will be simple primitives) . I have some experience designing and building game engines, so I decided to iterate on previous designs and build my own engine for the task (of course increasing the scope of the project, as this is now a simulation + engine...)

For building the engine I chose to stick with C# as this is most familiar to me and would make for quicker development (I have experimented with making an engine in C++ previously, and I found it very slow in terms of development time). I chose the OpenGL API for rendering as I have experience using this previously, through the library OpenTK. In previous cases of making game engines, I generally stuck to an object oriented approach with everything existing in hierarchies. This has caused me many issues in the past, so I decided to attempt to build this using the Entity-Component-System architecture.

World Map Generation

As mentioned in the summary at the start, one of the most important parts of this simulation is creating an interesting environment with lots of detail. The idea is we are creating creature which will exist and learn from the environment, so there must be a lot of variance. I will be taking advantage of procedural generation to do the heavy lifting of map design, with the added bonus that we can attempt simulations on different maps (ie, having islands separated by the sea).

I opted to use a fixed-sized map with tiles rather than a continuous plane for the creatures to exist on. I chose to use hexagons as the tile because it allows for islands to have more interesting designs - rather than limiting to vertical and horizontal edges. I have also been interested in mechanics of a hexagon based world (thanks Civilization V) and feel this is a perfect opportunity. Using tiles allows us to give characteristics to an area such as a biome, rather than having every point in the map needing a biome assigning.

A procedurally generated world map.
A procedurally generated world map.

The steps to generating a world are as follows:

  • Generate a height map using noise generation (can be Perlin, Simplex, Cubic, etc)
  • All tiles above point x is land, all below is sea
  • Generate a rain map using noise generation
  • Generate a temperature gradient which is cold on poles and hot in middle
  • Use rain map + temperature gradient to determine biomes
  • Add plants to biomes (biome determines what grows there and plant population density)

In the above map, the biomes we have are:

  • Deep ocean
  • Shallow ocean
  • Beach
  • Forest
  • Grassland
  • Shrubland
  • Desert

Creature Generation

My aim with generating creatures is that they must be entirely defined by the instructions contained in their DNA. My current method allows for 2 body types (single segment and multi segment).

Generation of a segment from a creature
Generation of a segment from a creature

I've put together a simple body generation algorithm that works like this:

  • Sweep 180 degrees around the origin and plot n points. The distance between the point and origin is determined using Perlin Noise.
  • Connect these points together.
  • Mirror the image and connect all the points together again.

The parameters for this generation is stored within the DNA, which means they are open to mutation. The segment will evolve slowly, however due to recessive genes (discussed later) some segments can change suddenly.

Evolution of a segment over an arbitrary time
Evolution of a segment over an arbitrary time

Creature Movement

Creature movement is fairly straight forward; essentially all segments are joined with a rotational joint in a long string. The first segment can move forward and the rest of the segments are pulled along like a piece of string.

I added legs which animate in such a way that it looks like the creature is walking rather than being dragged along (I used this as a reference for implementation). With a bit of torque on the segments, it really enhances the animation. I am really happy with the results:

A creature walking around
A creature walking around
Website created by Jacob Morris