Exemplo n.º 1
0
 def __init__(self,
              size=2,
              discrete=True,
              partially_observable=False,
              episodic=True,
              deterministic=False):
     self.size = size
     self.terminal_state = size
     self.episodic = episodic
     self.partially_observable = partially_observable
     self.deterministic = deterministic
     self.n_max_offset = 1
     # (s_0, ..., s_N) + terminal state + offset
     self.n_dim_obs = self.size + 1 + self.n_max_offset
     self.observation_space = spaces.Box(
         low=-np.inf,
         high=np.inf,
         shape=(self.n_dim_obs, ),
         dtype=np.float32,
     )
     if discrete:
         self.action_space = spaces.Discrete(self.size)
     else:
         self.action_space = spaces.Box(
             low=-1.0,
             high=1.0,
             shape=(self.size, ),
             dtype=np.float32,
         )
Exemplo n.º 2
0
    def __init__(self,
                 game,
                 seed=None,
                 use_sdl=False,
                 n_last_screens=4,
                 frame_skip=4,
                 treat_life_lost_as_terminal=True,
                 crop_or_scale='scale',
                 max_start_nullops=30,
                 record_screen_dir=None):
        self.n_last_screens = n_last_screens
        self.treat_life_lost_as_terminal = treat_life_lost_as_terminal
        self.crop_or_scale = crop_or_scale
        self.max_start_nullops = max_start_nullops

        # atari_py is used only to provide rom files. atari_py has its own
        # ale_python_interface, but it is obsolete.
        game_path = atari_py.get_game_path(game)

        ale = ALEInterface()
        if seed is not None:
            assert seed >= 0 and seed < 2 ** 16, \
                "ALE's random seed must be represented by unsigned int"
        else:
            # Use numpy's random state
            seed = np.random.randint(0, 2**16)
        ale.setInt(b'random_seed', seed)
        ale.setFloat(b'repeat_action_probability', 0.0)
        ale.setBool(b'color_averaging', False)
        if record_screen_dir is not None:
            ale.setString(b'record_screen_dir',
                          str.encode(str(record_screen_dir)))
        self.frame_skip = frame_skip
        if use_sdl:
            if 'DISPLAY' not in os.environ:
                raise RuntimeError(
                    'Please set DISPLAY environment variable for use_sdl=True')
            # SDL settings below are from the ALE python example
            if sys.platform == 'darwin':
                import pygame
                pygame.init()
                ale.setBool(b'sound', False)  # Sound doesn't work on OSX
            elif sys.platform.startswith('linux'):
                ale.setBool(b'sound', True)
            ale.setBool(b'display_screen', True)

        ale.loadROM(str.encode(str(game_path)))

        assert ale.getFrameNumber() == 0

        self.ale = ale
        self.legal_actions = ale.getMinimalActionSet()
        self.initialize()

        self.action_space = spaces.Discrete(len(self.legal_actions))
        one_screen_observation_space = spaces.Box(low=0,
                                                  high=255,
                                                  shape=(84, 84))
        self.observation_space = spaces.Tuple([one_screen_observation_space] *
                                              n_last_screens)
Exemplo n.º 3
0
    def __init__(self,
                 scenario="./config/basic.wad",
                 dmap="map01",
                 episode_len=200,
                 window=False):
        self.game = DoomGame()
        self.game.set_doom_scenario_path(scenario)
        self.game.set_doom_map(dmap)
        self.game.set_screen_resolution(ScreenResolution.RES_640X480)
        self.game.set_screen_format(ScreenFormat.RGB24)
        self.game.set_depth_buffer_enabled(True)
        self.game.set_labels_buffer_enabled(True)
        self.game.set_automap_buffer_enabled(True)
        self.game.set_render_hud(False)
        self.game.set_render_minimal_hud(False)  # If hud is enabled
        self.game.set_render_crosshair(False)
        self.game.set_render_weapon(True)
        self.game.set_render_decals(
            False)  # Bullet holes and blood on the walls
        self.game.set_render_particles(False)
        self.game.set_render_effects_sprites(False)  # Smoke and blood
        self.game.set_render_messages(False)  # In-game messages
        self.game.set_render_corpses(False)
        self.game.set_render_screen_flashes(
            True)  # Effect upon taking damage or picking up items
        self.game.add_available_button(Button.MOVE_LEFT)
        self.game.add_available_button(Button.MOVE_RIGHT)
        self.game.add_available_button(Button.ATTACK)
        self.game.add_available_game_variable(GameVariable.AMMO2)
        self.game.set_episode_timeout(episode_len)
        self.game.set_episode_start_time(10)
        self.game.set_window_visible(window)
        self.game.set_sound_enabled(True)
        self.game.set_living_reward(-1)
        self.game.set_mode(Mode.PLAYER)
        self.game.init()
        self.game.new_episode()
        self._reward = 0
        self.frame = 0
        self.legal_actions = [[True, False, False], [False, True, False],
                              [False, False, True]]

        self.action_space = spaces.Discrete(len(self.legal_actions))

        one_screen_observation_space = spaces.Box(low=0,
                                                  high=255,
                                                  shape=(80, 80))
        n_last_screens = 4
        self.observation_space = spaces.Tuple([one_screen_observation_space] *
                                              n_last_screens)

        self.episode_len = episode_len
        obs = resize(rgb2gray(self.game.get_state().screen_buffer), (80, 80))
        obs = obs[np.newaxis, :, :]
        self.current_screen = obs
Exemplo n.º 4
0
 def __init__(self,
              size=2,
              discrete=True,
              partially_observable=False,
              episodic=True,
              deterministic=False):
     self.size = size
     self.episodic = episodic
     self.partially_observable = partially_observable
     self.deterministic = deterministic
     self.n_max_offset = 1
     self.n_dim_obs = self.size + 2 + self.n_max_offset
     self.observation_space = spaces.Box(
         low=np.asarray([-np.inf] * self.n_dim_obs, dtype=np.float32),
         high=np.asarray([np.inf] * self.n_dim_obs, dtype=np.float32))
     if discrete:
         self.action_space = spaces.Discrete(self.size)
     else:
         self.action_space = spaces.Box(
             low=-np.ones(self.size, dtype=np.float32),
             high=np.ones(self.size, dtype=np.float32))