I always found the concept of simulating evolution with computers fascinating. I found a couple of projects on YouTube and I finally decided to try my own version of it.
In particular, I wanted to simulate creatures with some kind of genome, which encodes the weights and connections of a small neural net brain.
As a starting point, I drew inspiration from this video and used some of its concepts and implementations. I wrote everything in Python, although it’s not the best performance-wise.
The source code is available here.
The world our creatures will be living in is organized in a grid of user-specified dimensions. I usually go 100 by 100.
I then store in separate grids of the same shape a few pieces of information, namely:
Food map with 50% coverage and no borders.
Food map with 25% coverage and no borders.
Food map with 50% coverage and “box” borders.
Creatures can eat food from a tile, which then becomes ground. They can move to any cell that is not an obstacle or that is not already occupied by another creature.
Food is distributed randomly according to a given coverage percentage.
The map wraps both vertically and horizontally so that creatures that leave one side can reenter from the opposite one.
The creatures that will live in this simulation are independent agents that are governed by a small neural network brain.
At each step of the simulation, the food, position, and obstacle values of the neighboring cells are forwarded in the net. which then outputs probabilities for each possible action. The action that the creature will take is sampled from said probabilities.
Each creature has: