Flappy bird using NEAT

Machine LearningNEAT
Flappy Bird NEAT Network

Image sources: CNN, O’Reilly

What is NEAT?

NeuroEvolution of Augmenting Topologies (NEAT) evolves both neural network weights and structure. It solves three key problems: crossover without data loss, protecting new innovations through speciation, and maintaining simple topologies without manual complexity penalties.

Each genome contains connection genes with innovation numbers that enable O(n)O(n) gene alignment during crossover. Networks grow via two mutations: adding connections between nodes, or splitting connections to insert new nodes. Species compete within niches defined by a compatibility threshold δt\delta_t, allowing novel structures time to optimize.


Flappy Bird Implementation

Game & Neural Network

Built with pygame (400×600 screen, gravity g=2.0g=2.0, flap strength v=20v=-20). The network receives 4 inputs: bird y-position, distance to pipe, distance to gap center, and velocity (all normalized). Output > 0.0 triggers a flap.

Fitness & Evolution

  • +0.001 per frame, +5 per pipe, +10 at score 20, -4 for collision
  • Runs 200 generations using NEAT-Python
  • Each genome controls one bird; dead birds are removed when they hit pipes, ground, or bounds

NEAT evolves efficient network topologies that master the game through survival-based selection.