This project implements an AI-powered Flappy Bird game using a Perceptron-based Neural Network. The AI learns to play Flappy Bird through natural selection and a fitness-based evaluation system.
- Perceptron Neural Network: The AI uses a simple neural network with input nodes representing the bird's vision and an output determining its jump decision.
- Natural Selection: The AI evolves over multiple generations using a genetic algorithm to improve performance.
- Fitness Score: The survival time of each bird determines its fitness, influencing the next generation's selection.
- Species Classification: Birds are grouped into species based on weight differences in their neural networks.
- Dynamic Gameplay: Pipes spawn dynamically, and the AI continuously learns from previous attempts.
flappybird/
│── main.py # Main game loop
│── img/ # visualization images for pipes and birds.
│── src/
│── config.py # Game configurations (window size, pipes, etc.)
│── components.py # Game elements (ground, pipes)
│── player.py # Player class representing the AI bird
│── population.py # Handles natural selection and species classification
│── species.py # Manages species grouping
│── brain.py # Neural network for decision-making
│── connection.py # Handles connections between neural network nodes
│── node.py # Defines individual neural network nodesEnsure you have Python installed along with the required dependencies:
pip install pygameNavigate to the project directory and execute:
python main.py- Game Initialization: The game window opens, and a population of birds (AI players) is created.
- AI Perception: Each bird observes its environment using three vision inputs:
- Distance to the top pipe
- Horizontal distance to the pipe
- Distance to the bottom pipe
- Decision Making: The AI's neural network processes inputs and decides whether to jump.
- Survival and Fitness Calculation: Birds that survive longer score higher fitness points.
- Natural Selection: After all birds perish, the fittest individuals reproduce to create the next generation.
- Species Grouping: Birds with similar neural weights are grouped into species.
- Mutation and Evolution: Random mutations occur in the offspring, allowing the AI to evolve over time.