Flappy AI

Loading sprites…
How to play

Guide the bird through each gap

Press Space or ↑, or tap the game, to flap upward. When you do nothing, gravity pulls the bird down. You score one point for every pipe you clear.

Read the planned path

The dotted line shows the route currently proposed by A*. The yellow point is where that route clears the next pipe. You do not have to follow it: when you choose another action, the AI draws a new path from the position you actually reach.

Saves can catch a missed flap

You begin with three saves, shown in the upper-left corner. If the next glide would cause a collision and a flap can prevent it, the game flaps automatically and spends one save. Input is briefly paused so your reaction does not create a second flap.

You regain one save every 10 points, up to a maximum of three.

Start again immediately

After a crash, press either flap key or tap the game to begin a new run.

FROM GAME TO GRAPH

How the AI plays Flappy Bird

1

Planning requires a model of the game

The aim of Flappy Bird is to guide the bird through gaps in moving pipes without touching a pipe, the ceiling, or the floor. To choose an action, the AI must predict what each choice will do. We therefore describe the game with precise rules. Time advances in fixed steps called ticks. On every tick, the bird either flaps or glides; gravity changes its vertical speed, the bird moves, and the pipes move left.

2

One snapshot contains everything needed

A complete snapshot of the game is called a state. It records the bird's height and vertical velocity, together with the positions and gap heights of the three pipes. It also records the random generator used to create future pipes, so those pipes can be predicted and reproduced exactly. No earlier history is needed.

3

The possible futures form a graph

From any state, the AI can examine two possible futures: the state reached after a flap and the state reached after a glide. Each of those states leads to two more possibilities, and so on. This branching collection of futures is a graph: states are its nodes and actions are the directed edges between them. A future that hits a pipe, the ceiling, or the floor is a dead end and is not explored.

4

A* searches the most promising futures first

A path through the graph is a sequence of flap and glide actions. The goal is a collision-free path that carries the bird beyond the second upcoming pipe. A* keeps several unfinished paths and expands the one with the smallest value of g + h. g counts the flaps already used. h estimates the horizontal and vertical distance still needed to place the bird safely inside the second pipe's gap. This focuses the search on useful futures while favoring plans that flap less often.

5

The short plan moves forward with the game

The AI deliberately plans only as far as the next two pipes. After it clears one, it searches again from the new state, always keeping two upcoming pipes in view. In player mode, the dotted line shows the current A* path. If the player chooses a different action, that path is no longer current, so the AI calculates a new one from the state the player actually reached.