This repository contains an AI-based implementation of the classic Flappy Bird game. The AI learns to play the game using the Neuroevolution of Augmenting Topologies (NEAT) algorithm. The goal is to train the AI to navigate through the obstacles (pipes) with minimal collisions and high scores.
- Game Implementation: Developed using the popular Pygame library for 2D graphics and physics.
- AI Training: Utilizes the NEAT algorithm for reinforcement learning.
- Visualization: Displays AI's real-time learning and decision-making process during gameplay.
- Customizability: Easily configurable parameters for training, like population size and fitness functions.
- Python 3.8 or above
pygame
libraryneat-python
library
-
Clone the repository:
git clone https://github.com/Aafimalek/flappy_bird_AI.git cd flappy_bird_AI
-
Install the required dependencies:
pip install -r requirements.txt
-
Run the game:
python flappy_bird.py
The AI uses the NEAT algorithm for evolving neural networks. Here's how it learns to play:
- Inputs to the Neural Network:
- Bird's position
- Distance to the next pipe
- Vertical position of the next pipe
- Outputs:
- Whether to "jump" or "do nothing."
- Fitness Function:
- Rewards the bird for surviving longer and passing more pipes.
The NEAT algorithm evolves the neural network over multiple generations, improving the AI's performance over time.
flappy_bird_AI/
├── images/ # Game assets like sprites and sounds
├── config-feedforward.txt # NEAT configuration file
├── flappy_bird.py # Main script to run the game
├── visualize.py # to visualize the progress of model
├── README.md # Project documentation
├── requirements.txt # List of dependencies
├── winner_genome.joblib # saved traied model
You can modify the config-feedforward.txt
file to tune the NEAT algorithm:
- Population size: Number of AI agents per generation.
- Fitness function: Adjust how the AI's performance is evaluated.
- Mutation rate: Control the variation in neural networks between generations.
- Add a leaderboard to compare AI scores.
- Train the AI using advanced reinforcement learning techniques like Deep Q-Learning.
Contributions are welcome! If you have suggestions or improvements:
- Fork the repository.
- Create a new branch for your changes.
- Submit a pull request.
For any questions or feedback, feel free to reach out:
- Author: Aafi Malek
- Email: [email protected]