太空侵略者

../../../_images/atari_space_invaders.gif

此环境是 雅达利 (Atari) 环境的一部分。请先阅读该页面以获取一般信息。

导入

from pettingzoo.atari import space_invaders_v2

动作 (Actions)

离散 (Discrete)

Parallel API

手动控制 (Manual Control)

智能体 (Agents)

agents= ['first_0', 'second_0']

智能体 (Agents)

2

动作形状 (Action Shape)

(1,)

动作值 (Action Values)

[0,5]

观测形状 (Observation Shape)

(210, 160, 3)

观测值 (Observation Values)

(0,255)

经典的雅达利游戏,但有两个由两名玩家控制的飞船,每名玩家都试图最大化自己的分数。

这个游戏具有合作性,玩家可以选择通过合作闯关来最大化得分。普通外星人的分数在 5 到 30 分之间,取决于它们出现的高度;而飞越屏幕顶部的飞船值 100 分。

然而,它也具有竞争性,当另一名玩家被外星人击中时,一名玩家会获得 200 分的奖励。因此,以某种方式破坏另一名玩家也是一种可能的策略。

生命次数在两艘飞船之间共享,即当任一飞船被击中 3 次时游戏结束。

太空侵略者官方手册

环境参数

一些环境参数是所有 雅达利 (Atari) 环境共有的,并在 基本 雅达利 (Atari) 文档中进行了描述。

太空侵略者特有的参数是:

space_invaders_v2.env(alternating_control=False, moving_shields=True,
zigzaging_bombs=False, fast_bomb=False, invisible_invaders=False)

alternating_control: 两名玩家中一次只能有一名玩家可以射击。如果你射击,你的对手就可以射击。然而,你不能永远囤积射击能力,最终控制权还是会转移给你的对手。

moving_shields: 护盾会来回移动,提供的保护不太可靠。

zigzaging_bombs: 入侵者的炸弹会来回移动,使其更难躲避。

fast_bomb: 炸弹速度更快,使其更难躲避。

invisible_invaders: 入侵者隐形,使其更难击中。

动作空间 (最小)

在任何给定的回合中,智能体可以从 6 个动作中选择一个。

动作

行为

0

无操作

1

射击

2

向上移动

3

向右移动

4

向左移动

5

向下移动

版本历史

  • v2:最小动作空间 (1.18.0)

  • v1:整个 API 的破坏性更改 (1.4.0)

  • v0:初始版本发布 (1.0.0)

用法

AEC

from pettingzoo.atari import space_invaders_v2

env = space_invaders_v2.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 space_invaders_v2

env = space_invaders_v2.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()

API

class pettingzoo.atari.space_invaders.space_invaders.raw_env(alternating_control: bool = False, moving_shields: bool = True, zigzaging_bombs: bool = False, fast_bomb: bool = False, invisible_invaders: bool = False, **kwargs: Any)[source]