This is my first attempt at coding a target finder that uses the principles of genetic inheritance to improve its target finder abilities over many generations. No matter how many times I see this, the results will always surprise me. There is no where I have coded the "boids" to search the "target" directly. Yet over many generations, they manage to still find the target. Scroll down to the end for a detailed explanation.
Sorry, your browser does not support Canvas.Gen # | # of Wins | Steps | Top score | 2nd score | 3rd score |
---|
This world has three components.
- Boids : That's the bird like creature whose job it is to find the "Target"
- Target: The Big yellow circle at the top is the target. The goal of the boid is to get to the target.
- Obtacles: Obtacles prevent a boid from getting through. Boids must figure out a way to get around obstacles.
Each run of the animation is 200 frames. 200 over here is how many individual genes in a DNA. Each boid has one DNA assigned with it. Each gene determines how the boid will move. Every boid always starts from the bottom of the canvas.
At the end of every run, the boids are removed and a new generation is introduced. A new generation is created from the top 20% of the best performing boids. A boids' performance is determined at the end of the run using a fitness score. The fitness is determined by just one factor.... how close the boid got to the target. From the winning boids, a pool of DNA is created. The better a boid has performed, the more its DNA will be in the pool.
The DNAs are then mated in exactly the same way as the real world. 50% from one parent, 50% from the other. However, every once in a while a mutation is introduced. Mutations, like in the real world, are either beneficial or harmful. The rules of this world ensure that harmful mutations are removed from the gene pool.
Every boid that makes it to the target is given the highest fitness score possible. However in some cases multiple boids make it to the target. In this case, the boid that reached the target in the lowest number of genes has a better chance of making it to the next generation.