在OpenAI复古游戏中离散Atari游戏中的动作空间?

时间:2018-12-11 16:06:09

标签: openai-gym

我目前正在使用Space Invaders在PyTorch的DQN代理中工作,但是我有一些问题: -Retro的动作系统是一个数组,每个按钮按下1。 -但是,有太多无用的组合,我们只需要(对于太空入侵者):左,右,射击,[左射击],[右射击]。

我修改了Sonic Action离散器:

class SpaceInvadersDiscretizer(gym.ActionWrapper):
    """
    Wrap a gym-retro environment and make it use discrete
    actions for the Space Invaders game.
    """
    def __init__(self, env):
        super(SpaceInvadersDiscretizer, self).__init__(env)
        buttons = ["BUTTON", "LEFT", "RIGHT"]
        actions = [["BUTTON"], ['LEFT'], ['RIGHT'], ["BUTTON","LEFT"], ["BUTTON", "RIGHT"]]
        self._actions = []
        """
        What we do in this loop:
        For each action in actions
            - Create an array of 3 False (3 = nb of buttons)
            For each button in action: (for instance ['LEFT']) we need to make that left button index = True
                - Then the button index = LEFT = True
            In fact at the end we will have an array where each array is an action and each elements True of this array
            are the buttons clicked.
        """
        for action in actions:
            arr = np.array([False] * 3)
            for button in action:
                arr[buttons.index(button)] = True
            self._actions.append(arr)
        self.action_space = gym.spaces.Discrete(len(self._actions))

    def action(self, a): # pylint: disable=W0221
        return self._actions[a].copy()

现在我有5种可能的动作:

  • 0:射击(有效)
  • 1:向左(不起作用)
  • 2:正确(无效)
  • 3:向左射击(不向左射击)
  • 4:正确并射击(拍摄效果不正确)

有人知道为什么吗? 并存在一种更好的复古处理动作的方法吗?

谢谢!

0 个答案:

没有答案
相关问题