It is a software robotics engineering quarter project for the machine learning subject. It consists of a simple genetic algorithm in which randomly generated creatures evolve to become faster while moving.
Play with the project here : https://jorgerando.github.io/Random-Creature-Evolution/
The creatures will be formed by 3 types of pieces: solids, thrusters and unions
Solids can be rectangles, circles, and triangles. This type of appendage does not produce force and its dimensions will be random. The thrusters rot force in a specific direction with a magnitude and frequency that will depend on their mass. Very heavy propellers will produce a lot of force but with low frequency and light propellers will produce little force but with great frequency. Finally, there are the unions that are in charge of joining appendages and can be elastic or solid.
The first generation of a genetic algorithm must always be random, therefore we have designed an algorithm for the random creation of creatures. This algorithm has 4 parts: creation of solids and propellers, selection of the individual's body, positioning of the appendages and creation of the joints.
Creation of solids: in this first stage, between 2 to 3 solids and propellants will be generated randomly
Selection of the Body: it will be iterated through all the solids looking for the one with the greatest area. The one with the most area will be the individual's body
Positioning of the appendages: the body of the individual will be positioned in the center and the other appendages will be positioned around randomly avoiding collisions
Creation of the unions: all the appendages will be joined to the body with unions of dimension and random type
This gif shows some individuals generated with this algorithm
A fundamental part of a genetic algorithm is the fitness function that tells us how fit an individual is. In this case we will let the individuals of a generation move freely around the world for 20 seconds and those who go further will be the fittest and will have the most probability of reproducing and passing on their genes.
In order to generate a new generation from the previous ones, we have created a reproduction algorithm for n individuals. This algorithm consists of 3 steps: merge bodies, merge appendages and merge joins.
Mixture of bodies: if the bodies of the parents are of different types, a random one is selected; Otherwise, the average of the bodies of the parents is made.
Merge appendages: it is iterated through all the appendages of the parents in hourly order, if the appendages are different, a random one is chosen, if they are the same, the average is done.
Merge joins : try to join as parent appendage if not possible search for a new coherent join point
This gif shows some examples of reproduction
So that the generations do not stagnate in a genetic algorithm, there must be a probability that when reproducing a mutation is produced. In this case, the mutation will occur with a 5% probability and will consist of adding an extra random appendage or removing an existing one.
As can be seen in the gif, as the generations pass, individuals are able to move faster and faster (the gif is in fast motion).
Evolution : https://en.wikipedia.org/wiki/Natural_selection
Nature of code Book : https://natureofcode.com/book/chapter-9-the-evolution-of-code
Genetic Algorims : https://en.wikipedia.org/wiki/Genetic_algorithm
matterJs : https://brm.io/matter-js/
Jorge Rando Hernández 〽️ @jorgerando
Javi 〽️ @ javi-dbgr