-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom_agent.py
30 lines (21 loc) · 940 Bytes
/
random_agent.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import gymnasium
from gymnasium import spaces
from pettingzoo.utils import BaseWrapper
from pettingzoo.utils.env import AgentID, ObsType
class CustomWrapper(BaseWrapper):
"""
An example of a custom wrapper that flattens the symbolic vector state of the environment.
Wrappers are useful to do state pre-processing (e.g. feature engineering) that does not need to be learned by the agent.
"""
def observation_space(self, agent: AgentID) -> gymnasium.spaces.Space:
return spaces.flatten_space(super().observation_space(agent))
def observe(self, agent: AgentID) -> ObsType | None:
obs = super().observe(agent)
flat_obs = obs.flatten()
return flat_obs
class CustomPredictFunction:
"""A random archer agent."""
def __init__(self, env):
self.env = env
def __call__(self, observation, agent, *args, **kwargs):
return self.env.action_space(agent).sample()