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
- Host: GitHub
- URL: https://github.com/kokodoko/flappy-evolution
- Owner: KokoDoko
- Created: 2025-04-12T10:27:14.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-04-12T10:47:14.000Z (9 months ago)
- Last Synced: 2025-04-12T11:37:11.626Z (9 months ago)
- Topics: game-development, javascript, machine-learning, ml5js, neuroevolution
- Language: JavaScript
- Homepage: https://kokodoko.github.io/flappy-evolution/
- Size: 2.47 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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
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