src.plangym.videogames.nes#
Environment for playing Mario bros using gym-super-mario-bros.
Attributes#
Classes#
A wrapper for the NES environment. |
|
An environment wrapper to convert binary to discrete action space. |
|
Environment for working with the NES-py emulator. |
|
Interface for using gym-super-mario-bros in plangym. |
Module Contents#
- src.plangym.videogames.nes.RIGHT_ONLY = [['NOOP'], ['right'], ['right', 'A'], ['right', 'B'], ['right', 'A', 'B']]#
- src.plangym.videogames.nes.SIMPLE_MOVEMENT = [['NOOP'], ['right'], ['right', 'A'], ['right', 'B'], ['right', 'A', 'B'], ['A'], ['left']]#
- src.plangym.videogames.nes.COMPLEX_MOVEMENT = [['NOOP'], ['right'], ['right', 'A'], ['right', 'B'], ['right', 'A', 'B'], ['A'], ['left'],...#
- src.plangym.videogames.nes.ObsType#
- src.plangym.videogames.nes.ActType#
- src.plangym.videogames.nes.RenderFrame#
- class src.plangym.videogames.nes.NESWrapper(wrapped)[source]#
A wrapper for the NES environment.
- _wrapped#
- step(action)[source]#
Modify the
envafter callingstep()usingself.observation().- Parameters:
action (ActType)
- Return type:
tuple[gymnasium.core.WrapperObsType, gymnasium.core.SupportsFloat, bool, bool, dict[str, Any]]
- class src.plangym.videogames.nes.JoypadSpace(env, actions)[source]#
Bases:
gymnasium.WrapperAn environment wrapper to convert binary to discrete action space.
- Parameters:
env (gymnasium.Env)
actions (list)
- _button_map#
- action_space#
Return the
Envaction_spaceunless overwritten then the wrapperaction_spaceis used.
- _action_map#
- _action_meanings#
- step(action)[source]#
Take a step using the given action.
- Parameters:
action (int) – the discrete action to perform
- Returns:
(numpy.ndarray) the state as a result of the action
(float) the reward achieved by taking the action
(bool) a flag denoting whether the episode has ended
(dict) a dictionary of extra information
- Return type:
a tuple of
- class src.plangym.videogames.nes.NesEnv(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.VideogameEnvEnvironment for working with the NES-py emulator.
- 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)
- property nes_env: NESEnv#
Access the underlying NESEnv.
- Return type:
NESEnv
- get_image()[source]#
Return a numpy array containing the rendered view of the environment.
Square matrices are interpreted as a greyscale image. Three-dimensional arrays are interpreted as RGB images with channels (Height, Width, RGB)
- Return type:
numpy.ndarray
- get_state(state=None)[source]#
Recover the internal state of the simulation.
A state must completely describe the Environment at a given moment.
- Parameters:
state (numpy.ndarray | None)
- Return type:
numpy.ndarray
- class src.plangym.videogames.nes.MarioEnv(name, movement_type='simple', original_reward=False, **kwargs)[source]#
Bases:
NesEnvInterface for using gym-super-mario-bros in plangym.
- Parameters:
name (str)
movement_type (str)
original_reward (bool)
- AVAILABLE_OBS_TYPES#
- MOVEMENTS#
- _movement_type#
- _original_reward#
- get_state(state=None)[source]#
Recover the internal state of the simulation.
A state must completely describe the Environment at a given moment.
- Parameters:
state (numpy.ndarray | None)
- Return type:
numpy.ndarray
- init_gym_env()[source]#
Initialize the
NESEnv`instance that the current class is wrapping.- Return type:
gymnasium.Env
- get_coords_obs(obs, info=None, **kwargs)[source]#
Return the information contained in info as an observation if obs_type == “info”.
- Parameters:
obs (numpy.ndarray)
info (dict[str, Any] | None)
- Return type:
numpy.ndarray
- process_reward(reward, info, **kwargs)[source]#
Return a custom reward based on the x, y coordinates and level mario is in.
- Return type:
float