强化学习环境 OpenAI Retro 的介绍及安装方式

使用 OpenAI Retro,这是一个使用 Libretro API 将电子游戏模拟器核心转到 Gym 环境的包装器

环境

这里 gym-retro 环境仅仅提供了游戏交互,但是没有提供游戏的 ROMS,直接创建游戏环境会报错,比如:

FileNotFoundError: Game not found: Airwolf-Nes. Did you make sure to import the ROM?

所以需要先下载 ROMS

推荐网址:

//www.atarimania.com/rom_collection_archive_atari_2600_roms.html

下载 Roms.rar 后解压缩,然后在终端运行:(这里的/xxx/xxx/ROMS是解压的地址)

python -m retro.import /xxx/xxx/ROMS

然后终端会提示载入成功,这里仅解压了一个文件作为尝试:

Importing SpaceInvaders-Atari2600
Imported 1 games

这里使用的是经典的雅达利游戏:太空侵略者

# 创建环境
env = retro.make(game='SpaceInvaders-Atari2600')

print("The size of our frame is: ", env.observation_space)
print("The action size is : ", env.action_space.n)

# 把动作维度变成 one-hot 向量
# possible_actions = [[1, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 0]...]
possible_actions = np.array(np.identity(env.action_space.n,dtype=int).tolist())

运行结果:

The size of our frame is:  Box(210, 160, 3)
The action size is :  8

这里我们可以看到,画面是 210*160,3 通道的 RGB 图片

动作维度是 8
截屏2020-07-05 下午4.12.28.png