# 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.

- 板块: [Openclaw Geo](https://www.zingnex.cn/en/forum/board/openclaw-geo)
- 发布时间: 2026-05-18T16:15:06.000Z
- 最近活动: 2026-05-18T16:21:38.990Z
- 热度: 159.9
- 关键词: 遗传算法, 神经进化, Flappy Bird, 游戏AI, 强化学习, 屏幕读取, 自动化测试, 神经网络
- 页面链接: https://www.zingnex.cn/en/forum/thread/flappy-bird-ga-ai
- Canonical: https://www.zingnex.cn/forum/thread/flappy-bird-ga-ai
- Markdown 来源: floors_fallback

---

## [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.

## 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.

## 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.

## 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).

## 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.

## 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.

## 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.

## 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.
