src.plangym.videogames.retro#

Implement the plangym API for retro environments.

Classes#

ActionDiscretizer

Wrap a gym-retro environment and make it use discrete actions for the Sonic game.

RetroEnv

Environment for playing gym-retro games.

Module Contents#

class src.plangym.videogames.retro.ActionDiscretizer(env, actions=None)[source]#

Bases: gymnasium.ActionWrapper

Wrap a gym-retro environment and make it use discrete actions for the Sonic game.

buttons = ['B', 'A', 'MODE', 'START', 'UP', 'DOWN', 'LEFT', 'RIGHT', 'C', 'Y', 'X', 'Z']#
actions#
_actions = []#
action_space#

Return the Env action_space unless overwritten then the wrapper action_space is used.

action(a)[source]#

Return the corresponding action in the emulator’s format.

Return type:

int

class src.plangym.videogames.retro.RetroEnv(name, frameskip=5, episodic_life=False, autoreset=True, delay_setup=False, remove_time_limit=True, obs_type='rgb', render_mode=None, wrappers=None, **kwargs)[source]#

Bases: plangym.videogames.env.VideogameEnv

Environment for playing gym-retro games.

Parameters:
  • name (str)

  • frameskip (int)

  • episodic_life (bool)

  • autoreset (bool)

  • delay_setup (bool)

  • remove_time_limit (bool)

  • obs_type (str)

  • render_mode (str | None)

  • wrappers (Iterable[plangym.core.wrap_callable] | None)

AVAILABLE_OBS_TYPES#
SINGLETON = True#
__getattr__(item)[source]#

Forward getattr to self.gym_env.

static get_win_condition(info)[source]#

Get win condition for games that have the end of the screen available.

Parameters:

info (dict[str, Any])

Return type:

bool

get_ram()[source]#

Return the ram of the emulator as a numpy array.

Return type:

numpy.ndarray

clone(**kwargs)[source]#

Return a copy of the environment with its initialization delayed.

Return type:

RetroEnv

init_gym_env()[source]#

Initialize the retro environment.

Return type:

gymnasium.Env

get_state()[source]#

Get the state of the retro environment.

Return type:

numpy.ndarray

set_state(state)[source]#

Set the state of the retro environment.

Parameters:

state (numpy.ndarray)

close()[source]#

Close the underlying gym.Env.

reset(return_state=True)[source]#

Restart the environment.

Parameters:

return_state (bool) – If True, it will return the state of the environment.

Returns:

(state, obs) if `return_state is True else return obs.

Return type:

numpy.ndarray | tuple[numpy.ndarray, numpy.ndarray]