Home › Projects

Evolutionary Creatures

Jun – Aug 2024 · Team of two · C++ simulation · by Abhiyan Khanal

A simulation written in C++ where virtual creatures with small neural-network brains reproduce, mutate and compete. Leave it running and new species with different brain wiring appear, get protected for a while so they can improve, and either take over or die out.

Source on GitHub

Features

How the creatures think

Each creature has a small neural network with four inputs, four hidden neurons and two outputs, using tanh activation. Instead of all 24 possible connections being active, each brain starts with only six randomly chosen ones. Mutation changes the connection weights and, sometimes, which connections exist, so brains can grow different shapes over generations.

Evolution and species

A population of 500 creatures lives on a 100 by 100 grid for 400 steps per generation, for 100 generations, with a 15% mutation rate. Creatures are scored by a fitness function, the best are kept as parents and the rest of the next generation is bred from them. When a mutation changes a brain's wiring, the creature is labelled a new species and shielded from selection for a few generations, so a promising design is not wiped out before it has had time to improve.

Two modes

Visualisation

An SDL2 window renders the population every ten generations and replays the best creature at the end, along with its weights, active connections and movement history in the console.

Tech stack

More projects by Abhiyan Khanal