Who doesn't love playing video games? But why play them yourself when you can get a computer to do it for you? Meet FlapPy bird.

What it does

FlapPy bird plays through an implementation of the classic flappy bird game in python. It uses a neural network to control the game, and finds the solution from scratch through evolution of the network weights.

How I built it

The first step was making the game itself and getting it playable. This involved tracking all the objects, detecting collisions, and getting inputs. The network runs with the game and takes the bird's y-position, the y-position of the next pipe's gap, and the x-position of the next pipe as inputs. It has one hidden layer, and the sign of the output determines whether to flap or not flap. When the bird hits a wall and the game ends, that network's score is recorded, and some random modifications are made to the network. If this change improves the score, the changes are kept, and the cycle repeats. In this way, it can find a solution without human intervention.

Challenges I ran into

In my first attempts, I tried to use the tensorflow libraries to make the network, but I had a lot of difficulty getting it installed and working due to python version and environment issues. In the end, I just implemented it myself. Another issue was that the network random adjustment rate took a lot of tuning. I wasn't sure if it was going to work, until it did.

Accomplishments that I'm proud of

The moment I first got the game playing itself was super exiting. This is something I've been wanting to do for a long time.

What I learned

I learned about how to use pygame, the structure of a neural network, and the power of an evolutionary technique.

What's next for Flappy Bird AI

This concept could easily be expanded to other games such as Snake or Pong. This is something I want to try in the near future.

Built With

Share this project: