How to use vizdoom - 10 common examples

To help you get started, we’ve selected a few vizdoom examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mwydmuch / ViZDoom / examples / python / test_recording.py View on Github external
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()
github mwydmuch / ViZDoom / examples / python / test_recording.py View on Github external
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
github mihahauke / deep_rl_vizdoom / test_wrapper_performance.py View on Github external
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)))
github mwydmuch / ViZDoom / examples / python / test_recording.py View on Github external
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')
github mwydmuch / ViZDoom / examples / python / test_recording.py View on Github external
#!/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()
github mihahauke / deep_rl_vizdoom / test_wrapper_performance.py View on Github external
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)))
github mwydmuch / ViZDoom / examples / python / test_recording.py View on Github external
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
github mwydmuch / ViZDoom / examples / python / basic.py View on Github external
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
github Urinx / ReinforcementLearning / DQN / Doom / DQN_Doom.py View on Github external
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
github mwydmuch / ViZDoom / examples / python / learning_tensorflow.py View on Github external
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