Zing Forum

Reading

Flappy Bird GA: AI Game Training Framework Combining Genetic Algorithms and Neural Networks, plus Screen-reading Robot

This project combines the classic Flappy Bird game with genetic algorithms, enabling AI to autonomously learn game strategies through evolving neural networks. It also provides a Python screen-reading robot to apply the trained model to real game environments, demonstrating the application potential of neuroevolution in game AI and automated testing.

遗传算法神经进化Flappy Bird游戏AI强化学习屏幕读取自动化测试神经网络
Published 2026-05-19 00:15Recent activity 2026-05-19 00:21Estimated read 6 min
Flappy Bird GA: AI Game Training Framework Combining Genetic Algorithms and Neural Networks, plus Screen-reading Robot
1

Section 01

[Main Floor/Introduction] Flappy Bird GA: AI Game Training Framework Combining Genetic Algorithms and Neural Networks, plus Screen Robot

This project combines the classic Flappy Bird game with genetic algorithms (GA), enabling AI to autonomously learn game strategies through evolving neural networks. It also provides a Python screen-reading robot to apply the trained model to real game environments, demonstrating the application potential of neuroevolution in game AI and automated testing.

2

Section 02

Project Background and Unique Application Scenarios

Flappy Bird GA is an open-source project whose core goal is to demonstrate the principles of neuroevolution. Its uniqueness lies in two scenarios: 1. A built-in GA trainer in the browser allows observing the AI population learning from scratch; 2. The Python screen-reading robot applies the trained model to real game environments, realizing a complete "training-deployment" process and providing references for game AI development and automated testing.

3

Section 03

Concise and Efficient Neural Network Architecture Design

The project uses a neural network with five inputs and one output: the input layer contains 5 key game state variables (bird's Y-coordinate, vertical velocity, horizontal distance to the next pipe, vertical positions of the pipe's upper and lower edges); the hidden layer has 8 neurons activated by ReLU; the output layer has 1 neuron activated by Sigmoid—when the output is >0.5, the bird flaps its wings. Instead of using raw pixels, high-level semantic features are extracted to reduce complexity.

4

Section 04

Genetic Algorithm Process Simulating Natural Selection

The algorithm starts with 60 individuals (each being a set of neural network weights). Each individual in a generation plays the game to obtain fitness (survival time + pipe-passing reward + off-center penalty). Selection uses tournament selection (randomly pick 5 and choose the best); genetic operations include uniform crossover and Gaussian mutation with a 12% probability; an elitism strategy is applied (the top 4 excellent individuals of each generation directly enter the next generation).

5

Section 05

Training Process of AI Learning to Fly from Scratch

The training interface is intuitive: 60 birds play the game simultaneously, and the population's performance improves as generations progress. It supports 50x speed acceleration and real-time plotting of fitness curves. When satisfied, you can save the optimal individual's weights as a JSON file. Typically, after dozens of generations of training, a stable flying AI can be generated, demonstrating the strategy search capability of evolutionary computation.

6

Section 06

Python Screen Robot: From Simulation to Reality

The Python component uses mss for efficient screenshotting and OpenCV image processing to identify the positions of the bird and pipes, calculate the 5 input features, and input them into the trained network to automatically control the game. It supports keyboard/mouse control and a calibration mode to adjust color detection parameters, applicable to the built-in HTML version and other Flappy Bird clone games.

7

Section 07

Multi-scenario Application Value of the Project

Application scenarios include: 1. Game development: automatically generate test cases, explore the game state space to find bugs; 2. Reinforcement learning research: a lightweight experimental platform to quickly verify algorithms; 3. Education: intuitively teach neural networks and genetic algorithms, with clear and easy-to-use code structure.

8

Section 08

Project Summary and Expansion Directions

The project combines classic games with machine learning technologies, demonstrating the principles and practical value of neuroevolution. Expansion directions include: improving the neural network architecture (e.g., convolutional layers), trying genetic algorithm variants (shared fitness, co-evolution), expanding to other games, combining with modern deep learning technologies (e.g., PPO), etc.