
    hs              
         S r SSKJr  SSKJr  SSKJrJrJrJ	r	J
r
  SSKrSSKrSSKJr  SSKJrJr  \(       a  SSKJrJr  \
" S	5      r\
" S
5      r\
" S5      r " S S\\\4   5      r\
" S5      r\
" S5      r " S S\\\4   \\\\\4   5      r " S S\\\\\4   5      r " S S\\\\\4   5      r " S S\\\\\4   5      rg)zWCore API for Environment, Wrapper, ActionWrapper, RewardWrapper and ObservationWrapper.    )annotations)deepcopy)TYPE_CHECKINGAnyGenericSupportsFloatTypeVarN)spaces)RecordConstructorArgsseeding)EnvSpecWrapperSpecObsTypeActTypeRenderFramec                  X   \ rS rSr% SrS/ 0rS\S'   SrS\S'   SrS	\S
'   S\S'   S\S'   Sr	S\S'   Sr
S\S'       S%S jrSSS.     S&S jjrS'S jrS r\S(S j5       r\S)S j5       r\S*S j5       r\R&                  S+S j5       rS rS rS,S jrS-S jrS.S  jrS!S".S/S# jjrS$rg)0Env   a
  The main Gymnasium class for implementing Reinforcement Learning Agents environments.

The class encapsulates an environment with arbitrary behind-the-scenes dynamics through the :meth:`step` and :meth:`reset` functions.
An environment can be partially or fully observed by single agents. For multi-agent environments, see PettingZoo.

The main API methods that users of this class need to know are:

- :meth:`step` - Updates an environment with actions returning the next agent observation, the reward for taking that actions,
  if the environment has terminated or truncated due to the latest action and information from the environment about the step, i.e. metrics, debug info.
- :meth:`reset` - Resets the environment to an initial state, required before calling step.
  Returns the first agent observation for an episode and information, i.e. metrics, debug info.
- :meth:`render` - Renders the environments to help visualise what the agent see, examples modes are "human", "rgb_array", "ansi" for text.
- :meth:`close` - Closes the environment, important when external software is used, i.e. pygame for rendering, databases

Environments have additional attributes for users to understand the implementation

- :attr:`action_space` - The Space object corresponding to valid actions, all valid actions should be contained within the space.
- :attr:`observation_space` - The Space object corresponding to valid observations, all valid observations should be contained within the space.
- :attr:`spec` - An environment spec that contains the information used to initialize the environment from :meth:`gymnasium.make`
- :attr:`metadata` - The metadata of the environment, e.g. `{"render_modes": ["rgb_array", "human"], "render_fps": 30}`. For Jax or Torch, this can be indicated to users with `"jax"=True` or `"torch"=True`.
- :attr:`np_random` - The random number generator for the environment. This is automatically assigned during
  ``super().reset(seed=seed)`` and when assessing :attr:`np_random`.

.. seealso:: For modifying or extending environments use the :class:`gymnasium.Wrapper` class

Note:
    To get reproducible sampling of actions, a seed can be set with ``env.action_space.seed(123)``.

Note:
    For strict type checking (e.g. mypy or pyright), :class:`Env` is a generic class with two parameterized types: ``ObsType`` and ``ActType``.
    The ``ObsType`` and ``ActType`` are the expected types of the observations and actions used in :meth:`reset` and :meth:`step`.
    The environment's :attr:`observation_space` and :attr:`action_space` should have type ``Space[ObsType]`` and ``Space[ActType]``,
    see a space's implementation to find its parameterized type.
render_modesdict[str, Any]metadataN
str | Nonerender_modeEnvSpec | Nonespeczspaces.Space[ActType]action_spacezspaces.Space[ObsType]observation_spaceznp.random.Generator | None
_np_random
int | None_np_random_seedc                    [         e)a
  Run one timestep of the environment's dynamics using the agent actions.

When the end of an episode is reached (``terminated or truncated``), it is necessary to call :meth:`reset` to
reset this environment's state for the next episode.

.. versionchanged:: 0.26

    The Step API was changed removing ``done`` in favor of ``terminated`` and ``truncated`` to make it clearer
    to users when the environment had terminated or truncated which is critical for reinforcement learning
    bootstrapping algorithms.

Args:
    action (ActType): an action provided by the agent to update the environment state.

Returns:
    observation (ObsType): An element of the environment's :attr:`observation_space` as the next observation due to the agent actions.
        An example is a numpy array containing the positions and velocities of the pole in CartPole.
    reward (SupportsFloat): The reward as a result of taking the action.
    terminated (bool): Whether the agent reaches the terminal state (as defined under the MDP of the task)
        which can be positive or negative. An example is reaching the goal state or moving into the lava from
        the Sutton and Barto Gridworld. If true, the user needs to call :meth:`reset`.
    truncated (bool): Whether the truncation condition outside the scope of the MDP is satisfied.
        Typically, this is a timelimit, but could also be used to indicate an agent physically going out of bounds.
        Can be used to end the episode prematurely before a terminal state is reached.
        If true, the user needs to call :meth:`reset`.
    info (dict): Contains auxiliary diagnostic information (helpful for debugging, learning, and logging).
        This might, for instance, contain: metrics that describe the agent's performance state, variables that are
        hidden from observations, or individual reward terms that are combined to produce the total reward.
        In OpenAI Gym <v26, it contains "TimeLimit.truncated" to distinguish truncation and termination,
        however this is deprecated in favour of returning terminated and truncated variables.
    done (bool): (Deprecated) A boolean value for if the episode has ended, in which case further :meth:`step` calls will
        return undefined results. This was removed in OpenAI Gym v26 in favor of terminated and truncated attributes.
        A done signal may be emitted for different reasons: Maybe the task underlying the environment was solved successfully,
        a certain timelimit was exceeded, or the physics simulation has entered an invalid state.
NotImplementedErrorselfactions     H/home/james-whalen/.local/lib/python3.13/site-packages/gymnasium/core.pystepEnv.stepJ   s    L "!    seedoptionsc               R    Ub$  [         R                  " U5      u  U l        U l        gg)a  Resets the environment to an initial internal state, returning an initial observation and info.

This method generates a new starting state often with some randomness to ensure that the agent explores the
state space and learns a generalised policy about the environment. This randomness can be controlled
with the ``seed`` parameter otherwise if the environment already has a random number generator and
:meth:`reset` is called with ``seed=None``, the RNG is not reset.

Therefore, :meth:`reset` should (in the typical use case) be called with a seed right after initialization and then never again.

For Custom environments, the first line of :meth:`reset` should be ``super().reset(seed=seed)`` which implements
the seeding correctly.

.. versionchanged:: v0.25

    The ``return_info`` parameter was removed and now info is expected to be returned.

Args:
    seed (optional int): The seed that is used to initialize the environment's PRNG (`np_random`) and
        the read-only attribute `np_random_seed`.
        If the environment does not already have a PRNG and ``seed=None`` (the default option) is passed,
        a seed will be chosen from some source of entropy (e.g. timestamp or /dev/urandom).
        However, if the environment already has a PRNG and ``seed=None`` is passed, the PRNG will *not* be reset
        and the env's :attr:`np_random_seed` will *not* be altered.
        If you pass an integer, the PRNG will be reset even if it already exists.
        Usually, you want to pass an integer *right after the environment has been initialized and then never again*.
        Please refer to the minimal example above to see this paradigm in action.
    options (optional dict): Additional information to specify how the environment is reset (optional,
        depending on the specific environment)

Returns:
    observation (ObsType): Observation of the initial state. This will be an element of :attr:`observation_space`
        (typically a numpy array) and is analogous to the observation returned by :meth:`step`.
    info (dictionary):  This dictionary contains auxiliary information complementing ``observation``. It should be analogous to
        the ``info`` returned by :meth:`step`.
N)r   	np_randomr   r    r%   r,   r-   s      r'   reset	Env.resetr   s*    T 4;4E4Ed4K1DOT1 r*   c                    [         e)a  Compute the render frames as specified by :attr:`render_mode` during the initialization of the environment.

The environment's :attr:`metadata` render modes (`env.metadata["render_modes"]`) should contain the possible
ways to implement the render modes. In addition, list versions for most render modes is achieved through
`gymnasium.make` which automatically applies a wrapper to collect rendered frames.

Note:
    As the :attr:`render_mode` is known during ``__init__``, the objects used to render the environment state
    should be initialised in ``__init__``.

By convention, if the :attr:`render_mode` is:

- None (default): no render is computed.
- "human": The environment is continuously rendered in the current display or terminal, usually for human consumption.
  This rendering should occur during :meth:`step` and :meth:`render` doesn't need to be called. Returns ``None``.
- "rgb_array": Return a single frame representing the current state of the environment.
  A frame is a ``np.ndarray`` with shape ``(x, y, 3)`` representing RGB values for an x-by-y pixel image.
- "ansi": Return a strings (``str``) or ``StringIO.StringIO`` containing a terminal-style text representation
  for each time step. The text can include newlines and ANSI escape sequences (e.g. for colors).
- "rgb_array_list" and "ansi_list": List based version of render modes are possible (except Human) through the
  wrapper, :py:class:`gymnasium.wrappers.RenderCollection` that is automatically applied during ``gymnasium.make(..., render_mode="rgb_array_list")``.
  The frames collected are popped after :meth:`render` is called or :meth:`reset`.

Note:
    Make sure that your class's :attr:`metadata` ``"render_modes"`` key includes the list of supported modes.

.. versionchanged:: 0.25.0

    The render function was changed to no longer accept parameters, rather these parameters should be specified
    in the environment initialised, i.e., ``gymnasium.make("CartPole-v1", render_mode="human")``
r"   r%   s    r'   render
Env.render   s    @ "!r*   c                    g)a  After the user has finished using the environment, close contains the code necessary to "clean up" the environment.

This is critical for closing rendering windows, database or HTTP connections.
Calling ``close`` on an already closed environment has no effect and won't raise an error.
N r4   s    r'   close	Env.close   s     	r*   c                    U $ )zrReturns the base non-wrapped environment.

Returns:
    Env: The base non-wrapped :class:`gymnasium.Env` instance
r8   r4   s    r'   	unwrappedEnv.unwrapped   s	     r*   c                x    U R                   c"  [        R                  " 5       u  U l        U l         U R                   $ )aq  Returns the environment's internal :attr:`_np_random_seed` that if not set will first initialise with a random int as seed.

If :attr:`np_random_seed` was set directly instead of through :meth:`reset` or :meth:`set_np_random_through_seed`,
the seed will take the value -1.

Returns:
    int: the seed of the current `np_random` or -1, if the seed of the rng is unknown
)r    r   r/   r   r4   s    r'   np_random_seedEnv.np_random_seed   s4     '4;4E4E4G1DOT1###r*   c                x    U R                   c"  [        R                  " 5       u  U l         U l        U R                   $ )zReturns the environment's internal :attr:`_np_random` that if not set will initialise with a random seed.

Returns:
    Instances of `np.random.Generator`
)r   r   r/   r    r4   s    r'   r/   Env.np_random   s0     ??"4;4E4E4G1DOT1r*   c                    Xl         SU l        g)a/  Sets the environment's internal :attr:`_np_random` with the user-provided Generator.

Since it is generally not possible to extract a seed from an instance of a random number generator,
this will also set the :attr:`_np_random_seed` to `-1`, which is not valid as input for the creation
of a numpy rng.
Nr   r    r%   values     r'   r/   rB      s      !r*   c                    U R                   c  S[        U 5      R                   S3$ S[        U 5      R                   SU R                   R                   S3$ )z~Returns a string of the environment with :attr:`spec` id's if :attr:`spec.

Returns:
    A string identifying the environment
<z
 instance>z>>)r   type__name__idr4   s    r'   __str__Env.__str__   sP     99tDz**+:66tDz**+1TYY\\N"==r*   c                    U $ )z+Support with-statement for the environment.r8   r4   s    r'   	__enter__Env.__enter__  s    r*   c                $    U R                  5         g)zFSupport with-statement for the environment and closes the environment.F)r9   )r%   argss     r'   __exit__Env.__exit__  s    

r*   c                    [        X5      $ )z9Checks if the attribute `name` exists in the environment.)hasattrr%   names     r'   has_wrapper_attrEnv.has_wrapper_attr      t""r*   c                    [        X5      $ )z/Gets the attribute `name` from the environment.)getattrrX   s     r'   get_wrapper_attrEnv.get_wrapper_attr  r\   r*   Tforcec               L    U(       d  [        X5      (       a  [        XU5        gg)zhSets the attribute `name` on the environment with `value`, see `Wrapper.set_wrapper_attr` for more info.TF)rW   setattr)r%   rY   rG   rb   s       r'   set_wrapper_attrEnv.set_wrapper_attr  s    GD''D&r*   rE   r&   r   return9tuple[ObsType, SupportsFloat, bool, bool, dict[str, Any]])r,   r   r-   dict[str, Any] | Nonerh   ztuple[ObsType, dict[str, Any]]rh   z&RenderFrame | list[RenderFrame] | Nonerh   Env[ObsType, ActType])rh   intrh   np.random.GeneratorrG   rp   )rS   r   rY   strrh   boolrY   rs   rh   r   rY   rs   rG   r   rb   rt   rh   rt   )rK   
__module____qualname____firstlineno____doc__r   __annotations__r   r   r   r    r(   r1   r5   r9   propertyr<   r?   r/   setterrM   rP   rT   rZ   r_   re   __static_attributes__r8   r*   r'   r   r      s#   !H !/3Hn3"K"D. (',, .2J*1"&OZ&&"&"	B&"V  )-	+L +L '	+L
 
(+LZ "D   $ $   	" 	"	>## HL  r*   r   WrapperObsTypeWrapperActTypec                     \ rS rSrSrS!S jr    S"S jrSSS.     S#S jjrS$S jrS	 r	\
S%S
 j5       r\
S&S j5       r\
S'S j5       r\S(S j5       rS)S jrS*S jrSS.S+S jjrS rS r\S,S j5       r\
  S-S j5       r\R.                  S.S j5       r\
  S/S j5       r\R.                  S0S j5       r\
S1S j5       r\R.                  S2S j5       r\
S3S j5       r\
S4S j5       r\R.                  S5S j5       r\
S 5       rS rg)6Wrapperi   a  Wraps a :class:`gymnasium.Env` to allow a modular transformation of the :meth:`step` and :meth:`reset` methods.

This class is the base class of all wrappers to change the behavior of the underlying environment.
Wrappers that inherit from this class can modify the :attr:`action_space`, :attr:`observation_space`
and :attr:`metadata` attributes, without changing the underlying environment's attributes.
Moreover, the behavior of the :meth:`step` and :meth:`reset` methods can be changed by these wrappers.

Some attributes (:attr:`spec`, :attr:`render_mode`, :attr:`np_random`) will point back to the wrapper's environment
(i.e. to the corresponding attributes of :attr:`env`).

Note:
    If you inherit from :class:`Wrapper`, don't forget to call ``super().__init__(env)``
c                    Xl         [        U[        5      (       d   S[        U5       35       eSU l        SU l        SU l        SU l        g)zWraps an environment to allow a modular transformation of the :meth:`step` and :meth:`reset` methods.

Args:
    env: The environment to wrap
z-Expected env to be a `gymnasium.Env` but got N)env
isinstancer   rJ   _action_space_observation_space	_metadata_cached_specr%   r   s     r'   __init__Wrapper.__init__2  s]     
 
 	G:49+F	G 
 CGGK04,0r*   c                8    U R                   R                  U5      $ )z]Uses the :meth:`step` of the :attr:`env` that can be overwritten to change the returned data.)r   r(   r$   s     r'   r(   Wrapper.stepC  s     xx}}V$$r*   Nr+   c               4    U R                   R                  XS9$ )z^Uses the :meth:`reset` of the :attr:`env` that can be overwritten to change the returned data.r+   )r   r1   r0   s      r'   r1   Wrapper.resetI  s     xx~~4~99r*   c                6    U R                   R                  5       $ )z_Uses the :meth:`render` of the :attr:`env` that can be overwritten to change the returned data.)r   r5   r4   s    r'   r5   Wrapper.renderO  s    xx  r*   c                6    U R                   R                  5       $ )z#Closes the wrapper and :attr:`env`.)r   r9   r4   s    r'   r9   Wrapper.closeS  s    xx~~r*   c                .    U R                   R                  $ )z6Returns the base environment's :attr:`np_random_seed`.)r   r?   r4   s    r'   r?   Wrapper.np_random_seedW  s     xx&&&r*   c                .    U R                   R                  $ )zReturns the base environment of the wrapper.

This will be the bare :class:`gymnasium.Env` environment, underneath all layers of wrappers.
)r   r<   r4   s    r'   r<   Wrapper.unwrapped\  s     xx!!!r*   c                :   U R                   b  U R                   $ U R                  R                  nUb  [        U [        5      (       a/  [        U S5      nSU;   a  [        U5      nUR                  S5        OSnSSKJ	n  U" U R                  5       U R                   S[        U 5      R                   3US9n [        U5      nU=R                  U4-  sl        Xl         U$ ! [         a/  n[         R"                  R%                  SU S	U 35         SnAgSnAff = f)
znReturns the :attr:`Env` :attr:`spec` attribute with the `WrapperSpec` if the wrapper inherits from `EzPickle`.N_saved_kwargsr   r   r   :rY   entry_pointkwargszAn exception occurred (z%) while copying the environment spec=)r   r   r   r   r   r^   r   popgymnasium.envs.registrationr   
class_namerw   rJ   rK   additional_wrappers	Exception	gymnasiumloggerwarn)r%   env_specr   r   wrapper_speces         r'   r   Wrapper.specd  s    ($$$88==$ 566 7F?%f-FJJu%?&__&#/qd1D1D0EFL#H-,,?, %    %%-aS0UV^U_` 	s   8!C! !
D+%DDc                l    SSK Jn  U" U R                  5       U R                   SU R                   3US9$ )z+Generates a `WrapperSpec` for the wrappers.r   r   r   r   )r   r   r   rw   rK   )clsr   r   s      r'   r   Wrapper.wrapper_spec  s8     	<!>>*!CLL>:
 	
r*   c                Z    [        X5      (       a  gU R                  R                  U5      $ )zGChecks if the given attribute is within the wrapper or its environment.T)rW   r   rZ   rX   s     r'   rZ   Wrapper.has_wrapper_attr  s%    488,,T22r*   c                    [        X5      (       a  [        X5      $  U R                  R                  U5      $ ! [         a&  n[	        SU R                  5        SU< 35      UeSnAff = f)zGets an attribute from the wrapper and lower environments if `name` doesn't exist in this object.

Args:
    name: The variable name to get

Returns:
    The variable with name in wrapper or lower environments
zwrapper z has no attribute N)rW   r^   r   r_   AttributeErrorr   )r%   rY   r   s      r'   r_   Wrapper.get_wrapper_attr  sm     44&&xx0066! $t011CD8Ls   8 
A(!A##A(Tra   c                   [        X5      (       a  [        XU5        gU R                  R                  XSS9nU(       a  gU(       a  [        XU5        gg)ar  Sets an attribute on this wrapper or lower environment if `name` is already defined.

Args:
    name: The variable name
    value: The new variable value
    force: Whether to create the attribute on this wrapper if it does not exists on the
       lower environment instead of raising an exception

Returns:
    If the variable has been set in this or a lower wrapper.
TFra   )rW   rd   r   re   )r%   rY   rG   rb   already_sets        r'   re   Wrapper.set_wrapper_attr  sN     4D&((33Du3MKE*r*   c                L    S[        U 5      R                   U R                   S3$ )zCReturns the wrapper name and the :attr:`env` representation string.rI   >)rJ   rK   r   r4   s    r'   rM   Wrapper.__str__  s$    4:&&'z33r*   c                    [        U 5      $ )z1Returns the string representation of the wrapper.)rs   r4   s    r'   __repr__Wrapper.__repr__  s    4yr*   c                    U R                   $ )z&Returns the class name of the wrapper.)rK   )r   s    r'   r   Wrapper.class_name  s     ||r*   c                `    U R                   c  U R                  R                  $ U R                   $ )zmReturn the :attr:`Env` :attr:`action_space` unless overwritten then the wrapper :attr:`action_space` is used.)r   r   r   r4   s    r'   r   Wrapper.action_space  s,    
 %88(((!!!r*   c                    Xl         g N)r   r%   spaces     r'   r   r     s    "r*   c                `    U R                   c  U R                  R                  $ U R                   $ )zwReturn the :attr:`Env` :attr:`observation_space` unless overwritten then the wrapper :attr:`observation_space` is used.)r   r   r   r4   s    r'   r   Wrapper.observation_space  s,    
 ""*88---&&&r*   c                    Xl         g r   )r   r   s     r'   r   r     s    "'r*   c                `    U R                   c  U R                  R                  $ U R                   $ )z)Returns the :attr:`Env` :attr:`metadata`.)r   r   r   r4   s    r'   r   Wrapper.metadata  s(     >>!88$$$~~r*   c                    Xl         g r   )r   rF   s     r'   r   r     s    r*   c                .    U R                   R                  $ )z,Returns the :attr:`Env` :attr:`render_mode`.)r   r   r4   s    r'   r   Wrapper.render_mode  s     xx###r*   c                .    U R                   R                  $ )z4Returns the :attr:`Env` :attr:`np_random` attribute.r   r/   r4   s    r'   r/   Wrapper.np_random  s     xx!!!r*   c                $    XR                   l        g r   r   rF   s     r'   r/   r     s    "r*   c                    [        S5      e)zThis code will never be run due to __getattr__ being called prior this.

It seems that @property overwrites the variable (`_np_random`) meaning that __getattr__ gets called with the missing variable.
zTCan't access `_np_random` of a wrapper, use `.unwrapped._np_random` or `.np_random`.)r   r4   s    r'   r   Wrapper._np_random  s     b
 	
r*   )r   r   r   r   r   r   rm   )r&   r   rh   @tuple[WrapperObsType, SupportsFloat, bool, bool, dict[str, Any]]r,   r   r-   rj   rh   z%tuple[WrapperObsType, dict[str, Any]]rk   )rh   r   rl   )rh   r   )r   r   rh   r   rr   ru   rv   )rh   rs   )rh   z4spaces.Space[ActType] | spaces.Space[WrapperActType])r   zspaces.Space[WrapperActType])rh   z4spaces.Space[ObsType] | spaces.Space[WrapperObsType])r   zspaces.Space[WrapperObsType])rh   r   )rG   r   )rh   r   ro   rq   )rK   rw   rx   ry   rz   r   r(   r1   r5   r9   r|   r?   r<   r   classmethodr   rZ   r_   re   rM   r   r   r   r}   r   r   r   r/   r   r~   r8   r*   r'   r   r      s   1"%$%	I% %)4:!:3H:	.:!  ' ' " " # #J 
 
3& HL 24   "	=" " # # '	=' ' ( (   __  $ $ " " # # 
 
r*   r   c                  \    \ rS rSrSrS
S jrSSS.     SS jjr    SS jrSS jrS	r	g)ObservationWrapperi  aV  Modify observations from :meth:`Env.reset` and :meth:`Env.step` using :meth:`observation` function.

If you would like to apply a function to only the observation before
passing it to the learning code, you can simply inherit from :class:`ObservationWrapper` and overwrite the method
:meth:`observation` to implement that transformation. The transformation defined in that method must be
reflected by the :attr:`env` observation space. Otherwise, you need to specify the new observation space of the
wrapper by setting :attr:`self.observation_space` in the :meth:`__init__` method of your wrapper.
c                .    [         R                  X5        g)zTConstructor for the observation wrapper.

Args:
    env: Environment to be wrapped.
Nr   r   r   s     r'   r   ObservationWrapper.__init__       	#r*   Nr+   c               ^    U R                   R                  XS9u  p4U R                  U5      U4$ )zvModifies the :attr:`env` after calling :meth:`reset`, returning a modified observation using :meth:`self.observation`.r+   )r   r1   observation)r%   r,   r-   obsinfos        r'   r1   ObservationWrapper.reset%  s0     HHNNN>	$d**r*   c                h    U R                   R                  U5      u  p#pEnU R                  U5      X4XV4$ )zpModifies the :attr:`env` after calling :meth:`step` using :meth:`self.observation` on the returned observations.)r   r(   r   r%   r&   r   reward
terminated	truncatedr   s          r'   r(   ObservationWrapper.step,  s6     <@88==;P8ZD,f)QQr*   c                    [         e)z{Returns a modified observation.

Args:
    observation: The :attr:`env` observation

Returns:
    The modified observation
r"   )r%   r   s     r'   r   ObservationWrapper.observation3  
     "!r*   r8   r   r   )r&   r   rh   r   )r   r   rh   r   )
rK   rw   rx   ry   rz   r   r1   r(   r   r~   r8   r*   r'   r   r     sM    $ %)4+!+3H+	.+RR	IR	"r*   r   c                  >    \ rS rSrSrSS jr    S	S jrS
S jrSrg)RewardWrapperi?  aH  Superclass of wrappers that can modify the returning reward from a step.

If you would like to apply a function to the reward that is returned by the base environment before
passing it to learning code, you can simply inherit from :class:`RewardWrapper` and overwrite the method
:meth:`reward` to implement that transformation.
c                .    [         R                  X5        g)zOConstructor for the Reward wrapper.

Args:
    env: Environment to be wrapped.
Nr   r   s     r'   r   RewardWrapper.__init__G  r   r*   c                h    U R                   R                  U5      u  p#pEnX R                  U5      XEU4$ )zGModifies the :attr:`env` :meth:`step` reward using :meth:`self.reward`.)r   r(   r   r   s          r'   r(   RewardWrapper.stepO  s4     <@88==;P8ZDKK/LLr*   c                    [         e)zReturns a modified environment ``reward``.

Args:
    reward: The :attr:`env` :meth:`step` reward

Returns:
    The modified `reward`
r"   )r%   r   s     r'   r   RewardWrapper.rewardV  r   r*   r8   Nr   rg   )r   r   rh   r   )	rK   rw   rx   ry   rz   r   r(   r   r~   r8   r*   r'   r   r   ?  s)    $MM	BM	"r*   r   c                  >    \ rS rSrSrSS jr    S	S jrS
S jrSrg)ActionWrapperib  u  Superclass of wrappers that can modify the action before :meth:`step`.

If you would like to apply a function to the action before passing it to the base environment,
you can simply inherit from :class:`ActionWrapper` and overwrite the method :meth:`action` to implement
that transformation. The transformation defined in that method must take values in the base environment’s
action space. However, its domain might differ from the original action space.
In that case, you need to specify the new action space of the wrapper by setting :attr:`action_space` in
the :meth:`__init__` method of your wrapper.

Among others, Gymnasium provides the action wrappers :class:`gymnasium.wrappers.ClipAction` and
:class:`gymnasium.wrappers.RescaleAction` for clipping and rescaling actions.
c                .    [         R                  X5        g)zOConstructor for the action wrapper.

Args:
    env: Environment to be wrapped.
Nr   r   s     r'   r   ActionWrapper.__init__p  r   r*   c                V    U R                   R                  U R                  U5      5      $ )z]Runs the :attr:`env` :meth:`env.step` using the modified ``action`` from :meth:`self.action`.)r   r(   r&   r$   s     r'   r(   ActionWrapper.stepx  s      xx}}T[[011r*   c                    [         e)zReturns a modified action before :meth:`step` is called.

Args:
    action: The original :meth:`step` actions

Returns:
    The modified actions
r"   r$   s     r'   r&   ActionWrapper.action~  r   r*   r8   Nr   )r&   r   rh   ri   )r&   r   rh   r   )	rK   rw   rx   ry   rz   r   r(   r&   r~   r8   r*   r'   r   r   b  s&    $2$2	B2	"r*   r   )rz   
__future__r   copyr   typingr   r   r   r   r	   numpynpr   r
   gymnasium.utilsr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r8   r*   r'   <module>r     s    ] "  F F    : @
)

)
m$B''7"
# BJ )*)*p
&'NNGW<=p
f)"'7!JK )"X "GGWgw>?  "F%"GG^WgEF %"r*   