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.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.
- 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-2.0.1.tar.gz
.
File metadata
- Download URL: gym_tetris-2.0.1.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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9876c742e9eafb3c9471bdf4c0994ad7040078c3c805d9138ad9c7b46e52a0ab |
|
MD5 | c0152b40919bb2cf50a87b65fb504cba |
|
BLAKE2b-256 | 16cd8baf61790c47ae427cd625c2a5ab37e01abec9e94af5f8ee1ea0f96bc832 |
File details
Details for the file gym_tetris-2.0.1-py2.py3-none-any.whl
.
File metadata
- Download URL: gym_tetris-2.0.1-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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75b9733be8be509ad3a6e759f588b0f0a539fa83e8e30f667a596bc4a844093b |
|
MD5 | f3cc7dbe0da89bdc9263882549a2c969 |
|
BLAKE2b-256 | 184161a2ebbfcad8f4489c66d8b156d2a0930719e8569929c981a1ddac4fdd0d |