Pong¶

此环境是 Atari 环境 的一部分。请先阅读该页面以获取一般信息。
导入 |
|
---|---|
动作 |
离散 |
Parallel API |
是 |
手动控制 |
否 |
智能体 |
|
智能体 |
2 |
动作形状 |
(1,) |
动作值 |
[0,5] |
观察形状 |
(210, 160, 3) |
观察值 |
(0,255) |
经典的两人竞技计时游戏。
将球打过对手。
得分会给你 +1 奖励,给你的对手 -1 奖励。
发球有计时:如果玩家在接到球后 2 秒内没有发球,他们将受到 -1 分的惩罚,并且计时器会重置。这可以防止一个玩家无限期地拖延比赛,但同时也意味着它不再是一个纯粹的零和游戏。
环境参数¶
一些环境参数是所有 Atari 环境通用的,并在基础 Atari 文档中进行了描述。
Pong 特有的参数是
pong_v3.env(num_players=2)
num_players
: 玩家数量(必须是 2 或 4)
动作空间(最小)¶
在任何给定回合中,智能体可以从 6 个动作中选择一个。
动作 |
行为 |
---|---|
0 |
无操作 |
1 |
开火 |
2 |
向右移动 |
3 |
向左移动 |
4 |
向右开火 |
5 |
向左开火 |
版本历史¶
v3:最小动作空间 (1.18.0)
v2:无动作计时器 (1.9.0)
v1:整个 API 的破坏性更改 (1.4.0)
v0:初始版本发布 (1.0.0)
用法¶
AEC¶
from pettingzoo.atari import pong_v3
env = pong_v3.env(render_mode="human")
env.reset(seed=42)
for agent in env.agent_iter():
observation, reward, termination, truncation, info = env.last()
if termination or truncation:
action = None
else:
# this is where you would insert your policy
action = env.action_space(agent).sample()
env.step(action)
env.close()
Parallel¶
from pettingzoo.atari import pong_v3
env = pong_v3.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()