Giter VIP home page Giter VIP logo

flap-py's Introduction

flap-py

flap-py is about using a genetic algorithm to teach an AI how to play flappy bird in python. In each generation, the population of birds tries to stay alive, i.e. stay in between the pipes and not fall down. The next generation is mostly formed from the members of the previous one based on their score or fitness function. A smaller parts is sampled from the whole previous population with equal probability and the missing spots are filled with new, random birds to make sure there is enough diversity in the gene pool. Crossover and mutation are applied to converge to a 'good enough' solution quickly.

The 'brain' of the birds (neural network that decides wheter to jump or not) uses a keras model with 5 inputs, a hidden layer with 5 nodes and 2 outputs. Softmax is applied so the outputs can be interpreted as the probability to either jump or do nothing. The neural network gets the following inputs (normalized to [0,1]): birdY, birdVelocity, pipeDist, gapTop, gapBottom; Where pipe and gap related values are taken from the closest pipe in front of the bird.

Game Preview

A simplified version of the flappy bird game is drawn with the arcade library. Every bird is a triangle with a random color. Depending on the population size, it might need a few minutes to produce a new generation.

How to run

You want to install the dependencies with the python packet manager of your choice first:

  • tensorflow (or any keras backend of your choice)
  • keras
  • arcade
  • numpy
  • pygal (for plots of statistics)

The main application file is flap.py. There, you can also configure the population size (128 should be a good value). You can generate different statistics like top and average score of each generation by running stats.py. The generated plots will open in your default browser.

flap-py's People

Contributors

philno avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.