Source code for pettingzoo.utils.wrappers.base
from __future__ import annotations
from typing import Any
import gymnasium.spaces
import numpy as np
from pettingzoo.utils.env import ActionType, AECEnv, AgentID, ObsType
[docs]
class BaseWrapper(AECEnv[AgentID, ObsType, ActionType]):
"""Creates a wrapper around `env` parameter.
All AECEnv wrappers should inherit from this base class
"""
def __init__(self, env: AECEnv[AgentID, ObsType, ActionType]):
super().__init__()
self.env = env
def __getattr__(self, name: str) -> Any:
"""Returns an attribute with ``name``, unless ``name`` starts with an underscore."""
if name.startswith("_") and name != "_cumulative_rewards":
raise AttributeError(f"accessing private attribute '{name}' is prohibited")
return getattr(self.env, name)
@property
def unwrapped(self) -> AECEnv:
return self.env.unwrapped
def close(self) -> None:
self.env.close()
def render(self) -> None | np.ndarray | str | list:
return self.env.render()
def reset(self, seed: int | None = None, options: dict | None = None):
self.env.reset(seed=seed, options=options)
def observe(self, agent: AgentID) -> ObsType | None:
return self.env.observe(agent)
def state(self) -> np.ndarray:
return self.env.state()
def step(self, action: ActionType) -> None:
self.env.step(action)
def observation_space(self, agent: AgentID) -> gymnasium.spaces.Space:
return self.env.observation_space(agent)
def action_space(self, agent: AgentID) -> gymnasium.spaces.Space:
return self.env.action_space(agent)
def __str__(self) -> str:
"""Returns a name which looks like: "max_observation<space_invaders_v1>"."""
return f"{type(self).__name__}<{str(self.env)}>"