How shuhuagao/gpflappybird works
This is a Pygame Flappy Bird game that evolves a Cartesian Genetic Programming (CGP) policy to control AI birds. The main workflow initializes a population, runs game generations, scores birds by survival, and evolves the population; a bird’s policy evaluates the front pipe’s vertical offset, horizontal distance, and gap to decide whether to flap. A human can join and control a bird during play. After evolution, the entry point can extract, simplify, and optionally visualize evolved formulas. The game/evolution loop is supported by sampled source; some update and evolution details are only partially excerpted.
Main entry points: game.py Game controller · main_entry.py Program entry · sprites.py Bird and sprites · postprocessing.py Formula simplification
Components 17
Game play
- Program entry
main_entry.py - Game controller
game.py - Pipes and gaps
game.py - Bird and sprites
sprites.py - Game controls
game.py - Game display
game.py - Sound effects
sprites.py
CGP evolution
- Population setup
cgp.py - CGP policy
cgp.py - Survival scoring
sprites.py - Mutation and selection
cgp.py
Solution analysis
- Active graph extraction
postprocessing.py - Formula simplification
postprocessing.py - Graph visualization
postprocessing.py - Formula output
main_entry.py - Graph output
main_entry.py
Other components
- Human player
Connections 19
- Human player → Game controls: presses controls
- Program entry → Game controller: creates and runs
- Program entry → Population setup: initializes population
- Game controller → Pipes and gaps: spawns pipes
- Game controller → Bird and sprites: creates birds
- Game controls → Game controller: controls play
- Game controller → Game display: draws frame
- Bird and sprites → Sound effects: plays effects
- Game controller → CGP policy: requests flap decision
- CGP policy → Bird and sprites: returns flap score
- Bird and sprites → Survival scoring: sets fitness on death
- Game controller → Mutation and selection: evolves generation
- Mutation and selection → Population setup: returns next generation
- Program entry → Active graph extraction: extracts evolved graphs
- Active graph extraction → Formula simplification: provides active graph
- Program entry → Formula simplification: simplifies formula
- Formula simplification → Formula output: writes formula
- Program entry → Graph visualization: requests visualization
- Graph visualization → Graph output: writes graph files