Skip to main content

Tetris (NES) for OpenAI Gym

Project description

gym-tetris

BuildStatus PackageVersion PythonVersion Stable Format License

An OpenAI Gym environment for Tetris on The Nintendo Entertainment System (NES) based on the nes-py emulator.

Installation

The preferred installation of gym-tetris is from pip:

pip install gym-tetris

Usage

Python

You must import gym_tetris before trying to make an environment. This is because gym environments are registered at runtime. By default, gym_tetris environments use the full NES action space of 256 discrete actions. To constrain this, gym_tetris.actions provides an action list called MOVEMENT (20 discrete actions) for the nes_py.wrappers.BinarySpaceToDiscreteSpaceEnv wrapper.

from nes_py.wrappers import BinarySpaceToDiscreteSpaceEnv
import gym_tetris
from gym_tetris.actions import MOVEMENT

env = gym_tetris.make('Tetris-v0')
env = BinarySpaceToDiscreteSpaceEnv(env, MOVEMENT)

done = True
for step in range(5000):
    if done:
        state = env.reset()
    state, reward, done, info = env.step(env.action_space.sample())
    env.render()

env.close()

NOTE: gym_tetris.make is just an alias to gym.make for convenience.

NOTE: remove calls to render in training code for a nontrivial speedup.

Command Line

gym_tetris features a command line interface for playing environments using either the keyboard, or uniform random movement.

gym_tetris -m <`human` or `random`>

Step

Info about the rewards and info returned by the step method.

Reward Function

The reward function assumes the objective of the game is to increase the score. As such, the reward is defined as the instantaneous change in score for a given action.

info dictionary

The info dictionary returned by the step method contains the following keys:

Key Type Description
current_piece str the current piece as a string
number_of_lines int the number of cleared lines
score int the current score of the game
next_piece str the next piece on deck
statistics dict statistics for each piece

Citation

Please cite gym-tetris if you use it in your research.

@misc{gym-tetris,
  author = {Christian Kauten},
  title = {{Tetris (NES)} for {OpenAI Gym}},
  year = {2019},
  publisher = {GitHub},
  howpublished = {\url{https://github.com/Kautenja/gym-tetris}},
}

References

The following references contributed to the construction of this project.

  1. Tetris (NES): RAM Map. Data Crystal ROM Hacking.
  2. Tetris: Memory Addresses. NES Hacker.
  3. Applying Artificial Intelligence to Nintendo Tetris. MeatFighter.

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

gym_tetris-2.1.0.tar.gz (34.2 kB view details)

Uploaded Source

Built Distribution

gym_tetris-2.1.0-py2.py3-none-any.whl (32.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file gym_tetris-2.1.0.tar.gz.

File metadata

  • Download URL: gym_tetris-2.1.0.tar.gz
  • Upload date:
  • Size: 34.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.3

File hashes

Hashes for gym_tetris-2.1.0.tar.gz
Algorithm Hash digest
SHA256 744ea3ec6c5ba8408256d5f6bc164600a8818cfec39f87a9d6a66ae51d25dde6
MD5 8c72c278c4d34e7a3656745cddc609fd
BLAKE2b-256 6e96a1856decea03e6b98037befb12be7a34efd8b681e6e2219e35e8f4327bea

See more details on using hashes here.

File details

Details for the file gym_tetris-2.1.0-py2.py3-none-any.whl.

File metadata

  • Download URL: gym_tetris-2.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 32.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.3

File hashes

Hashes for gym_tetris-2.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 384af64797bdefeddc063c5f49a8999a4b5c40595b50e75e965dcc63df2c3184
MD5 fb59ad34c544a463e4ae85bf58a26fd6
BLAKE2b-256 727869ef71316af5d1efaf027484b4e01dc3789746c1a83831f2ccae8d9fb2be

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