from pettingzoo.butterfly import pistonball_v4
env = pistonball_v4.env()
env.reset()
for agent in env.agent_iter():
observation, reward, done, info = env.last()
action = policy(observation, agent)
env.step(action)
parallel_env = pistonball_v4.parallel_env()
observations = parallel_env.reset()
max_cycles = 500
for step in range(max_cycles):
actions = {agent: policy(observations[agent], agent) for agent in parallel_env.agents}
observations, rewards, dones, infos = parallel_env.step(actions)
Attributes: agents
, num_agents
, possible_agents
, max_num_agents
, observation_spaces
, action_spaces
Methods: render(mode='human')
, seed(seed=None)
, close()
, observation_space(agent)
, action_space(agent)
step(actions)
: receives a dictionary of actions keyed by the agent name.
Returns the observation dictionary, reward dictionary, done dictionary, and info dictionary,
where each dictionary is keyed by the agent.
reset()
: resets the environment and returns a dictionary of observations (keyed by the agent name)
Often, you want to be able to play before trying to learn it to get a better feel for it. Some of our games directly support this:
from pettingzoo.butterfly import prison_v3
prison_v3.manual_control(<environment parameters>)
You can also easily get a quick impression of them by watching a random policy control all the actions:
from pettingzoo.utils import random_demo
random_demo(env, render=True, episodes=1)