Пример #1
0
    def __init__(self, width, height, mechanic, mechanic_args):

        self.env = MazeGame((width, height),
                            mechanic=mechanic,
                            mechanic_args=mechanic_args)

        self.observation_space = self.env.get_state().shape
        self.action_space = 4
Пример #2
0
    def __init__(self, width, height):
        opt = dict(algorithm="none", disable_target=True)
        self.env = MazeGame((width, height),
                            mechanic=NoMazeEnv.NoMazeMechanic,
                            mechanic_args=None,
                            options=opt)

        self.observation_space = self.env.get_state().shape
        self.action_space = 4
Пример #3
0
    def __init__(self, width, height, state_type, mechanic, mechanic_args):

        self.env = MazeGame((width, height), mechanic=mechanic, mechanic_args=mechanic_args)

        if state_type == "image":
            self.env.set_preprocess(dict(
                image=dict(),
                #resize=dict(size=(84, 84)),
                #grayscale=dict()
            ))

        self.observation_space = self.env.get_state().shape
        self.action_space = 4
Пример #4
0
class MazeEnv(gym.Env):
    metadata = {'render.modes': ['human']}
    id = "maze-v0"

    def __init__(self, width, height, state_type, mechanic, mechanic_args):

        self.env = MazeGame((width, height), mechanic=mechanic, mechanic_args=mechanic_args)

        if state_type == "image":
            self.env.set_preprocess(dict(
                image=dict(),
                #resize=dict(size=(84, 84)),
                #grayscale=dict()
            ))

        self.observation_space = self.env.get_state().shape
        self.action_space = 4

    def step(self, action):
        return self.env.step(action)

    def reset(self):
        return self.env.reset()

    def render(self, mode='human', close=False):
        if close:
            self.env.quit()
            return None

        return self.env.render()
Пример #5
0
    def __init__(self, width, height, state_type):
        opt = dict(algorithm="none", disable_target=True)
        self.env = MazeGame((width, height),
                            mechanic=NoMazeEnv.NoMazeMechanic,
                            mechanic_args=None,
                            options=opt)

        if state_type == "image":
            self.env.set_preprocess(
                dict(image=dict(),
                     #resize=dict(size=(84, 84)),
                     #grayscale=dict()
                     ))

        self.observation_space = self.env.get_state().shape
        self.action_space = 4
Пример #6
0
class MazeEnv(gym.Env):
    metadata = {'render.modes': ['human']}
    id = "maze-v0"

    def __init__(self, width, height, mechanic, mechanic_args):

        self.env = MazeGame((width, height),
                            mechanic=mechanic,
                            mechanic_args=mechanic_args)

        self.observation_space = self.env.get_state().shape
        self.action_space = 4

    def step(self, action, type):
        return self.env.step(action, type)

    def reset(self):
        return self.env.reset()

    def render(self, mode=0, close=False):
        if close:
            self.env.quit()
            return None

        return self.env.render(type=mode)
Пример #7
0
class NoMazeEnv(gym.Env):
    metadata = {'render.modes': ['human']}
    id = "NoMaze-%s-%sx%s-v0"

    class NoMazeMechanic(BaseMazeMechanic):
        def on_start(self):
            pass

        def on_update(self):
            pass

        def on_terminal(self):
            pass

    def __init__(self, width, height, state_type):
        opt = dict(algorithm="none", disable_target=True)
        self.env = MazeGame((width, height),
                            mechanic=NoMazeEnv.NoMazeMechanic,
                            mechanic_args=None,
                            options=opt)

        if state_type == "image":
            self.env.set_preprocess(
                dict(image=dict(),
                     #resize=dict(size=(84, 84)),
                     #grayscale=dict()
                     ))

        self.observation_space = self.env.get_state().shape
        self.action_space = 4

    def step(self, action):
        return self.env.step(action)

    def reset(self):
        return self.env.reset()

    def render(self, mode='human', close=False):
        if close:
            self.env.quit()
            return None

        return self.env.render()
Пример #8
0
class NoMazeEnv(gym.Env):
    metadata = {'render.modes': ['human']}
    id = "NoMaze-%s-%sx%s-v0"

    class NoMazeMechanic(BaseMazeMechanic):
        def on_start(self):
            pass

        def on_update(self):
            pass

        def on_terminal(self):
            pass

    def __init__(self, width, height):
        opt = dict(algorithm="none", disable_target=True)
        self.env = MazeGame((width, height),
                            mechanic=NoMazeEnv.NoMazeMechanic,
                            mechanic_args=None,
                            options=opt)

        self.observation_space = self.env.get_state().shape
        self.action_space = 4

    def step(self, action, type):
        return self.env.step(action, type)

    def reset(self):
        return self.env.reset()

    def render(self, mode=0, close=False):
        if close:
            self.env.quit()
            return None

        return self.env.render(type=mode)
Пример #9
0
if __name__ == "__main__":

    env = gym.make("Maze-11x11-NormalMaze-v0")

    while False:
        a = random.randint(0, 3)

        s, r, t, info = env.step(a)
        env.render()

        if t:
            env.reset()

    # Direct initialization
    m = MazeGame((32, 32),
                 mechanic=MazeGame.NormalMaze,
                 mechanic_args=dict(vision=3))
    path = list(reversed(m.maze_optimal_path[1]))

    fps = 0
    path.pop()

    while True:
        nx, ny = path.pop()
        px, py = m.player
        dx, dy = nx - px, ny - py

        if dx == 1:
            a = 3
        elif dx == -1:
            a = 2
Пример #10
0
if __name__ == "__main__":

    env = gym.make("Maze-Arr-11x11-NormalMaze-v0")

    while False:
        a = random.randint(0, 3)

        s, r, t, info = env.step(a)
        env.render()

        if t:
            env.reset()

    # Direct initialization
    m = MazeGame((32, 32),
                 mechanic=MazeGame.NormalMaze,
                 mechanic_args=dict(vision=3))
    path = list(reversed(m.maze_optimal_path[1]))

    m.set_preprocess(
        dict(image=dict(),
             #resize=dict(size=(84, 84)),
             #grayscale=dict()
             ))

    fps = 0
    path.pop()

    while True:
        nx, ny = path.pop()
        px, py = m.player