This project was highly inspired by Machine Learning Flappy Bird.
Lunar Lander is a single-player arcade game in the Lunar Lander subgenre. In the game, the player controls a lunar landing module as viewed from the side and attempts to land safely on the Moon.
For this project, I thought it would be a nice idea to combine this classic game with modern technology, and train these rockets to land by themselves.
Inspired by Machine Learning Flappy Bird, I decided to combine the concept of Neuron Networks with Genetic Algorithm.
Each rocket is assigned with a neural network, with an input layer of 9 neurons, a hidden layer of 16 neurons, and an output layer of 4 neurons:
9 input neurons:
- 8 inputs represent the surroundings of the rocket, telling the rocket the distances to the obstacles around it
- 1 input is the closest "landable" platform to the rocket
The outputs of the NN comes in an array of 4 numbers between 0-1. Four of them each represents Thrust
, Rotate Left
, Rotate Right
, and Do Nothing
. If the value is over 0.5, the action is performed by the rocket.
Each rocket has a fitness
function that determines how successful a rocket is upon these criteria:
- Angle difference of landing/crashing platform
- Fuel used in rocket's lifetime
- Landing/crashing speed
- Distance of rocket to the closest landable platform
This is essentially the score of the rocket, used as a measure of how successful a certain rocket is at landing.
I mass spawn 30 rockets each iteration. In a certain time period, the rockets either crash, land or stay in the air.
After each iteration, I calculate the fitness of each and every rocket, and rank them from high to low. I keep the top rockets, and reproduce new rockets by crossing over and mutating their weights and biases out of the top units.
After a few iterations, rockets start to land by themselves, and the average fitness slowly reaches a maximum value.