This project showcases an AI system that automates the Flappy Bird game using the NeuroEvolution of Augmented Topologies (NEAT) algorithm combined with a genetic algorithm. The goal is to evolve a neural network capable of playing the game autonomously, improving its performance over generations.
-
NeuroEvolution of Augmented Topologies (NEAT): NEAT is a method for evolving neural networks using genetic algorithms. It starts with simple networks and gradually evolves them, adding nodes and connections as needed to improve performance. This allows the AI to optimize both the weights and the structure of the neural network.
-
Genetic Algorithm: A genetic algorithm is used to evolve the population of neural networks. The fittest networks (those that perform best in the game) are selected to reproduce, passing on their characteristics to the next generation.
-
Language: Python
-
Libraries:
- NEAT-Python: An implementation of the NEAT algorithm in Python.
- Pygame: Used to simulate the Flappy Bird game environment.
- Numpy: For numerical operations and handling neural network data.
-
Functionality:
- The neural network starts with a simple topology and evolves as it learns to play Flappy Bird.
- The fitness function is based on the score (i.e., how far the bird flies without hitting obstacles).
- Over several generations, the algorithm produces increasingly sophisticated networks capable of better performance in the game.
To run the project locally, follow these steps:
- Clone the repository:
git clone https://github.com/yourusername/flappy-bird-neat.git
- Navigate to the project directory:
cd flappy-bird-neat - Install the required packages:
pip install -r requirements.txt
- Start the simulation:
python flappy_bird_neat.py
- Initialization: The simulation starts with a population of randomly generated neural networks.
- Evaluation: Each network controls a bird in the Flappy Bird game. The network's fitness is determined by how far the bird travels without crashing.
- Selection and Reproduction: The top-performing networks are selected to create offspring through crossover and mutation, producing the next generation.
- Evolution: Over many generations, the neural networks evolve, becoming better at playing the game.
As the algorithm progresses, you should observe the AI-controlled birds getting better at avoiding obstacles and achieving higher scores. The NEAT algorithm allows for complex strategies to emerge as the networks evolve.
Contributions are welcome! If you have any ideas for improving the AI or extending the project, feel free to submit a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.
- NEAT-Python for the NEAT implementation in Python.
- Pygame for providing the game simulation environment.
- The community for their resources and tutorials on AI and game automation.