training.py
showcase
showcase2.mp4
- Ensure you have Python and pygame installed on your system (Python 3.6 or higher).
- Clone this repository to your local machine using the following command:
- Navigate to the project directory:
cd Flappy-Bird-AI
- Install the required dependencies. It is recommended to set up a virtual environment before installing the dependencies:
pip install -r requirements.txt
-
To play the game manually, run the
main.py
script:python main.py
-
To watch the AI play the game, run the
AI_mode.py
script:python AI_mode.py
Here's how to run the training:
-
Run the
training.py
script:python training.py
-
The training process will start, and you will see each generation's progress being printed to the console. The script will keep training until a bird successfully reaches a score of 100 or more.
-
Once a successful bird is found, the winning neural network's genome will be saved as
winner_genome.pkl
. This file contains the genetic information of the neural network that achieved the highest score during the training process. -
You can then use this winner_genome.pkl file to observe the AI playing the game automatically by running the
AI_mode.py
script.
Feel free to modify the parameters and settings in config-feedforward.txt
to experiment with the training process. You can adjust parameters like population size, mutation rate, and others to see how they impact the AI's learning.
NEAT (NeuroEvolution of Augmenting Topologies) is a method of evolving artificial neural networks. In this project, the NEAT algorithm is utilized to train an AI to play the Flappy Bird game.
- Initialization: The algorithm starts with a population of random neural networks (genomes) that control the birds.
- Evaluation: Each bird's performance is scored using a fitness function, based on how far it travels, how many pipes it passes, etc.
- Selection and Reproduction: The best-performing genomes are selected to create the next generation. They undergo mutations and crossover to improve performance.
- Iteration: This process repeats for many generations until a bird reaches a score of 100 or more.
- Saving the Best Genome: The best-performing genome is saved as winner_genome.pkl and used by AI_mode.py to demonstrate the AI playing the game automatically.