Skip to content

My take on making a genetic algorithm that plays Flappy Bird using Unity3D.

License

Notifications You must be signed in to change notification settings

Jamesscn/genetic-flappy-bird

Repository files navigation

Genetic Flappy Bird

My take on making a genetic algorithm that plays Flappy Bird using Unity3D.

Link to the demonstration.

This project was inspired by Machine-Learning-Flappy-Bird by ssusnic, who has an article on how the project works.

logo

Implementation of the genetic algorithm

A set number of birds are placed in the game with Neural Networks that contain two input neurons, six processing neurons and one output neuron. The first input neuron indicates the vertical distance between the bird and the center of the tubes opening, and the second one represents the horizontal distance to the nearest tube. The output neuron makes the bird jump if its value is greater than 0.5.

The six processing neurons and the output neuron are initialized with random weights which are modified only in the case of a mutation. The fittest birds are bred with eachother depending on the survival rate and the rest are killed off. Breeding takes random neurons from both parents and places them in the children's neural networks. Once the children are born, a select amount of them undergo mutation based on the mutation rate.

Fitness is calculated as the total amount of time that the bird stays in the air.