コード例 #1
0
 def __init__(self, env, randomize):
     super(MazeEnvImage, self).__init__(env)
     self.randomize = randomize
     self.maze_size = self.env.maze.shape
     channels = 3
     self.observation_space = gym.spaces.Box(0,
                                             255,
                                             [*self.maze_size, channels],
                                             dtype=np.uint8)
     if not randomize:
         random.seed(self.FIXED_SEED)
         self.env = mazenv.Env(mazenv.prim(self.maze_size))
コード例 #2
0
def load_maze(maze_name, maze_size=(8,8)):
    """
    Load maze environment with given :maze_name. If the maze does not exist as a
    file, create a new one.
    """
    maze_filename = os.path.join(MAZE_FOLDER,f"{maze_name}.txt")
    if not os.path.exists(maze_filename):
        print(f"Creating new maze for {maze_name}")

        maze = mazenv.prim(maze_size)
        with open(maze_filename, 'w+') as f:
            print(maze)
            f.write(str(maze))
    else:
        print(f"Loaded maze {maze_name} from file")
        with open(maze_filename, 'r') as f:
            maze = mazenv.parse_2d_maze(f.read())
        print(maze)
    env = mazenv.Env(maze)
    return env
コード例 #3
0
ファイル: envs.py プロジェクト: mandrecki/predictive-learners
    def __init__(self, env_id, seed, max_episode_length=1000):
        super(GameEnv, self).__init__()
        extra_args = ENV_GAMES_ARGS.get(env_id, {})
        self.env_id = env_id
        if env_id == "TetrisA-v2":
            self._env = JoypadSpace(gym_tetris.make(env_id, **extra_args), SIMPLE_MOVEMENT)
        elif "ple" in env_id:
            self._env = gym_ple.make(env_id, **extra_args)
        elif "MiniGrid" in env_id:
            # self._env = AbsoluteActionGrid(FullyObsWrapper(gym.make(env_id)))
            self._env = AbsoluteActionGrid(RGBImgObsWrapper(gym.make(env_id)))
        elif "Sokoban" in env_id:
            self._env = TinySokoban(gym.make(env_id, **extra_args))
        elif "MazeEnv" in env_id:
            self._env = MazeEnvImage(mazenv.Env(mazenv.prim((8, 8))), randomize=True)
        else:
            self._env = gym.make(env_id, **extra_args)

        self._env.seed(seed)
        self.action_repeat = GAME_ENVS_ACTION_REPEATS.get(env_id, 1)
        self.max_episode_length = max_episode_length * self.action_repeat
        self.t = 0
コード例 #4
0
 def reset(self):
     if self.randomize:
         self.env = mazenv.Env(mazenv.prim(self.maze_size))
     obs = self.env.reset()
     return self.observation(obs)
コード例 #5
0
 def seed(self, seed=None):
     if self.randomize:
         random.seed(seed)
         self.env = mazenv.Env(mazenv.prim(self.maze_size))