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)
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()
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()
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)
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 elif dy == 1: a = 0 elif dy == -1: a = 1 else: Exception("error") m.render() data = m.step(a) m.render() if m.terminal: path = list(reversed(m.maze_optimal_path[1])) path.pop()