An open API service indexing awesome lists of open source software.

https://github.com/kokodoko/flappy-evolution

Evolving Flappy Birds until they learn how to fly
https://github.com/kokodoko/flappy-evolution

game-development javascript machine-learning ml5js neuroevolution

Last synced: 4 months ago
JSON representation

Evolving Flappy Birds until they learn how to fly

Awesome Lists containing this project

README

          

# Flappy Evolution

[LIVE DEMO](https://kokodoko.github.io/flappy-evolution/)

### Flappy bird learns to fly by neuro-evolution

- Create a generation of 100 birds with a random brain
- The brain decides when to flap, based on 5 sensory inputs of the bird
- After all birds have sadly passed away, pairs of birds that performed best are selected for the next generation
- Those pairs make children, based on their parents brains, and mutate slightly
- After 5 ~ 15 generations with a population of ~30, the birds can avoid pipes effectively
- This demo loads this pre-trained brain into 3 birds




## ML5 Neural network

### Inputs

- The y-position of the bird
- The y-velocity of the bird
- The y-position of the next top pipe’s opening
- The y-position of the next bottom pipe’s opening
- The x-distance to the next pipe

Diagram of neural network inputs
Five sensory inputs - (The Nature of Code by Daniel Shiffman)




### Outputs

- Flap or don't flap


Resulting Neural Network (The Nature of Code by Daniel Shiffman)




### Code

```js
let options = {
inputs: 5,
outputs: ["flap", "no flap"],
task: "classification",
neuroEvolution: true
};
let brain = ml5.neuralNetwork(options);

let inputs = [...sensory data here...]
let prediction = brain.classify(inputs, (result) => {
console.log(`I think I should %{result[0].label}`)
})

```



## Links

- https://natureofcode.com/neuroevolution/
- https://docs.ml5js.org/#/reference/neural-network