This is part of an ongoing series in which we experiment with different methods of AI. We’ll look at the state of the art and the out of fashion; the practical and the (seemingly) impractical; to find what works and what doesn’t. In this part, we will finish the Genetic Algorithm that we started here. You can read the first article in the series for more information on what we are trying to accomplish.
So far we’ve implemented our UFOs, provided them with neural networks, and started our genetic algorithm. Which means we’re almost finished the series. There are only a few more things we need to accomplish:
A UFO is fitter than another UFO if stays ‘alive’ longer.
You can add the component anywhere after creating the object but before adding it to the object collection. Now whenever a UFO is added to the game this counter will start incrementing. We can then compare two agents fitness using this time alive value.
Solution: a vector of weights that represent a neural network. The weights will move the UFO in a specific manner based on its input. Better solutions will move the UFO away from other UFOs and the screen sides.
Say we have 5 individuals in the pool and we’ve sorted them in descending order:
Now we loop through each individual in the pool:
In this example, there are two split points (between -0.2 and 0.6, and between -0.1 and 0.4). This image was borrowed from the book AI Techniques for Game Programming. A book I cannot recommend enough as it was the inspiration for this series.