本文整理汇总了Python中doom_py.DoomGame.set_doom_map方法的典型用法代码示例。如果您正苦于以下问题:Python DoomGame.set_doom_map方法的具体用法?Python DoomGame.set_doom_map怎么用?Python DoomGame.set_doom_map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类doom_py.DoomGame
的用法示例。
在下文中一共展示了DoomGame.set_doom_map方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DoomPredictPositionEnv
# 需要导入模块: from doom_py import DoomGame [as 别名]
# 或者: from doom_py.DoomGame import set_doom_map [as 别名]
class DoomPredictPositionEnv(doom_env.DoomEnv):
"""
------------ Training Mission 7 - Predict Position ------------
This map is designed to train you on using a rocket launcher.
It is a rectangular map with a monster on the opposite side. You need
to use your rocket launcher to kill it. The rocket adds a delay between
the moment it is fired and the moment it reaches the other side of the room.
You need to predict the position of the monster to kill it.
Allowed actions:
[0] - ATTACK - Shoot weapon - Values 0 or 1
[13] - TURN_RIGHT - Turn right - Values 0 or 1
[14] - TURN_LEFT - Turn left - Values 0 or 1
Note: see controls.md for details
Rewards:
+ 1 - Killing the monster
-0.0001 - Several times per second - Kill the monster faster!
Goal: 0.5 point
Kill the monster
Hint: Missile launcher takes longer to load. You must wait a good second after the game starts
before trying to fire it.
Ends when:
- Monster is dead
- Out of missile (you only have one)
- Timeout (20 seconds - 700 frames)
-----------------------------------------------------
"""
def __init__(self):
package_directory = os.path.dirname(os.path.abspath(__file__))
self.loader = Loader()
self.game = DoomGame()
self.game.load_config(os.path.join(package_directory, 'assets/predict_position.cfg'))
self.game.set_vizdoom_path(self.loader.get_vizdoom_path())
self.game.set_doom_game_path(self.loader.get_freedoom_path())
self.game.set_doom_scenario_path(self.loader.get_scenario_path('predict_position.wad'))
self.game.set_doom_map('map01')
self.screen_height = 480 # Must match .cfg file
self.screen_width = 640 # Must match .cfg file
self.game.set_window_visible(False)
self.viewer = None
self.game.init()
self.game.new_episode()
self._seed()
def _seed(self, seed=None):
np_random, seed1 = seeding.np_random(seed)
# Derive a random seed.
seed2 = seeding.hash_seed(seed1 + 1) % 2**32
self.game.set_seed(seed2)
# 3 allowed actions [0, 13, 14] (must match .cfg file)
self.action_space = spaces.HighLow(np.matrix([[0, 1, 0]] * 3), np_random=np_random)
self.observation_space = spaces.Box(low=0, high=255, shape=(self.screen_height, self.screen_width, 3), np_random=np_random)
return [seed1, seed2]
示例2: DoomBasicEnv
# 需要导入模块: from doom_py import DoomGame [as 别名]
# 或者: from doom_py.DoomGame import set_doom_map [as 别名]
class DoomBasicEnv(doom_env.DoomEnv):
"""
------------ Training Mission 1 - Basic ------------
This map is rectangular with gray walls, ceiling and floor.
You are spawned in the center of the longer wall, and a red
circular monster is spawned randomly on the opposite wall.
You need to kill the monster (one bullet is enough).
Allowed actions:
[0] - ATTACK - Shoot weapon - Values 0 or 1
[9] - MOVE_RIGHT - Move to the right - Values 0 or 1
[10] - MOVE_LEFT - Move to the left - Values 0 or 1
Note: see controls.md for details
Rewards:
+101 - Killing the monster
- 5 - Missing a shot
- 1 - Several times per second - Kill the monster faster!
Goal: 10 points
Kill the monster in 3 secs with 1 shot
Ends when:
- Monster is dead
- Player is dead
- Timeout (10 seconds - 350 frames)
-----------------------------------------------------
"""
def __init__(self):
super(DoomBasicEnv, self).__init__()
package_directory = os.path.dirname(os.path.abspath(__file__))
self.loader = Loader()
self.game = DoomGame()
self.game.load_config(os.path.join(package_directory, 'assets/basic.cfg'))
self.game.set_vizdoom_path(self.loader.get_vizdoom_path())
self.game.set_doom_game_path(self.loader.get_freedoom_path())
self.game.set_doom_scenario_path(self.loader.get_scenario_path('basic.wad'))
self.game.set_doom_map('map01')
self.screen_height = 480 # Must match .cfg file
self.screen_width = 640 # Must match .cfg file
self.game.set_window_visible(False)
self.viewer = None
self.game.init()
self.game.new_episode()
self._seed()
def _seed(self, seed=None):
np_random, seed1 = seeding.np_random(seed)
# Derive a random seed.
seed2 = seeding.hash_seed(seed1 + 1) % 2**32
self.game.set_seed(seed2)
# 3 allowed actions [0, 9, 10] (must match .cfg file)
self.action_space = spaces.HighLow(np.matrix([[0, 1, 0]] * 3), np_random=np_random)
self.observation_space = spaces.Box(low=0, high=255, shape=(self.screen_height, self.screen_width, 3), np_random=np_random)
return [seed1, seed2]
示例3: DoomHealthGatheringEnv
# 需要导入模块: from doom_py import DoomGame [as 别名]
# 或者: from doom_py.DoomGame import set_doom_map [as 别名]
class DoomHealthGatheringEnv(doom_env.DoomEnv):
"""
------------ Training Mission 5 - Health Gathering ------------
This map is a guide on how to survive by collecting health packs.
It is a rectangle with green, acidic floor which hurts the player
periodically. There are also medkits spread around the map, and
additional kits will spawn at interval.
Allowed actions:
[12] - MOVE_FORWARD - Move forward - Values 0 or 1
[13] - TURN_RIGHT - Turn right - Values 0 or 1
[14] - TURN_LEFT - Turn left - Values 0 or 1
Note: see controls.md for details
Rewards:
+ 1 - Several times per second - Survive as long as possible
-100 - Death penalty
Goal: 1000 points
Stay alive long enough to reach 1,000 points (~ 30 secs)
Ends when:
- Player is dead
- Timeout (60 seconds - 2,100 frames)
-----------------------------------------------------
"""
def __init__(self):
super(DoomHealthGatheringEnv, self).__init__()
package_directory = os.path.dirname(os.path.abspath(__file__))
self.loader = Loader()
self.game = DoomGame()
self.game.load_config(os.path.join(package_directory, 'assets/health_gathering.cfg'))
self.game.set_vizdoom_path(self.loader.get_vizdoom_path())
self.game.set_doom_game_path(self.loader.get_freedoom_path())
self.game.set_doom_scenario_path(self.loader.get_scenario_path('health_gathering.wad'))
self.game.set_doom_map('map01')
self.screen_height = 480 # Must match .cfg file
self.screen_width = 640 # Must match .cfg file
self.game.set_window_visible(False)
self.viewer = None
self.game.init()
self.game.new_episode()
self._seed()
def _seed(self, seed=None):
np_random, seed1 = seeding.np_random(seed)
# Derive a random seed.
seed2 = seeding.hash_seed(seed1 + 1) % 2**32
self.game.set_seed(seed2)
# 3 allowed actions [12, 13, 14] (must match .cfg file)
self.action_space = spaces.HighLow(np.matrix([[0, 1, 0]] * 3), np_random=np_random)
self.observation_space = spaces.Box(low=0, high=255, shape=(self.screen_height, self.screen_width, 3), np_random=np_random)
return [seed1, seed2]
示例4: DoomTakeCoverEnv
# 需要导入模块: from doom_py import DoomGame [as 别名]
# 或者: from doom_py.DoomGame import set_doom_map [as 别名]
class DoomTakeCoverEnv(doom_env.DoomEnv):
"""
------------ Training Mission 8 - Take Cover ------------
This map is to train you on the damage of incoming missiles.
It is a rectangular map with monsters firing missiles and fireballs
at you. You need to survive as long as possible.
Allowed actions:
[9] - MOVE_RIGHT - Move to the right - Values 0 or 1
[10] - MOVE_LEFT - Move to the left - Values 0 or 1
Note: see controls.md for details
Rewards:
+ 1 - Several times per second - Survive as long as possible
Goal: 750 points
Survive for ~ 20 seconds
Ends when:
- Player is dead (one or two fireballs should be enough to kill you)
- Timeout (60 seconds - 2,100 frames)
-----------------------------------------------------
"""
def __init__(self):
super(DoomTakeCoverEnv, self).__init__()
package_directory = os.path.dirname(os.path.abspath(__file__))
self.loader = Loader()
self.game = DoomGame()
self.game.load_config(os.path.join(package_directory, 'assets/take_cover.cfg'))
self.game.set_vizdoom_path(self.loader.get_vizdoom_path())
self.game.set_doom_game_path(self.loader.get_freedoom_path())
self.game.set_doom_scenario_path(self.loader.get_scenario_path('take_cover.wad'))
self.game.set_doom_map('map01')
self.screen_height = 480 # Must match .cfg file
self.screen_width = 640 # Must match .cfg file
self.game.set_window_visible(False)
self.viewer = None
self.game.init()
self.game.new_episode()
self._seed()
def _seed(self, seed=None):
np_random, seed1 = seeding.np_random(seed)
# Derive a random seed.
seed2 = seeding.hash_seed(seed1 + 1) % 2**32
self.game.set_seed(seed2)
# 2 allowed actions [9, 10] (must match .cfg file)
self.action_space = spaces.HighLow(np.matrix([[0, 1, 0]] * 2), np_random=np_random)
self.observation_space = spaces.Box(low=0, high=255, shape=(self.screen_height, self.screen_width, 3), np_random=np_random)
return [seed1, seed2]
示例5: DoomEnv
# 需要导入模块: from doom_py import DoomGame [as 别名]
# 或者: from doom_py.DoomGame import set_doom_map [as 别名]
class DoomEnv(gym.Env, utils.EzPickle):
metadata = {'render.modes': ['human', 'rgb_array'], 'video.frames_per_second': 35}
def __init__(self, level):
utils.EzPickle.__init__(self)
self.previous_level = -1
self.level = level
self.game = DoomGame()
self.loader = Loader()
self.doom_dir = os.path.dirname(os.path.abspath(__file__))
self.mode = 'fast' # 'human', 'fast' or 'normal'
self.no_render = False # To disable double rendering in human mode
self.viewer = None
self.is_initialized = False # Indicates that reset() has been called
self.curr_seed = 0
self.action_space = spaces.HighLow(
np.matrix([[0, 1, 0]] * 38 + [[-10, 10, 0]] * 2 + [[-100, 100, 0]] * 3, dtype=np.int8))
self.allowed_actions = list(range(NUM_ACTIONS))
self._seed()
self._configure()
def _configure(self, screen_resolution=ScreenResolution.RES_640X480):
# Often agents end up downsampling the observations. Configuring Doom to
# return a smaller image yields significant (~10x) speedups
if screen_resolution == ScreenResolution.RES_640X480:
self.screen_height = 480
self.screen_width = 640
self.screen_resolution = ScreenResolution.RES_640X480
elif screen_resolution == ScreenResolution.RES_160X120:
self.screen_height = 120
self.screen_width = 160
self.screen_resolution = ScreenResolution.RES_160X120
self.observation_space = spaces.Box(low=0, high=255, shape=(self.screen_height, self.screen_width, 3))
def _load_level(self):
# Closing if is_initialized
if self.is_initialized:
self.is_initialized = False
self.game.close()
self.game = DoomGame()
# Loading Paths
if not self.is_initialized:
self.game.set_vizdoom_path(self.loader.get_vizdoom_path())
self.game.set_doom_game_path(self.loader.get_freedoom_path())
# Common settings
self._closed = False
self.game.load_config(os.path.join(self.doom_dir, 'assets/%s' % DOOM_SETTINGS[self.level][CONFIG]))
self.game.set_doom_scenario_path(self.loader.get_scenario_path(DOOM_SETTINGS[self.level][SCENARIO]))
if DOOM_SETTINGS[self.level][MAP] != '':
self.game.set_doom_map(DOOM_SETTINGS[self.level][MAP])
self.game.set_doom_skill(DOOM_SETTINGS[self.level][DIFFICULTY])
self.previous_level = self.level
self.allowed_actions = DOOM_SETTINGS[self.level][ACTIONS]
self.game.set_screen_resolution(self.screen_resolution)
# Algo mode
if 'human' != self.mode:
self.game.set_window_visible(False)
self.game.set_mode(Mode.PLAYER)
self.no_render = False
self.game.init()
self._start_episode()
self.is_initialized = True
return self.game.get_state().image_buffer.copy()
# Human mode
else:
self.game.add_game_args('+freelook 1')
self.game.set_window_visible(True)
self.game.set_mode(Mode.SPECTATOR)
self.no_render = True
self.game.init()
self._start_episode()
self.is_initialized = True
self._play_human_mode()
return np.zeros(shape=self.observation_space.shape, dtype=np.uint8)
def _start_episode(self):
if self.curr_seed > 0:
self.game.set_seed(self.curr_seed)
self.curr_seed = 0
self.game.new_episode()
return
def _play_human_mode(self):
while not self.game.is_episode_finished():
self.game.advance_action()
state = self.game.get_state()
total_reward = self.game.get_total_reward()
info = self._get_game_variables(state.game_variables)
info["TOTAL_REWARD"] = round(total_reward, 4)
print('===============================')
print('State: #' + str(state.number))
print('Action: \t' + str(self.game.get_last_action()) + '\t (=> only allowed actions)')
print('Reward: \t' + str(self.game.get_last_reward()))
print('Total Reward: \t' + str(total_reward))
print('Variables: \n' + str(info))
#.........这里部分代码省略.........
示例6: DoomEnv
# 需要导入模块: from doom_py import DoomGame [as 别名]
# 或者: from doom_py.DoomGame import set_doom_map [as 别名]
class DoomEnv(gym.Env):
metadata = {'render.modes': ['human', 'rgb_array'], 'video.frames_per_second': 35}
def __init__(self, level):
self.previous_level = -1
self.level = level
self.game = DoomGame()
self.loader = Loader()
self.doom_dir = os.path.dirname(os.path.abspath(__file__))
self._mode = 'algo' # 'algo' or 'human'
self.no_render = False # To disable double rendering in human mode
self.viewer = None
self.is_initialized = False # Indicates that reset() has been called
self.curr_seed = 0
self.lock = (DoomLock()).get_lock()
self.action_space = spaces.MultiDiscrete([[0, 1]] * 38 + [[-10, 10]] * 2 + [[-100, 100]] * 3)
self.allowed_actions = list(range(NUM_ACTIONS))
self.screen_height = 480
self.screen_width = 640
self.screen_resolution = ScreenResolution.RES_640X480
self.observation_space = spaces.Box(low=0, high=255, shape=(self.screen_height, self.screen_width, 3))
self._seed()
self._configure()
def _configure(self, lock=None, **kwargs):
if 'screen_resolution' in kwargs:
logger.warn('Deprecated - Screen resolution must now be set using a wrapper. See documentation for details.')
# Multiprocessing lock
if lock is not None:
self.lock = lock
def _load_level(self):
# Closing if is_initialized
if self.is_initialized:
self.is_initialized = False
self.game.close()
self.game = DoomGame()
# Customizing level
if getattr(self, '_customize_game', None) is not None and callable(self._customize_game):
self.level = -1
self._customize_game()
else:
# Loading Paths
if not self.is_initialized:
self.game.set_vizdoom_path(self.loader.get_vizdoom_path())
self.game.set_doom_game_path(self.loader.get_freedoom_path())
# Common settings
self.game.load_config(os.path.join(self.doom_dir, 'assets/%s' % DOOM_SETTINGS[self.level][CONFIG]))
self.game.set_doom_scenario_path(self.loader.get_scenario_path(DOOM_SETTINGS[self.level][SCENARIO]))
if DOOM_SETTINGS[self.level][MAP] != '':
self.game.set_doom_map(DOOM_SETTINGS[self.level][MAP])
self.game.set_doom_skill(DOOM_SETTINGS[self.level][DIFFICULTY])
self.allowed_actions = DOOM_SETTINGS[self.level][ACTIONS]
self.game.set_screen_resolution(self.screen_resolution)
self.previous_level = self.level
self._closed = False
# Algo mode
if 'human' != self._mode:
self.game.set_window_visible(False)
self.game.set_mode(Mode.PLAYER)
self.no_render = False
try:
with self.lock:
self.game.init()
except (ViZDoomUnexpectedExitException, ViZDoomErrorException):
raise error.Error(
'VizDoom exited unexpectedly. This is likely caused by a missing multiprocessing lock. ' +
'To run VizDoom across multiple processes, you need to pass a lock when you configure the env ' +
'[e.g. env.configure(lock=my_multiprocessing_lock)], or create and close an env ' +
'before starting your processes [e.g. env = gym.make("DoomBasic-v0"); env.close()] to cache a ' +
'singleton lock in memory.')
self._start_episode()
self.is_initialized = True
return self.game.get_state().image_buffer.copy()
# Human mode
else:
self.game.add_game_args('+freelook 1')
self.game.set_window_visible(True)
self.game.set_mode(Mode.SPECTATOR)
self.no_render = True
with self.lock:
self.game.init()
self._start_episode()
self.is_initialized = True
self._play_human_mode()
return np.zeros(shape=self.observation_space.shape, dtype=np.uint8)
def _start_episode(self):
if self.curr_seed > 0:
self.game.set_seed(self.curr_seed)
self.curr_seed = 0
self.game.new_episode()
return
#.........这里部分代码省略.........