This is a very basic implementation of a genetic algorithm, partly inspired by this Code Bullet video, with a few additions to improve the evolution speed and reliability. It's nothing fancy, but I found it fun to experiment with, so I thought I'd share it.
Each "ant" has a DNA consisting of a list of directions to move each frame, which starts off completely random, but though the process of mutations and "natural selection" evolves into a path to reach the goal.
To improve the evolution speed and reliability, the ants are evolved gradually by giving each generation slightly longer to reach the goal. In addition, the mutations to the DNA are biased towards the end of the path, so more ants have a chance to explore the end of the path before they die.
The simulation consists of 50 ants in each generation, with the current best path shown in red. Pressing X will restart the simulation with the goal in a random position.
[Please log in to post a comment]