src.plangym.videogames.nes
==========================

.. py:module:: src.plangym.videogames.nes

.. autoapi-nested-parse::

   Environment for playing Mario bros using gym-super-mario-bros.



Attributes
----------

.. autoapisummary::

   src.plangym.videogames.nes.RIGHT_ONLY
   src.plangym.videogames.nes.SIMPLE_MOVEMENT
   src.plangym.videogames.nes.COMPLEX_MOVEMENT
   src.plangym.videogames.nes.ObsType
   src.plangym.videogames.nes.ActType
   src.plangym.videogames.nes.RenderFrame


Classes
-------

.. autoapisummary::

   src.plangym.videogames.nes.NESWrapper
   src.plangym.videogames.nes.JoypadSpace
   src.plangym.videogames.nes.NesEnv
   src.plangym.videogames.nes.MarioEnv


Module Contents
---------------

.. py:data:: RIGHT_ONLY
   :value: [['NOOP'], ['right'], ['right', 'A'], ['right', 'B'], ['right', 'A', 'B']]


.. py:data:: SIMPLE_MOVEMENT
   :value: [['NOOP'], ['right'], ['right', 'A'], ['right', 'B'], ['right', 'A', 'B'], ['A'], ['left']]


.. py:data:: COMPLEX_MOVEMENT
   :value: [['NOOP'], ['right'], ['right', 'A'], ['right', 'B'], ['right', 'A', 'B'], ['A'], ['left'],...


.. py:data:: ObsType

.. py:data:: ActType

.. py:data:: RenderFrame

.. py:class:: NESWrapper(wrapped)

   A wrapper for the NES environment.


   .. py:attribute:: _wrapped


   .. py:method:: __getattr__(name)

      Get an attribute from the wrapped object.



   .. py:method:: __setattr__(name, value)

      Set an attribute on the wrapped object.



   .. py:method:: __delattr__(name)

      Delete an attribute from the wrapped object.



   .. py:method:: step(action)

      Modify the :attr:`env` after calling :meth:`step` using :meth:`self.observation`.



   .. py:method:: reset(*, seed = None, options = None)

      Modify the :attr:`env` after calling :meth:`reset`, returning a modified observation.



   .. py:method:: observation(observation)

      Return a modified observation.

      :param observation: The :attr:`env` observation

      :returns: The modified observation



.. py:class:: JoypadSpace(env, actions)

   Bases: :py:obj:`gymnasium.Wrapper`


   An environment wrapper to convert binary to discrete action space.


   .. py:attribute:: _button_map


   .. py:method:: buttons()
      :classmethod:


      Return the buttons that can be used as actions.



   .. py:attribute:: action_space

      Return the :attr:`Env` :attr:`action_space` unless overwritten then the wrapper :attr:`action_space` is used.


   .. py:attribute:: _action_map


   .. py:attribute:: _action_meanings


   .. py:method:: step(action)

      Take a step using the given action.

      :param action: the discrete action to perform
      :type action: int

      :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
      :rtype: a tuple of



   .. py:method:: get_keys_to_action()

      Return the dictionary of keyboard keys to actions.



   .. py:method:: get_action_meanings()

      Return a list of actions meanings.



.. py:class:: 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)

   Bases: :py:obj:`plangym.videogames.env.VideogameEnv`


   Environment for working with the NES-py emulator.


   .. py:property:: nes_env
      :type: NESEnv

      Access the underlying NESEnv.


   .. py:method:: get_image()

      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)



   .. py:method:: get_ram()

      Return a copy of the emulator environment.



   .. py:method:: get_state(state = None)

      Recover the internal state of the simulation.

      A state must completely describe the Environment at a given moment.



   .. py:method:: set_state(state)

      Set the internal state of the simulation.

      :param state: Target state to be set in the environment.

      :returns: None



   .. py:method:: close()

      Close the underlying :class:`gym.Env`.



   .. py:method:: __del__()

      Tear down the environment.



   .. py:method:: render(mode='rgb_array')

      Render the environment.



.. py:class:: MarioEnv(name, movement_type = 'simple', original_reward = False, **kwargs)

   Bases: :py:obj:`NesEnv`


   Interface for using gym-super-mario-bros in plangym.


   .. py:attribute:: AVAILABLE_OBS_TYPES


   .. py:attribute:: MOVEMENTS


   .. py:attribute:: _movement_type


   .. py:attribute:: _original_reward


   .. py:method:: get_state(state = None)

      Recover the internal state of the simulation.

      A state must completely describe the Environment at a given moment.



   .. py:method:: init_gym_env()

      Initialize the :class:`NESEnv`` instance that the current class is wrapping.



   .. py:method:: _update_info(info)


   .. py:method:: _get_info()


   .. py:method:: get_coords_obs(obs, info = None, **kwargs)

      Return the information contained in info as an observation if obs_type == "info".



   .. py:method:: process_reward(reward, info, **kwargs)

      Return a custom reward based on the x, y coordinates and level mario is in.



   .. py:method:: process_terminal(terminal, info, **kwargs)

      Return True if terminal or mario is dying.



   .. py:method:: process_info(info, **kwargs)

      Add additional data to the info dictionary.



