Skip to content

Using the NEAT Genetic Neural Network Architecture to train a set of birds to play the popular game Flappy Bird. Also playable by user.

License

Notifications You must be signed in to change notification settings

jadhaddad01/FlappyBirdAI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FlappyBirdAI

PYGAME MENU LIBRARY FAILED AND/OR IS OUTDATED. FOR THIS REASON BY DEFAULT ONLY THE AI WILL RUN FOR SHOWCASE.

Using the NEAT Genetic Neural Network Architecture to train a set of birds to play the popular game Flappy Bird. Also playable by user.

Table of Contents

Description

This project was made using only the Python programming language.

Using the open-source NeuroEvolution of Augmenting Topologies (NEAT) library in python, we can train an Artificial Intelligence through a reward/punishement system to learn to play the popular game Flappy Bird.

The user can choose the population number of birds, to try different architectures of neural networks at the same time, and also the generation number, which determines how many times the AI plays the game, training itself after each generation to play better. (Generation and population option is saved after one game is played using these options)

The user can also play the game. The high-score of the user is also saved, even after the game is closed and reopened.

Usage Guide

Installation

  1. Requirements: Python 3.5+ (64-bit)
  2. Run below lines in your terminal
Terminal Demo
$ cd ../FlappyBirdAI-master

$ pip3 install -r requirements.txt

$ python3 flappy_bird.py

Playing Game

User AI
Options None
  1. Population: How many birds to train each generation at the same time
  2. Generations: How many times the AI will try the game again after all birds die

In-Game Information

User AI
  • Score: How many times the user passed a pipe
  • High Score: Highest score the user got since playing the game
  • Score: How many times the AI passed a pipe
  • Gen: Which generation the AI is currently playing in
  • Alive: How many birds are still playing the game
  • Best NN: Visualized neural network of one of the birds that are still alive

AI Output Visualization

Output will be in the same folder ../FlappyBirdAI-master. For explanation on used terms, refer to Neural Network Architecture

File Name Demo Explanation
best_neural_net.png
  • The best neural network throughout all generations
  • If the user quits before all generations end, it shows the best neural network for the last generation played
    • Green Connection: positive weight
    • Red Connection: negative weight
    • Dotted Connected: disabled connection
avg_fitness.svg Model of the best bird in terms of fitness in each generation, and the average of all birds
speciation.svg Shows the population per species throughout the generations

Architecture

Neural Network

  • The Neural Network only starts with connected input and output layers as shown below.
  • Hidden layers, bias neurons, and weights are then added. substracted, and modified as needed, (hence the Augmenting Topologies in NEAT).
  • Each bird is different from the other. Bird species is defined when birds possess different base architectures of nodes connected to one another. Birds of the same species only have different values for their weight connections.
  • Bird fitness is measured by score and distance. By trying to maximize fitness, the neural network changes it's architecture each generation to fulfill that goal.

Activation Function

The used activation function in this neural network is the TanH, where if an output of more than 0.5 is calculated, the bird jumps

Contributors

License

This project is licensed under the GPL-3.0 License. License Details

About

Using the NEAT Genetic Neural Network Architecture to train a set of birds to play the popular game Flappy Bird. Also playable by user.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages