ViZDoom Documentation

repository·main·Indexed 24 days ago

https://github.com/farama-foundation/vizdoom

A research platform for developing AI bots that play Doom using visual information, designed for machine visual learning and deep reinforcement learning. It provides C++ and Python APIs, a Gymnasium wrapper for integration with RL libraries like stable-baselines3, and support for custom WAD and CFG scenario configurations. Features include visual, audio, and automap buffers, reward shaping, and spectator mode for apprenticeship learning.

Tokens
32.2K
Snippets
43
Records
204
Agent score
84%

What's inside ViZDoom

  1. Overview of Game_Music_Emu features and supported formats

    main

    Game_Music_Emu is a C interface library for emulating various video game music formats. It provides a uniform set of functions to interact with different emulators and supports the following systems/formats:

    • AY: ZX Spectrum/Amstrad CPC
    • GBS: Nintendo Game Boy
    • GYM: Sega Genesis/Mega Drive
    • HES: NEC TurboGrafx-16/PC Engine
    • KSS: MSX Home Computer/other Z80 systems (no FM sound support)
    • NSF/NSFE: Nintendo NES/Famicom (supports VRC 6, Namco 106, and FME-7)
    • SAP: Atari systems (POKEY sound chip)
    • SPC: Super Nintendo/Super Famicom
    • VGM/VGZ: Sega Master System/Mark III, Sega Genesis/Mega Drive, BBC Micro

    Key Capabilities:

    • Uniform API: Common functions work across all emulators.
    • Audio Control: Adjustable output sample rate (via quality band-limited resampling), tempo adjustment, and individual voice muting.
    • Effects: Treble/bass, stereo echo, and end-of-track fading.
    • Data Access: Read music data from files, memory, or custom reader functions; access track information without loading the full emulator.
    • Playlist Support: M3U track listing for multi-track formats.
  2. Overview of ViZDoom features

    main

    ViZDoom is a C++ library with a Python API designed for research in machine visual learning and deep reinforcement learning. Key capabilities include:

    • Multi-platform support: Linux, macOS, and Windows.
    • High performance: Capable of rendering up to 7000 fps on a single CPU thread.
    • Visual & Audio access: Access to the depth buffer (3D vision), audio buffer, and automatic labeling of visible game objects.
    • Game state information: Access to the list of actors/objects and map geometry.
    • Advanced rendering: Supports off-screen rendering and episode recording.
    • Customization: Supports single-player and multi-player modes, in-game time scaling, and custom scenario creation via visual editors and scripting.
  3. Use the original ViZDoom Python API

    main

    The original ViZDoom API provides direct access to the engine's features. Common tasks include:

    Environment Control & Configuration

    • Basic usage: Configuring the engine and performing actions (e.g., random actions).
    • Deterministic runs: Using seed.py to set a seed so that episodes are deterministic.
    • Save/Load: Using the built-in engine functionality to save and load game states.
    • Scenarios: Exploring the various built-in scenarios available in the environment.
    • Performance: Testing frames per second (FPS) to gauge hardware performance.
    • Ticrates: Using different ticrates in ASYNC mode.

    Buffers and Data Access

    ViZDoom exposes several buffers to access game state data:

    • Visual Buffers: Access screen, depth, labels, and map buffers.
    • Audio Buffer: Access the audio stream.
    • Automap Buffer: Access the automap data.
    • Notifications Buffer: Enable and read notifications from the game state.
    • Objects and Sectors: Access the list of actors/objects and map geometry.

    Reinforcement Learning & Training

    • Framework Integration: Examples are available for implementing Q-learning with PyTorch or TensorFlow.
    • Stable Baselines3: Training agents using the Gymnasium wrapper.
    • Reward Shaping: Implementing reward shaping using game variables (e.g., health-guided scenarios).
    • Built-in Rewards: Setting basic rewards via the API (e.g., set_health_reward, set_armor_reward, set_item_reward, set_kill_reward).

    Multiplayer & Competition

    • CIG Competition: Configuration and play for both singleplayer and multiplayer modes for the CIG competition.
    • Bots: Playing with bots to simulate multiplayer environments for AI agent development.
    • Multiple Instances: Creating a "server" to host multiple agents playing simultaneously.

    Recording & Playback

    • Episodes: Recording and replaying single episodes.
    • Multiplayer: Recording and replaying multiplayer games.

    Advanced Features

    • Delta Buttons: Using delta buttons for precise movement (values other than 0 and 1).
    • Spectator Mode: Using SPECTATOR mode where a human plays and the AI observes (useful for apprenticeship learning).
    • Sectors Visualization: Rendering 3D maps of sectors (floor/ceiling/walls) and objects.
  4. Use list parameters and the append operator in config files

    main

    Certain parameters like available_buttons and available_game_variables require a list of values instead of a single value.

    List Syntax

    Lists must be enclosed in braces { and } and values should be separated by whitespace. Lists can span multiple lines.

    Appending vs. Overwriting

    • Overwriting: Using KEY = { VALUES } clears any existing values for that key (from previous files or code) and replaces them with the new list.
    • Appending: Using the append operator KEY += { VALUES } adds the new values to the existing list without clearing the previous ones. This is useful for combining multiple configuration files.
  5. Configure ViZDoom game modes

    main

    ViZDoom uses vizdoom.Mode to define how the agent interacts with the game and how the game progresses.

    Agent Control

    • PLAYER and ASYNC_PLAYER: The agent controls the in-game character.
    • SPECTATOR and ASYNC_SPECTATOR: A human controls the character, and the agent receives information about the human's actions.

    Game Progression

    • PLAYER and SPECTATOR: The game waits for the agent to provide an action or permission to continue.
    • ASYNC modes: The game progresses at a constant speed (default 35 tics per second, configurable via set_ticrate) without waiting for agent actions.
  6. Use the Sector and Line structures for map data

    main

    A Sector represents a part of the map with a constant floor and ceiling height. It is composed of a list of Line segments.

    • Sector: Use DoomGame::setSectorsInfoEnabled to populate this. The id field is referenced by Object.sector_id.
    • Line: Describes the boundaries of a sector. The is_blocking field indicates if the line acts as a wall.
  7. Scenario file structure: .wad and .cfg

    main

    A ViZDoom scenario typically consists of two files:

    1. .wad file: Contains the map and scripts (Doom's engine format). It usually does not implement action constraints, death penalties, or living rewards unless programmed into the script.
    2. .cfg file: Contains additional settings such as action constraints, death penalties, living rewards, and access to additional information.

    Important Notes:

    • Settings specified in .cfg files are often marked as (config) in documentation.
    • Certain rewards (like killing specific opponents) cannot be set in .cfg files; they must be programmed directly into the .wad files.
    • Settings in .cfg files can be overridden in code when using the original ViZDoom API.
  8. Implement custom rewards using ACS scripting

    main

    ViZDoom uses the ACS scripting language to allow custom game logic. To implement a rewarding mechanism, you must use the global variable 0.

    Important Note on Numbers: ACS does not support real floating-point numbers; it uses fixed-point numbers. Because ViZDoom treats rewards as fixed-point numerals, you must use decimal points (e.g., 1.0 instead of 1) in your ACS scripts to ensure the reward is processed correctly.

    global int 0:reward;
    ...
    script 1(void)
    {
        ...
        reward += 100.0;
    }
    ...
  9. Understand ViZDoom nomenclature and API relationships

    main

    ViZDoom provides several API layers. The core is a C++ API, which is wrapped by a Python API. To use ViZDoom with reinforcement learning frameworks, Gymnasium wrappers wrap the Python API to provide a standard Gymnasium interface.

    Because ViZDoom predates OpenAI Gym, it uses different terminology for core concepts:

    • scenarios (instead of environments)
    • states (instead of observations)
    • tics (instead of steps). A tic represents a single logic update of the game state, corresponding to 1/35th of a second.

    Relationship Summary:

    • C++ API $\rightarrow$ Python API $\rightarrow$ Gymnasium Wrappers
  10. Understanding MultiBinary action space variants

    main

    For every Gymnasium environment provided, there is a corresponding MultiBinary variant.

    • Discrete Action Space (Default): The agent selects a single action from a predefined list.
    • MultiBinary Action Space: The agent can press multiple buttons simultaneously. This is often more natural for ViZDoom gameplay and allows for more complex behaviors.

    Naming Convention: To use the MultiBinary variant, append -MultiBinary before the version number in the environment ID.

    Example: VizdoomBasic-v1 (Discrete) $\rightarrow$ VizdoomBasic-MultiBinary-v1 (MultiBinary).

    MultiBinary variants share the same observation space, rewards, and configurations as their Discrete counterparts.