Skip to content

leocheung1001/flappy_bird_rl

Repository files navigation

Flappy Bird for Gymnasium

Python versions PyPI License

This repository contains the implementation of Gymnasium environment for the Flappy Bird game. The implementation of the game's logic and graphics was based on the flappy-bird-gym project, by @Talendar.

State space

The "FlappyBird-v0" environment, yields simple numerical information about the game's state as observations or RGB-arrays (images) representing the game's screen.

FlappyBird-v0

  • the last pipe's horizontal position

  • the last top pipe's vertical position

  • the last bottom pipe's vertical position

  • the next pipe's horizontal position

  • the next top pipe's vertical position

  • the next bottom pipe's vertical position

  • the next next pipe's horizontal position

  • the next next top pipe's vertical position

  • the next next bottom pipe's vertical position

  • player's vertical position

  • player's vertical velocity

  • player's rotation

  • or RGB-array (image) representing the game's screen

Action space

  • 0 - do nothing
  • 1 - flap

Rewards

  • +1 - every frame it stays alive
  • +100 - successfully passing a pipe
  • -100,0000- dying

Installation

To install flappy-bird-gymnasium, simply run the following command:

$ pip install flappy-bird-gymnasium

Usage

Like with other gymnasium environments, it's very easy to use flappy-bird-gymnasium. Simply import the package and create the environment with the make function. Take a look at the sample code below:

import flappy_bird_gymnasium
import gymnasium
env = gymnasium.make("FlappyBird-v0", render_mode="human")

obs, _ = env.reset()
while True:
    # Next action:
    # (feed the observation to your agent here)
    action = env.action_space.sample()

    # Processing:
    obs, reward, terminated, _, info = env.step(action)
    
    # Checking if the player is still alive
    if terminated:
        break

env.close()

Playing

To play the game (human mode), run the following command:

$ flappy_bird_gymnasium

To see a random agent playing, add an argument to the command:

$ flappy_bird_gymnasium --mode random

To test the DQN related algorithms for CS184 project, you can run:

$  python flappy_bird_gymnasium/my_priority.py -t
$  python flappy_bird_gymnasium/my_dqn.py
$  python flappy_bird_gymnasium/my_dueling_dqn.py -t

For the policy gradient related methods for our project, please refer to this link (https://github.com/JerryGao9527/Flappy-Bird-Gameplay-with-RL).

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages