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
Environment | Game Mode | Reward function |
---|---|---|
TetrisA-v0 |
A | change in score |
TetrisA-v1 |
A | change in lines cleared |
TetrisA-v2 |
A | change in score - change in board height |
TetrisA-v3 |
A | change in lines cleared - change in board height |
TetrisB-v0 |
B | change in score |
TetrisB-v1 |
B | change in lines cleared |
TetrisB-v2 |
B | change in score - change in board height |
TetrisB-v3 |
B | change in lines cleared - change in board height |
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
Hashes for gym_tetris-3.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66d7ec128ba2c3e1c2981b186bfe8c44be58096bd6ffe200cea2ebe97f4009ff |
|
MD5 | 8452e7e40478bb735e2f18fbbd2d864a |
|
BLAKE2b-256 | 12948c7c7334523a52589e554ef614a166a5cabea02816100283e954ebd71078 |