Skip to content

ColasGael/RL-flappy-bird

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RL-flappy-bird

Reinforcement Learning on a playable version of Flappy Bird.

Game screenshot

Demo

Training the AI agent from scratch — watch it progressively learn to navigate the pipes:

AI training demo

Installation

pip install -e .

On Linux, you also need tkinter as a backend for interactive matplotlib support:

sudo apt-get install python3-tk

To also install the tools for recording demos:

pip install -e ".[tools]"

Usage

Human player

rl-flappy-bird

A window will open. The score and commands are displayed on the right side of the window.

AI player

To let the AI agent learn from scratch:

rl-flappy-bird --agent ai

To load a pretrained agent:

rl-flappy-bird --agent ai --load_save

Press S during the simulation to save the agent's current state.

Record a training demo

python tools/record_demo.py

RL Algorithm

The state is composed of the Bird's horizontal and vertical distances to the next pipe opening.

The agent explores its environment with an increasingly greedy Epsilon-Greedy scheme. After each simulation, it:

  1. Updates its approximation of the underlying Markov Decision Process from observed transitions.
  2. Solves for the optimal value function via Value Iteration.

The best action in a given state is the one that maximizes the expected value.

Customization

Sprites (bird, pipes, background) can be swapped by:

  • placing new JPG files in the sprites/ directory;
  • updating the sprite paths in rl_flappy_bird/args.py.

Other simulation parameters can also be tuned in args.py:

  • environment dimensions;
  • bird dynamics (gravity, jump velocity);
  • RL hyperparameters (discount factor, state discretization).

About

Reinforcement Learning on playable version of Flappy Bird

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages