Package: gym-simpletetris
gym-simpletetrisSimple Tetris is a simple Tetris environment built entirely in Python. Several
options are provided for modifying the environment and its reward system.InstallationpipThe preferred installation ofgym-simpletetrisis viapip:pipinstallgym-simpletetrisClone the projectThe code is easy to read and modify. If you wish to modify the package to your
needs, then follow these instructions:Fork the projectDownload it using:gitclonehttps://github.com/<YOUR-USERNAME>/gym-simpletetrisMake your changesInstall it using pip:cdgym-simpletetris
pipinstall-e./UsageYou can create an environment usinggym.makeand supplying the environment id.importgymimportgym_simpletetrisenv=gym.make('SimpleTetris-v0')obs=env.reset()episode=0whileepisode<10:action=env.action_space.sample()obs,reward,done,info=env.step(action)ifdone:print(f"Episode{episode+1}has finished.")episode+=1obs=env.reset()env.close()EnvironmentSeveral options are provided to modify the environment. Arguments can be used
at the creation of the environment:importgymimportgym_simpletetrisenv=gym.make('SimpleTetris-v0',height=20,# Height of Tetris gridwidth=10,# Width of Tetris gridobs_type='ram',# ram | grayscale | rgbextend_dims=False,# Extend ram or grayscale dimensionsrender_mode='rgb_array',# Unused parameterreward_step=False,# See reward tablepenalise_height=False,# See reward tablepenalise_height_increase=False,# See reward tableadvanced_clears=False,# See reward tablehigh_scoring=False,# See reward tablepenalise_holes=False,# See reward tablepenalise_holes_increase=False,# See reward tablelock_delay=0,# Lock delay as number of stepsstep_reset=False# Reset lock delay on step downwards)If using an observation type of grayscale or rgb then the environment will be
as an array of size 84 x 84. If using grayscale, then the grid can be returned
as 84 x 84 or extended to 84 x 84 x 1 ifentend_dimsis set to True. The rgb
array will always be returned as 84 x 84 x 3. If using an observation type of
ram andextend_dimsis set then an array of size width x height x 1 is
returned.Note: The default render mode is human. Therender_modeparameter does not
alter the default render mode. To render usingrgb_arraythen please use the
mode option when callingenv.render(mode='rgb_array').Reward TableOptionDescriptionreward_stepAdds a reward of +1 for every time step that does not include a line clear or end of game.penalise_heightPenalises the height of the current Tetris tower at every time step. A negative reward equal to the height of the current tower is added at every time step.penalise_height_increasePenalises an increase in the height of the Tetris tower. At each time step, if the height increases then a negative reward equal to the increase is given.advanced_clearsChanges the rewards for clearing lines to be similar to the modern Tetris system. The new rewards are 100 for a single line clear, 250 for a double line clear, 750 for a triple line clear and 3000 for a Tetris (quadruple line clear).high_scoringChanges the reward given for each line clear to 1000.penalise_holesPenalises the number of holes in the current Tetris tower. A hole is an empty cell with at least one non-empty cell above it.penalise_holes_increasePenalises an increase in the number of holes in the current Tetris tower.Note:penalise_heightandpenalise_height_increasecannot be used together.
If both are enabled thenpenalise_heightwill be used.Note:penalise_holesandpenalise_holes_increasecannot be used together.
If both are enabled thenpenalise_holeswill be used.infodictionaryThe info dictionary returned by each step includes the following keys:KeyTypeDescriptiontimeintThe time passed (no. of steps) since the start of the current gamecurrent_piecestringThe letter representing the current piecescoreintThe score of the current gamelines_clearedintThe number of lines cleared in the current gameholesintThe number of holes in the current Tetris towerdeathsintThe number of deaths since the environment was createdstatisticsdictThe number of Tetris pieces dispatched by type