A car learns to drive in a small 2D environment using the NEAT-Algorithm with Pygame grafik


A car has 5 sensors (“eyes”) to detect and learn the distance to the road boundary. Using these sensors and Python’s Neat library, cars are trained to steer and stay on the road. Neat is a genetic algorithm that starts with a simple neural network and increases its complexity over the next few generations. In each generation there are many cars, each car having its own neural network. Once a generation is over (all cars are “dead”), Neat constructs the neural networks of the new generation based on the neural network of the best car of the previous generation. With this technique, the algorithm learns how to drive and gets better and better over the generations.


Run to see what the training process looks like. Once training is complete, the program saves the trained version of the best car to a file. loads a pre-trained model and lets the car drive based on the loaded model.


You need to have python, neat and pygame installed in order to run the program. Installation of pygame: Installation of Neat:


View Github