/flappy-learn

Evolve birds to play Flappy Bird

Primary LanguageJavaScript

flappy-learn

Evolve birds to play Flappy Bird. Live demo

Description

There is only one button: jump. The objective is to survive as long as possible without hitting the spikes or falling off-screen. The gap between spikes gets increasingly smaller, until a bird can no longer pass through it (at around score 80).

Demo

Start a run by accessing stefann.eu/flappy-learn and watch your birds learn how to fly. If you wish to observe a high-scoring bird, load the brain from demo/champion.json.

How?

Each bird's brain is a neural network with a few hidden layers and one output. It takes as input the x and y distances from the next gap center and the output dictates whether it should jump. This brain is simulated multiple times per second.

To optimize the network, a genetic algorithm is used. The fitness function is the bird's age – the time it survived.

The initial population consists of many birds with random weights. Each subsequent generation is built upon the previous like so:

  • the fittest genomes are selected
  • the best one, together with some lucky ones are mutated by applying random variation to their weights
  • offsprings are created by picking two winning genomes and randomly swapping their weights

Dependencies