FlappyBird game with Q-Learning AI
Project description
๐ FlappyAlpha: Reinforcement Learning vs Human
๐ฎ Overview
FlappyAlpha is a reinforcement learning (RL) project inspired by AlphaGo, where an RL agent learns to play a custom Flappy Bird game environment with realistic physics (gravity, collision, etc.). The agent (FlappyAlpha) is trained using Q-Learning to maximize its score by passing obstacles and avoiding crashes. The project also features human vs. agent battles to showcase the agent's learning progress.
๐ฎ Features
- Custom Flappy Bird environment built with Pygame
- Q-Learning agent with reward/punishment system
- RL training for "Beginner" and "Hard" agents
- Human vs Agent battle playground with score visualization
- Performance interpretation and result plots
๐ฎ Tech Stack
- Game & UI: Python, Pygame
- Reinforcement Learning: Q-Learning (NumPy)
- Data Analysis & Result Visualization: NumPy, Matplotlib
๐ฎ Simple Demo
๐ฎ Project Structure
rl_flappyBird/
โ
โโโ README.md
โโโ requirements.txt
โโโ .gitignore
โ
โโโ src/ # Core game environment
โ โโโ flappy_bird.py
โ
โโโ train/ # Training scripts
โ โโโ train_qLearningBEGINNER.py
โ โโโ train_qLearningHARD.py
โ
โโโ models/ # Trained models
โ โโโ best_q_table_beginner.npy
โ โโโ best_q_table_hard.npy
โ
โโโ results/ # Result plots and analysis
โ โโโ beginner_mode_scores.png
โ โโโ hard_mode_scores.png
โ โโโ user_vs_agent_scores.png
โ โโโ user_vs_agent_scoresHARD.png
โ
โโโ playground/ # Human vs agent
โ โโโ playground.py
โ โโโ playgroundHARD.py
โ
โโโ assets/ # Assets
๐ฎ How to Use
U can use virtual environment (venv), but since the dependencies are just common and less, so depend on yourself.
1. Install Dependencies
pip install -r requirements.txt
2. Train the RL Agent
Note: Pre-trained Q-tables are provided in the
models/folder. You can retrain if you wish.
- Train Beginner mode agent:
python train/train_qLearningBEGINNER.py - Train Hard mode agent:
python train/train_qLearningHARD.py
3. Human vs. Agent Battle
- Play against Beginner agent:
python playground/playground.py - Play against Hard agent:
python playground/playgroundHARD.py
4. View Results
- Training and battle results are auto saved as
.pngplots in theresults/folder.
๐ฎ Highlights & Insights
- The RL agent receives positive rewards for passing pipes/blocks and negative penalties for crashing.
- As training episodes increase, the agent's performance improves dramatically:
- After 2500 episodes
(beginner mode): Best score 17. - After 3000 episodes
(hard mode): Best score 75 (441% increase). - After 4000 episodes: Best score 3693 (near-perfect play).
U can modify the training parameter, ex. EPISODES = 4000 if u want.
- After 2500 episodes
- Human players can easily beat the Beginner agent
(2500 episodes), but the Hard agent(3000 episodes)is a tough opponent, often outperforming humans in average score, and I'm sure for> 4000 episodestraining, human can't beat RL agent as it plays near perfect.
๐ฎ Acknowledgements
Inspired by AlphaGo and the power of reinforcement learning.
๐ Feel free to fork, do experiment, and challenge FlappyAlpha.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flappy_rl-0.2.0.tar.gz.
File metadata
- Download URL: flappy_rl-0.2.0.tar.gz
- Upload date:
- Size: 16.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
784c01e0ee8874e5ba0d3372879fdb5da764711bf1a84727f51a0c8b6f72dc31
|
|
| MD5 |
7e18ff21cb57e5dd19f44352f20b3146
|
|
| BLAKE2b-256 |
71c96b18f2230b0a2fc3146c688e31790e4f2057775a5a8a15ddd7c03b8bb3d7
|
File details
Details for the file flappy_rl-0.2.0-py3-none-any.whl.
File metadata
- Download URL: flappy_rl-0.2.0-py3-none-any.whl
- Upload date:
- Size: 16.0 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15dddb2209443308b3f5048831494da1e8f94652bc7328ca0f096818ccce16bc
|
|
| MD5 |
fb499c99d40cce63d0108e514fd7020d
|
|
| BLAKE2b-256 |
eeaba9bd2307ba2dc91e055296e866f383b4a1b8eefb82daad7519a3f872ea55
|