Tetris (NES) for OpenAI Gym
Project description
gym-tetris
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.JoypadSpace
wrapper. There is also
SIMPLE_MOVEMENT
with a reduced action space (6 actions). For exact details,
see gym_tetris/actions.py.
from nes_py.wrappers import JoypadSpace
import gym_tetris
from gym_tetris.actions import MOVEMENT
env = gym_tetris.make('Tetris-v0')
env = JoypadSpace(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 -e <environment ID> -m <`human` or `random`>
Environments
There are two game modes define in NES Tetris, namely, A-type and B-type. A-type is the standard endurance Tetris game and B-type is an arcade style mode where the agent must clear a certain number of lines to win. There are three potential reward streams: (1) the change in score, (2) the change in number of lines cleared, and (3) a penalty for an increase in board height. The table below defines the available environments in terms of the game mode (i.e., A-type or B-type) and the rewards applied.
Environment | Game Mode | reward score | reward lines | penalize height |
---|---|---|---|---|
TetrisA-v0 |
A-type | ✅ | ✕ | ✕ |
TetrisA-v1 |
A-type | ✕ | ✅ | ✕ |
TetrisA-v2 |
A-type | ✅ | ✕ | ✅ |
TetrisA-v3 |
A-type | ✕ | ✅ | ✅ |
TetrisB-v0 |
B-type | ✅ | ✕ | ✕ |
TetrisB-v1 |
B-type | ✕ | ✅ | ✕ |
TetrisB-v2 |
B-type | ✅ | ✕ | ✅ |
TetrisB-v3 |
B-type | ✕ | ✅ | ✅ |
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.
- Tetris (NES): RAM Map. Data Crystal ROM Hacking.
- Tetris: Memory Addresses. NES Hacker.
- Applying Artificial Intelligence to Nintendo Tetris. MeatFighter.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file gym_tetris-3.0.2.tar.gz
.
File metadata
- Download URL: gym_tetris-3.0.2.tar.gz
- Upload date:
- Size: 36.1 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 563b682dbe46fa7bffade340cfdacaf1ea12d94fe9c88774620dd3eba5a49e9c |
|
MD5 | bc459740099af44362fde3f005af4a27 |
|
BLAKE2b-256 | e1522327b95dfc44df64c25c01fdfcd7c5b7db5936e80b9ae79e23f5c6ac158d |
File details
Details for the file gym_tetris-3.0.2-py3-none-any.whl
.
File metadata
- Download URL: gym_tetris-3.0.2-py3-none-any.whl
- Upload date:
- Size: 34.4 kB
- Tags: 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7eecdfa34b6f250926bcb7d291d8ae29c8927dab018a4da07adbec53a22f1095 |
|
MD5 | ae35f3248993efee5c0f653ebb3c5035 |
|
BLAKE2b-256 | 01b5e3ff8970bdfafabf59326bf419154d5193fb019f898160c535461a2e029f |