Docs


Flappy Bird

A bird learns to flap through a stream of pipes. The genetic algorithm evolves a tiny neural network from crashing into the first pipe to long clean runs.

Last updated October 25, 2026

Go to the live page Open the Flappy Bird demo

The Flappy Bird demo is the first tab of the Live Agent demo. A bird hangs at a fixed spot on the left while pipes scroll toward it, and gravity pulls it down every step. The only thing it can do is flap. The genetic algorithm evolves a small neural network that decides when to flap, and over a few generations the bird goes from hitting the first pipe to threading gap after gap.

It lives alongside the other live-agent games (Snake, the Self-Driving Car, Dino Runner, Breakout, Pong, Gem Collector and Frog Crossing) under the same Live Agent demo. Use the tabs at the top of the page to switch between them.

The Problem

Each pipe has a gap, and the gap sits at a random height. A flap gives the bird a fixed upward kick, and gravity then drags it back down, so the bird has to time its flaps to stay level with the next gap. Touching the floor, the ceiling or a pipe ends the run.

The network reads five inputs: the bird's height, its vertical speed, how far away the next pipe is, and where that pipe's gap starts and ends. One hidden layer of six neurons feeds a single output. If the output is above a threshold the bird flaps this step; otherwise it lets gravity work.

Fitness rewards every step the bird stays alive, adds a bonus for each pipe it clears, and adds a small extra for flying close to the middle of the next gap. A crash costs a penalty. That middle-of-the-gap reward matters early on: it tells the population which networks are at least heading the right way before any of them clears a pipe.

How a Run Looks

Click Start. The current best network plays a run live, and a panel in the corner shows its flap and no-flap scores each step with the chosen one highlighted. Every other bird of the generation flies the same pipes next to it as a faint bird, so you can watch the flock drop out one by one and see how far the best of them gets; Still in play in the Training panel counts the birds that are left. The Show all birds switch next to the Start button turns the flock off when you only want to watch the best bird (it shows at most the best 50, even with a bigger population). The chart on the right tracks the best score for each cycle, and the Training panel shows the most pipes the watched run could reach before its two minutes are up.

Early generations flap wildly or not at all and hit the first pipe. Within a few generations the bird learns to pace its flaps, and the curve flattens once the policy is solid.

Playing It Yourself

Switch the mode toggle from Agent to You, or press M, to take over. Press Space to flap, or tap anywhere on the game on a touch screen. Each press is exactly one flap. When the game ends, tap the game (or press Space, or Play again) to start a new round straight away. Press P to pause or resume and Esc to reset. Switch back to Agent at any time and the evolved network picks up from where the bird is.

Settings Worth Trying

Open Settings to tune the genetic algorithm for the next run. These only affect Agent mode:

  • Population size. More birds per generation means more variety to select from, at the cost of a slower cycle. The default is 40.
  • Generations per cycle. How much evolving happens between each live run you watch, from 1 to 15. The default is 10.
  • Max steps per episode. How long each bird may fly while it is scored during training, so a higher value makes each training cycle slower. The run you watch afterwards can last up to two minutes (about 99 pipes), or longer if you set this higher.
  • Mutation rate. How much the networks are randomly perturbed each generation. A little keeps the search exploring; too much stops it from settling on a good policy.

What the Achievement Rewards

Signed-in users unlock the Flappy ace achievement the first time an evolved bird clears at least five pipes in one of the runs you watch in Agent mode. Your own runs in You mode don't count toward it.

Flappy Bird records and shares like the other demos. See Sharing and recording for how to capture a clip of a good run.

For more on how the demos catalog works, see What the Demos Do.

Thanks for the feedback!