反。开放式健身房
gym-contra的Python项目详细描述
康特拉健身馆
一个健身房环境。在任天堂娱乐系统上使用nes-py emulator。
安装
contra的首选安装来自pip:
pip install gym-contra
用法
Python
在创建环境之前,必须导入contranv。这是因为健身房环境是在运行时注册的。默认情况下,contarenv使用256个离散操作的完整nes操作空间。为了解决这个问题,contranev.actions为nes_py.wrappers.joypadspace包装器提供了三个操作列表(仅右操作、简单操作和复杂操作)。请参阅Contra/actions.py以了解这三个列表中每一个列表中的法律行为的详细信息。
fromnes_py.wrappersimportJoypadSpaceimportgymfromContra.actionsimportSIMPLE_MOVEMENT,COMPLEX_MOVEMENT,RIGHT_ONLYenv=gym.make('Contra-v0')env=JoypadSpace(env,RIGHT_ONLY)print("actions",env.action_space)print("observation_space ",env.observation_space.shape[0])done=Falseenv.reset()forstepinrange(5000):ifdone:print("Over")breakstate,reward,done,info=env.step(env.action_space.sample())env.render()env.close()
NOTE: ContraEnv.make is just an alias to gym.make for convenience.
NOTE: remove calls to render in training code for a nontrivial speedup.
命令行
准备写入请稍候
NOTE: by default,-m is set to human.
环境
这些环境允许在游戏中进行3次尝试(生命)。这些环境只向代理发送可奖励的游戏帧;不向代理发送剪切场景、加载屏幕等,代理也不能在这些情况下执行操作。如果剪切场景无法通过黑客攻击nes的ram跳过,则环境将锁定python进程,直到模拟器为下一个操作做好准备。
步骤
Info about the rewards and info returned by the step method.
奖励功能
奖励函数假设游戏的目标是尽可能向右移动(增加代理的x值),尽可能快,而不死亡。为了模拟这个游戏,三个独立的变量组成奖励:
- V:状态间代理X值的差异
- 在这种情况下,这是给定步骤的瞬时速度
- V=x1至x0
- x0是步骤之前的x位置
- x1是步骤后的x位置
- 向右移动v>;0
- 向左移动v<;0
- 不移动v=0
- D:对在某州死亡的代理人处以死刑
- 这一刑罚鼓励代理人避免死亡
- 活的d=0
- 死亡d=-15
- B:如果特工打败了老板
- 这个改写将鼓励代理人尽可能击败老板
- 无败0
- 战败30
所以奖励函数是:
R=V+D+B
Note:The reward is clipped into the range (-15, 15).
信息字典
step方法返回的信息字典包含以下键:
life=self._life,dead=self._is_dead,done=self._get_done(),score=self._score(),status=self._player_state,x_pos=self._x_position,y_pos=self._y_position,
Key | Type | Description |
---|---|---|
life | int | The number of lives left, i.e., {3, 2, 1} |
dead | Bool | Get The palyer is dead |
done | Bool | Get the game is game over |
score | int | Get the player's score |
status | Bool | Alive Status (00 - Dead, 01 - Alive, 02 - Dying) |
x_pos | int | Player's x position in the stage (from the left) |
y_pos | int | Player's y position in the stage (from the bottom) |