本文整理汇总了Python中vizdoom.DoomGame方法的典型用法代码示例。如果您正苦于以下问题:Python vizdoom.DoomGame方法的具体用法?Python vizdoom.DoomGame怎么用?Python vizdoom.DoomGame使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vizdoom
的用法示例。
在下文中一共展示了vizdoom.DoomGame方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import vizdoom [as 别名]
# 或者: from vizdoom import DoomGame [as 别名]
def __init__(self, level):
# init game
self.game = DoomGame()
self.game.set_screen_resolution(ScreenResolution.RES_640X480)
scenarios_dir = os.path.join(os.path.dirname(__file__), 'scenarios')
self.game.load_config(os.path.join(scenarios_dir, CONFIGS[level][0]))
self.game.set_window_visible(False)
self.game.init()
self.state = None
self.action_space = spaces.Discrete(CONFIGS[level][1])
self.observation_space = spaces.Box(0, 255, (self.game.get_screen_height(),
self.game.get_screen_width(),
self.game.get_screen_channels()),
dtype=np.uint8)
self.viewer = None
示例2: __init__
# 需要导入模块: import vizdoom [as 别名]
# 或者: from vizdoom import DoomGame [as 别名]
def __init__(self, config_file, visible=False, mode=vizdoom.Mode.PLAYER, screen_format=vizdoom.ScreenFormat.GRAY8, screen_resolution=vizdoom.ScreenResolution.RES_640X480):
"""
Args:
config_file (str): The config file to configure the DoomGame object.
visible (bool):
mode (vizdoom.Mode): The playing mode of the game.
screen_format (vizdoom.ScreenFormat): The screen (pixel) format of the game.
screen_resolution (vizdoom.ScreenResolution): The screen resolution (width x height) of the game.
"""
# Some restrictions on the settings.
assert screen_format in [vizdoom.ScreenFormet.RGB24, vizdoom.ScreedFormat.GRAY8], "ERROR: `screen_format` must be either GRAY8 or RGB24!"
assert screen_resolution in [vizdoom.ScreenResolution.RES_640X480], "ERROR: `screen_resolution` must be 640x480!"
self.game = vizdoom.DoomGame()
self.game.load_config(config_file)
self.game.set_window_visible(False)
self.game.set_mode(mode)
self.game.set_screen_format(screen_format)
self.game.set_screen_resolution(screen_resolution)
self.game.init()
# Calculate action and state Spaces for Env c'tor.
state_space = IntBox(255, shape=(480, 480, 1 if screen_format == vizdoom.ScreenFormat.GRAY8 else 3)) # image of size [resolution] with [screen-format] channels
action_space = IntBox(1, shape=(self.game.get_available_buttons_size(),))
super(VizDoomEnv, self).__init__(state_space=state_space, action_space=action_space)
示例3: __init__
# 需要导入模块: import vizdoom [as 别名]
# 或者: from vizdoom import DoomGame [as 别名]
def __init__(self, args):
self.config = args['config']
self.resolution = args['resolution']
self.frame_skip = args['frame_skip']
self.color_mode = args['color_mode']
self.game_args = args['game_args']
self._game = vizdoom.DoomGame()
self._game.load_config(self.config)
self._game.add_game_args(self.game_args)
if 'ticrate' in args:
self._game.set_ticrate(args['ticrate'])
# set resolution
try:
self._game.set_screen_resolution(getattr(vizdoom.ScreenResolution, 'RES_%dX%d' % self.resolution))
except:
print("Requested resolution not supported:", sys.exc_info()[0])
raise
# set color mode
if self.color_mode == 'RGB':
self._game.set_screen_format(vizdoom.ScreenFormat.CRCGCB)
self.num_channels = 3
elif self.color_mode == 'GRAY':
self._game.set_screen_format(vizdoom.ScreenFormat.GRAY8)
self.num_channels = 1
else:
print("Unknown color mode")
raise
self.available_controls, self.continuous_controls, self.discrete_controls = self.analyze_controls(self.config)
self.num_buttons = self._game.get_available_buttons_size()
assert (self.num_buttons == len(self.discrete_controls) + len(self.continuous_controls))
assert (len(self.continuous_controls) == 0) # only discrete for now
self.num_meas = self._game.get_available_game_variables_size()
self.game_initialized = False
示例4: create_environment
# 需要导入模块: import vizdoom [as 别名]
# 或者: from vizdoom import DoomGame [as 别名]
def create_environment():
game = DoomGame()
game.load_config("basic.cfg")
game.set_doom_scenario_path("basic.wad")
game.init()
left = [1, 0, 0]
right = [0, 1, 0]
shoot = [0, 0, 1]
possible_actions = [left, right, shoot]
return game, possible_actions
示例5: create_environment
# 需要导入模块: import vizdoom [as 别名]
# 或者: from vizdoom import DoomGame [as 别名]
def create_environment():
game = DoomGame()
game.load_config('defend_the_center.cfg')
game.set_doom_scenario_path('defend_the_center.wad')
game.init()
possible_actions = np.identity(3, dtype=int).tolist()
return game, possible_actions
示例6: __init__
# 需要导入模块: import vizdoom [as 别名]
# 或者: from vizdoom import DoomGame [as 别名]
def __init__(
self, level, visualize=False, include_variables=False, factored_action=False,
frame_skip=12, seed=None
):
super().__init__()
from vizdoom import DoomGame, Mode, ScreenFormat, ScreenResolution
self.config_file = level
self.include_variables = include_variables
self.factored_action = factored_action
self.visualize = visualize
self.frame_skip = frame_skip
self.environment = DoomGame()
self.environment.load_config(self.config_file)
if self.visualize:
self.environment.set_window_visible(True)
self.environment.set_mode(Mode.ASYNC_PLAYER)
else:
self.environment.set_window_visible(False)
self.environment.set_mode(Mode.PLAYER)
# e.g. CRCGCB, RGB24, GRAY8
self.environment.set_screen_format(ScreenFormat.RGB24)
# e.g. RES_320X240, RES_640X480, RES_1920X1080
self.environment.set_screen_resolution(ScreenResolution.RES_640X480)
self.environment.set_depth_buffer_enabled(False)
self.environment.set_labels_buffer_enabled(False)
self.environment.set_automap_buffer_enabled(False)
if seed is not None:
self.environment.setSeed(seed)
self.environment.init()
self.state_shape = (480, 640, 3)
self.num_variables = self.environment.get_available_game_variables_size()
self.num_buttons = self.environment.get_available_buttons_size()
self.available_actions = [
tuple(a) for a in itertools.product([0, 1], repeat=self.num_buttons)
]
示例7: __init__
# 需要导入模块: import vizdoom [as 别名]
# 或者: from vizdoom import DoomGame [as 别名]
def __init__(self, config='vizdoom_env/asset/default.cfg', verbose=False,
perception_type='more_simple'):
self.verbose = verbose
self.game = DoomGame()
self.game.load_config(config)
if self.verbose:
self.game.set_window_visible(True)
self.game.set_screen_resolution(ScreenResolution.RES_1280X960)
self.game_variables = self.game.get_available_game_variables()
self.buttons = self.game.get_available_buttons()
self.action_strings = [b.__str__().replace('Button.', '')
for b in self.buttons]
self.game_variable_strings = [v.__str__().replace('GameVariable.', '')
for v in self.game_variables]
self.perception_type = perception_type
if perception_type == 'clear':
self.distance_dict = CLEAR_DISTANCE_DICT
self.horizontal_dict = CLEAR_HORIZONTAL_DICT
elif perception_type == 'simple':
pass
elif perception_type == 'more_simple':
pass
else:
self.distance_dict = DISTANCE_DICT
self.horizontal_dict = HORIZONTAL_DICT
示例8: __init__
# 需要导入模块: import vizdoom [as 别名]
# 或者: from vizdoom import DoomGame [as 别名]
def __init__(self, cfg_name, repeat=1):
super().__init__()
self.game = DoomGame()
self.game.load_config(f'./slm_lab/env/vizdoom/cfgs/{cfg_name}.cfg')
self._viewer = None
self.repeat = 1
# TODO In future, need to update action to handle (continuous) DELTA buttons using gym's Box space
self.action_space = spaces.MultiDiscrete([2] * self.game.get_available_buttons_size())
self.action_space.dtype = 'uint8'
output_shape = (self.game.get_screen_channels(), self.game.get_screen_height(), self.game.get_screen_width())
self.observation_space = spaces.Box(low=0, high=255, shape=output_shape, dtype='uint8')
self.game.init()
示例9: __init__
# 需要导入模块: import vizdoom [as 别名]
# 或者: from vizdoom import DoomGame [as 别名]
def __init__(self, vizdoom_dir=os.path.expanduser('~/ViZDoom'),
window_visible=True, scenario='basic', skipcount=10,
resolution_width=640, sleep=0.0, seed=None):
self.skipcount = skipcount
self.sleep = sleep
sys.path.append(os.path.join(vizdoom_dir, "examples/python"))
from vizdoom import DoomGame
from vizdoom import ScreenFormat
from vizdoom import ScreenResolution
game = DoomGame()
if seed is not None:
assert seed >= 0 and seed < 2 ** 16, \
"ViZDoom's random seed must be represented by unsigned int"
else:
# Use numpy's random state
seed = np.random.randint(0, 2 ** 16)
game.set_seed(seed)
# Load a config file
game.load_config(os.path.join(
vizdoom_dir, "examples", 'config', scenario + '.cfg'))
# Replace default relative paths with actual paths
game.set_vizdoom_path(os.path.join(vizdoom_dir, "bin/vizdoom"))
game.set_doom_game_path(
os.path.join(vizdoom_dir, 'scenarios/freedoom2.wad'))
game.set_doom_scenario_path(
os.path.join(vizdoom_dir, 'scenarios', scenario + '.wad'))
# Set screen settings
resolutions = {640: ScreenResolution.RES_640X480,
320: ScreenResolution.RES_320X240,
160: ScreenResolution.RES_160X120}
game.set_screen_resolution(resolutions[resolution_width])
game.set_screen_format(ScreenFormat.RGB24)
game.set_window_visible(window_visible)
game.set_sound_enabled(window_visible)
game.init()
self.game = game
# Use one-hot actions
self.n_actions = game.get_available_buttons_size()
self.actions = []
for i in range(self.n_actions):
self.actions.append([i == j for j in range(self.n_actions)])
示例10: __init__
# 需要导入模块: import vizdoom [as 别名]
# 或者: from vizdoom import DoomGame [as 别名]
def __init__(self, cfg_path, number_maps, scaled_resolution=(42, 42), action_frame_repeat=4, clip=(-1, 1),
seed=None, data_augmentation=False):
"""
Gym environment for training reinforcement learning agents.
:param cfg_path: name of the mission (.cfg) to run
:param number_maps: number of maps which are contained within the cfg file
:param scaled_resolution: resolution (height, width) of the observation to be returned with each step
:param action_frame_repeat: how many game tics should an action be active
:param clip: how much the reward returned on each step should be clipped to
:param seed: seed for random, used to determine the other that the doom maps should be shown.
:param data_augmentation: bool to determine whether or not to use data augmentation
(adding randomly colored, randomly sized boxes to observation)
"""
self.cfg_path = str(cfg_path)
if not os.path.exists(self.cfg_path):
raise ValueError("Cfg file not found", cfg_path)
if not self.cfg_path.endswith('.cfg'):
raise ValueError("cfg_path must end with .cfg")
self.number_maps = number_maps
self.scaled_resolution = scaled_resolution
self.action_frame_repeat = action_frame_repeat
self.clip = clip
self.data_augmentation = data_augmentation
if seed:
random.seed(seed)
super(VizDoom, self).__init__()
self._logger = logging.getLogger(__name__)
self._logger.info("Creating environment: VizDoom (%s)", self.cfg_path)
# Create an instace on VizDoom game, initalise it from a scenario config file
self.env = DoomGame()
self.env.load_config(self.cfg_path)
self.env.init()
# Perform config validation:
# Only RGB format with a seperate channel per colour is supported
# assert self.env.get_screen_format() == ScreenFormat.RGB24
# Only discreete actions are supported (no delta actions)
available_actions = self.env.get_available_buttons()
not_supported_actions = [Button.LOOK_UP_DOWN_DELTA, Button.TURN_LEFT_RIGHT_DELTA,
Button.MOVE_LEFT_RIGHT_DELTA, Button.MOVE_UP_DOWN_DELTA,
Button.MOVE_FORWARD_BACKWARD_DELTA]
assert len((set(available_actions) - set(not_supported_actions))) == len(available_actions)
# Allow only one button to be pressed at a given step
self.action_space = gym.spaces.Discrete(self.env.get_available_buttons_size())
rows = scaled_resolution[1]
columns = scaled_resolution[0]
self.observation_space = gym.spaces.Box(0.0,
255.0,
shape=(columns, rows, 3),
dtype=np.float32)
self._rgb_array = None
self.reset()