An educational project demonstrating how a Neural Network combined with a Genetic Algorithm can learn to play Flappy Bird from scratch.
Built with pure JavaScript, HTML, and CSS. No external libraries or frameworks.
Each bird has a tiny brain (Neural Network) consisting of:
- Input Layer (4 nodes):
- Y Position
- Velocity
- Distance to next pipe
- Height of the pipe gap
- Hidden Layer (6 nodes): Processes the inputs using Tanh activation.
- Output Layer (1 node): Decides whether to jump (> 0.5) or not.
- Population: We start with 50 birds with random brains (random weights).
- Selection: Birds that survive longer get a higher "fitness" score.
- Reproduction: The best performing birds are selected to be parents.
- Mutation: The offspring inherit the parents' brains but with slight random "mutations" to their weights. This introduces variation.
- Loop: This process repeats endlessly, creating smarter birds over time.
- Visualized Neural Network: See the active brain of the best bird in real-time.
- Speed Control: Speed up the simulation (up to 1000x) to train faster.
- Headless Mode: Disable rendering to train even faster.
- Save/Load: The best brain is automatically saved to local storage (feature in progress).
-
Clone the repository
git clone https://github.com/yourusername/neuroevolution-bird.git cd neuroevolution-bird -
Run locally Since this is a static site, you can open
index.htmldirectly in your browser, or serve it with a local server for better module support:# Using Python python3 -m http.server # Using Node.js (npx) npx serve .
-
Open in Browser Go to
http://localhost:8000(or whatever port your server uses).
This project is open source and available under the MIT License.