Dec 2023 · Jan 2024
Flappy Bird AI with NEAT
Neural networks that evolve their own topology until they can play the game indefinitely.
- Python
- Pygame
- NEAT
- Evolutionary Algorithms
An implementation of NEAT, NeuroEvolution of Augmenting Topologies, that trains an agent to play Flappy Bird without ever being shown how.
Inputs and decision
Each network receives three inputs: the bird’s vertical position, the distance to the top pipe, and the distance to the bottom pipe. A hyperbolic tangent activation decides whether to jump. Three inputs is deliberately minimal: it is enough to solve the game, and it keeps the search space small.
Evolution
Each generation contains 100 birds. The best performers are selected and mutated, and NEAT adjusts network complexity itself, adding neurons, connections and layers where they help rather than starting from a fixed architecture. Over successive generations the population converges on a policy that plays indefinitely.
The game itself is written in Pygame, handling physics, collision detection and rendering, with NEAT governing evolution on top.