A 2D simulation in which cars learn to maneuver through a course by themselves, using a neural network and evolutionary algorithms. The entire source code of this project is open-source and can be found on my Github repository.
Description
At the start of each generation 20 cars are spawned. Each car has its own neural network, which makes up the “intelligence” of the car. The cars also have 5 front facing sensors, which measure the distance to obstacles and serve as the input of the neural network. If a car hits an obstacle, it dies.
Once all cars have died, a new generation is formed using an evolutionary algorithm. The “genes” of the two cars with the best fitness are crossed and 20 new “children” are born. Additionally these children get slightly mutated. Finally these newborn children try to maneuver through the course.
The fitness of a car is calculated by its progress throughout the course. A car’s “genes” are the weights of its neural network. The neural networks are simple feed-forward networks and consist of 5 input nodes, 2 output nodes and 2 hidden layers with 4 and 3 nodes.
Visualization
The crosses in front of each car symbolize its sensors’ current readings. The camera always follows the car with the best current fitness. The best car is drawn in green, the second best in beige.
In the top left corner the current outputs and fitness of the targeted car are displayed. In the top right corner the neural network of the target is visualized. The width of a connection between nodes symbolizes the magnitude of its weight, the color its sign (green: positive, red: negative).
In the bottom left corner the current generation count is displayed.
Time of Development
Late 2016