Butterfly¶
Butterfly 环境是由 Farama 创建的具有挑战性的场景,使用 Pygame 和可视化 Atari 空间。
所有环境都需要高度的协调性,并需要学习涌现行为才能达到最优策略。因此,这些环境目前学习起来非常具有挑战性。
环境可以通过其各自文档中指定的参数进行高度配置:合作 Pong,骑士弓箭手僵尸,活塞球。
安装¶
这组环境的特有依赖项可以通过以下方式安装
pip install 'pettingzoo[butterfly]'
用法¶
要启动一个包含随机智能体的活塞球环境
from pettingzoo.butterfly import pistonball_v6
env = pistonball_v6.parallel_env(render_mode="human")
observations, infos = env.reset()
while env.agents:
# this is where you would insert your policy
actions = {agent: env.action_space(agent).sample() for agent in env.agents}
observations, rewards, terminations, truncations, infos = env.step(actions)
env.close()
要启动一个带有交互式用户输入的骑士弓箭手僵尸环境(参见manual_policy.py)
import pygame
from pettingzoo.butterfly import knights_archers_zombies_v10
env = knights_archers_zombies_v10.env(render_mode="human")
env.reset(seed=42)
manual_policy = knights_archers_zombies_v10.ManualPolicy(env)
for agent in env.agent_iter():
observation, reward, termination, truncation, info = env.last()
if termination or truncation:
action = None
elif agent == manual_policy.agent:
# get user input (controls are WASD and space)
action = manual_policy(observation, agent)
else:
# this is where you would insert your policy (for non-player agents)
action = env.action_space(agent).sample()
env.step(action)
env.close()