Flappy Bird AI
How do they learn?

How to play

  • Space ↑ or tapflap
  • Aswitch to AI mode
  • Mmute
Your best
0
AI best
–

The AI starts out terrible. Hundreds of birds with random brains crash within seconds. Give evolution a minute and see who wins.

How it learns

Survival of the flappiest

Nobody programs these birds to dodge pipes. They start with random brains and evolve. Scroll through one full cycle of the genetic algorithm that runs above.

01Senses

  1. 01

    What a bird sees

    Every frame, each bird measures five things: its height, how fast it's rising or falling, the distance to the next pipe, and where that pipe's gap starts and ends.

    inputs = [y, velocity, pipeDist, gapTop, gapBottom]
  2. 02

    A tiny brain decides

    Those five numbers flow through a small neural network: 5 inputs, 8 hidden neurons, 2 outputs. If FLAP scores higher than WAIT, the bird flaps. That's the whole brain.

    if (flap > wait) jump()
  3. 03

    The brain is just numbers

    Every connection has a strength (a weight) and every neuron a bias. Line all 66 numbers up and you have the bird's DNA. Different numbers, different behaviour.

    genes.length === 66 // 40 + 8 + 16 + 2
  4. 04

    Generation 1: pure chaos

    We hatch 500 birds with completely random DNA. None of them know what a pipe is. Each bird is coloured by its DNA, so relatives look alike.

    new Bird(randomGenes())
  5. 05

    Let them all fly

    The whole flock plays at once. Some never flap and drop like stones, others flap into the ceiling. Most crash within seconds; a lucky few slip through a pipe or two.

    framesAlive++
  6. 06

    Score every bird

    When the last bird falls, each one gets a fitness score: frames survived, plus a bonus that doubles with every pipe cleared. One more pipe beats any amount of hovering.

    fitness = frames + 1000 * 2 ** pipes
  7. 07

    Spin for parents

    Parents are picked on a roulette wheel where fitter birds own bigger slices: likely to win, never guaranteed. The champion also skips the wheel and is copied into the next generation untouched. That's elitism.

    parent = spinWheel(fitness)
  8. 08

    Copy, then mutate

    Each child starts as an exact copy of its parent's DNA. Then every gene has a 10% chance of being nudged by up to ±0.5. Most nudges hurt, a few help, and selection keeps the helpful ones.

    if (rand() < 0.1) gene += rand(-0.5, 0.5)
  9. 09

    Bonus: crossover

    Nature also mixes two parents. Switch on crossover in the lab and each child takes every gene from one parent or the other on a coin flip. In our tests it helps tiny flocks but slows big ones. Try it!

    child[i] = coin() ? mom[i] : dad[i]
  10. 10

    Repeat until it masters the game

    Fly, score, select, mutate, repeat. Progress stalls for a while, then one lucky mutation cracks it and its descendants take over the flock. In this recorded run, generation 19 sailed past 150 pipes.

    generation++

Your turn

Run evolution yourself

Every experiment below reconfigures the game at the top of the page and starts a fresh flock. Watch the score chart and the colours of the birds.

Good to know

Is this real AI?

Yes. Each bird is driven by a genuine neural network. What's unusual is how it learns: there's no training data and no backpropagation, only random variation plus selection. This family of methods is called neuroevolution.

Why do the birds change colour over time?

Each bird's colour is computed from its DNA, so relatives look alike. Early generations are a rainbow of unrelated random brains. As one family out-breeds the rest, the flock converges on its colour.

Why does progress come in sudden jumps?

For a while every bird fails at the same hurdle and fitness barely moves. Then one mutation cracks it, that bird scores exponentially higher, wins most roulette spins, and its descendants flood the next generation.

Why does the best bird sometimes do worse next time?

Pipe heights are random every run. A champion that got lucky once may crash on a harder layout. That's why evolution works with a whole population rather than a single star.