Skip to main content

A Gymnasium environment for the Flappy Bird game.

Project description

Flappy Bird for Gymnasium

Python versions PyPI License

This repository contains the implementation of two Gymnasium environments 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-rgb-v0" environment, yields RGB-arrays (images) representing the game's screen. The "FlappyBird-v0" environment, on the other hand, yields simple numerical information about the game's state as observations.

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

FlappyBird-rgb-v0

The RGB image of size 288, 512 pixels. The pixel values are from range [0, 255]. The image does not contain score of bird.

Action space

  • 0 - do nothing
  • 1 - flap

Rewards

  • +0.1 - every frame it stays alive
  • +1.0 - successfully passing a pipe
  • -1.0 - 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 time
import flappy_bird_gymnasium
import gymnasium
env = gymnasium.make("FlappyBird-v0")

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)
    
    # Rendering the game:
    # (remove this two lines during training)
    env.render()
    time.sleep(1 / 30)  # FPS
    
    # 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 see a Deep Q Network agent playing, add an argument to the command:

$ flappy_bird_gymnasium --mode dqn

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flappy-bird-gymnasium-0.2.2.tar.gz (1.1 MB view details)

Uploaded Source

Built Distribution

flappy_bird_gymnasium-0.2.2-py3-none-any.whl (1.1 MB view details)

Uploaded Python 3

File details

Details for the file flappy-bird-gymnasium-0.2.2.tar.gz.

File metadata

  • Download URL: flappy-bird-gymnasium-0.2.2.tar.gz
  • Upload date:
  • Size: 1.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for flappy-bird-gymnasium-0.2.2.tar.gz
Algorithm Hash digest
SHA256 62cac60a280d20ed0d5aa658f0efd2cd5172399cb70e6ba6767ea28359c83a85
MD5 53f1e48b5c872961ddbce60ab57a4656
BLAKE2b-256 18ea2e12ffab88a360fa4f99831872536e657f71bba053e6154aa84514220818

See more details on using hashes here.

File details

Details for the file flappy_bird_gymnasium-0.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for flappy_bird_gymnasium-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fffa0d36028be45635ede55cd4994a250082018f8efa9d2d1f9b2043f4df5ef6
MD5 89b2e39faf3e1e3e04c9eb691dde8f3f
BLAKE2b-256 9d1f94c6bfa98d80ae43d55213e9a21943245803a9deb4ac73c664fd46d8e058

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page