/flappy-bird-ai

Flappy bird played by neural network improved by a genetic algorithm.

Primary LanguageTypeScriptGNU Affero General Public License v3.0AGPL-3.0

flappy-bird-ai

screenshot

This project was created for fun and studying purposes. These were the mains goals behind it:

  1. Use the Reactive Message Orientation Object Orientation. A paradigm I conceived to try to reflect Reactive System design in a OO level to get the hang of it and get used to the difficulties that may occur. To do this, I elaborated two ground rules:

    • Message oriented object communication: no public methods. Every communication has to be through a message mechanism (Event emitters) and serializable objects (dto, vo, and others). Objects are not aware of each other.
    • Stateless messages: the messages should include every information it needs, so the receivers process them accordingly.
  2. Study Neural Network. Find a mathematical function that receives inputs (bird y position, the closest pipe gap x position, the closest pipe gap y position) and results in a single output (should jump?).

  3. Study Genetic Algorithms. Select the best citizens of every generation and create a new generation based exclusively on this and operations such as crossover and mutations.

  4. Study Reinforcement Learning (q-learning). An agent (i.e. the bird) takes in a state and a reward from the environment, and based on these variables, the agent chooses the optimal action (flap/not to flap).

  5. Study Simulated annealing. Wikipedia. Specifically, it is a metaheuristic to approximate global optimization in a large search space for an optimization problem.

  6. Have fun. Yay.

If you want to, you can watch it live or/and defy the AI. I should warn you, it's not a good idea.

Remember to control the BLUE one (press SPACE BAR to jump and ESC to reinitialize round). Feel free to mess around with the url query params (Defaults to: mutationRate=0.01&populationPerGeneration=1500&relativeSelectedPopulationPerGeneration=0.01&qBirdsNumber=100)

Preview