Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setup_test(buttons, variables, visible=True):
game = vzd.DoomGame()
game.set_doom_scenario_path("../../scenarios/basic.wad")
game.set_doom_map("map01")
game.set_episode_start_time(10)
game.set_window_visible(visible)
if visible:
game.set_screen_resolution(vzd.ScreenResolution.RES_640X480)
# Test if everything is alright with variables
game.set_available_game_variables(variables)
assert len(variables) == game.get_available_game_variables_size()
assert variables == game.get_available_game_variables()
# Test if everything is alright with buttons
game.set_available_buttons(buttons)
assert len(buttons) == game.get_available_buttons_size()
def setup_test(buttons, variables, visible=True):
game = vzd.DoomGame()
game.set_doom_scenario_path("../../scenarios/basic.wad")
game.set_doom_map("map01")
game.set_episode_start_time(10)
game.set_window_visible(visible)
if visible:
game.set_screen_resolution(vzd.ScreenResolution.RES_640X480)
# Test if everything is alright with variables
game.set_available_game_variables(variables)
assert len(variables) == game.get_available_game_variables_size()
assert variables == game.get_available_game_variables()
# Test if everything is alright with buttons
game.set_available_buttons(buttons)
assert len(buttons) == game.get_available_buttons_size()
assert buttons == game.get_available_buttons()
game.set_mode(vzd.Mode.PLAYER)
return game
if doom_wrapper.is_terminal():
doom_wrapper.reset()
end = time()
wrapper_t = (end - start)
# Vanilla vizdoom:
doom = vzd.DoomGame()
if "scenarios_path" not in settings:
scenarios_path = vzd.__path__[0] + "/scenarios"
else:
scenarios_path = settings["scenarios_path"]
config_file = scenarios_path + "/" + settings["config_file"]
doom.load_config(config_file)
doom.set_window_visible(False)
doom.set_screen_format(vzd.ScreenFormat.GRAY8)
doom.set_screen_resolution(vzd.ScreenResolution.RES_160X120)
doom.init()
actions = [list(a) for a in it.product([0, 1], repeat=len(doom.get_available_game_variables()))]
start = time()
frame_skip = settings["frame_skip"]
for _ in trange(iters, leave=False):
if doom.is_episode_finished():
doom.new_episode()
doom.make_action(choice(actions), frame_skip)
end = time()
vanilla_t = end - start
print(green("\twrapper: {:0.2f} steps/s".format(iters / wrapper_t)))
print(green("\twrapper: {:0.2f} s/1000 steps".format(wrapper_t / iters * 1000)))
print(blue("\tvanilla: {:0.2f} steps/s".format(iters / vanilla_t)))
print(blue("\tvanilla: {:0.2f} s/1000 steps\n".format(vanilla_t / iters * 1000)))
def recording_test(buttons, variables, actions, recording_file="test_recording.lmp", sleep_time=0, mode=vzd.Mode.PLAYER,
verbose=0, verbose_sleep_time=0.1, title="Unnamed test"):
print("Test: {}".format(title))
game = setup_test(buttons, variables, visible=verbose)
# Append all zeros action
actions.append([0.0] * game.get_available_buttons_size())
history_of_actions = []
history_of_variables = []
history_of_rewards = []
game.init()
game.new_episode(recording_file)
for i, action in enumerate(actions):
print(" Playing:", i, "/", len(actions), end = '\r')
#!/usr/bin/env python3
#####################################################################
# This script test recording functionality
#####################################################################
from __future__ import print_function
import vizdoom as vzd
from random import random
from time import sleep
import os
GV = vzd.GameVariable
B = vzd.Button
def setup_test(buttons, variables, visible=True):
game = vzd.DoomGame()
game.set_doom_scenario_path("../../scenarios/basic.wad")
game.set_doom_map("map01")
game.set_episode_start_time(10)
game.set_window_visible(visible)
if visible:
game.set_screen_resolution(vzd.ScreenResolution.RES_640X480)
# Test if everything is alright with variables
game.set_available_game_variables(variables)
assert len(variables) == game.get_available_game_variables_size()
assert variables == game.get_available_game_variables()
if doom_wrapper.is_terminal():
doom_wrapper.reset()
end = time()
wrapper_t = (end - start)
# Vanilla vizdoom:
doom = vzd.DoomGame()
if "scenarios_path" not in settings:
scenarios_path = vzd.__path__[0] + "/scenarios"
else:
scenarios_path = settings["scenarios_path"]
config_file = scenarios_path + "/" + settings["config_file"]
doom.load_config(config_file)
doom.set_window_visible(False)
doom.set_screen_format(vzd.ScreenFormat.GRAY8)
doom.set_screen_resolution(vzd.ScreenResolution.RES_160X120)
doom.init()
actions = [list(a) for a in it.product([0, 1], repeat=len(doom.get_available_game_variables()))]
start = time()
frame_skip = settings["frame_skip"]
for _ in trange(iters, leave=False):
if doom.is_episode_finished():
doom.new_episode()
doom.make_action(choice(actions), frame_skip)
end = time()
vanilla_t = end - start
print(green("\twrapper: {:0.2f} steps/s".format(iters / wrapper_t)))
print(green("\twrapper: {:0.2f} s/1000 steps".format(wrapper_t / iters * 1000)))
print(blue("\tvanilla: {:0.2f} steps/s".format(iters / vanilla_t)))
print(blue("\tvanilla: {:0.2f} s/1000 steps\n".format(vanilla_t / iters * 1000)))
game.set_window_visible(visible)
if visible:
game.set_screen_resolution(vzd.ScreenResolution.RES_640X480)
# Test if everything is alright with variables
game.set_available_game_variables(variables)
assert len(variables) == game.get_available_game_variables_size()
assert variables == game.get_available_game_variables()
# Test if everything is alright with buttons
game.set_available_buttons(buttons)
assert len(buttons) == game.get_available_buttons_size()
assert buttons == game.get_available_buttons()
game.set_mode(vzd.Mode.PLAYER)
return game
game.set_episode_timeout(200)
# Makes episodes start after 10 tics (~after raising the weapon)
game.set_episode_start_time(10)
# Makes the window appear (turned on by default)
game.set_window_visible(True)
# Turns on the sound. (turned off by default)
game.set_sound_enabled(True)
# Sets the livin reward (for each move) to -1
game.set_living_reward(-1)
# Sets ViZDoom mode (PLAYER, ASYNC_PLAYER, SPECTATOR, ASYNC_SPECTATOR, PLAYER mode is default)
game.set_mode(vzd.Mode.PLAYER)
# Enables engine output to console.
#game.set_console_enabled(True)
# Initialize the game. Further configuration won't take any effect from now on.
game.init()
# Define some actions. Each list entry corresponds to declared buttons:
# MOVE_LEFT, MOVE_RIGHT, ATTACK
# game.get_available_buttons_size() can be used to check the number of available buttons.
# 5 more combinations are naturally possible but only 3 are included for transparency when watching.
actions = [[True, False, False], [False, True, False], [False, False, True]]
# Run this many episodes
episodes = 10
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
def initialize_vizdoom(config_file_path):
print("Initializing doom...")
game = vzd.DoomGame()
game.load_config(config_file_path)
game.set_window_visible(False)
game.set_mode(vzd.Mode.PLAYER)
game.set_screen_format(vzd.ScreenFormat.GRAY8)
game.set_screen_resolution(vzd.ScreenResolution.RES_640X480)
game.init()
print("Doom initialized.")
return game