File size: 2,218 Bytes
952f360
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

"""
Data models for the Doom Environment.

The doom_env environment wraps ViZDoom for reinforcement learning research.
ViZDoom is a Doom-based AI research platform for visual RL.
"""

from dataclasses import dataclass
from typing import List, Optional

from openenv_core.env_server.types import Action, Observation


@dataclass(kw_only=True)
class DoomAction(Action):
    """
    Action for the Doom environment.

    Actions are specified as a list of button states. Each element corresponds to
    a button (e.g., MOVE_LEFT, MOVE_RIGHT, ATTACK, etc.) with value 0 (not pressed)
    or 1 (pressed).

    Attributes:
        buttons: List of button states (0 or 1). The length and meaning depend on
                 the available buttons in the scenario.
        action_id: Optional pre-defined action ID if using discrete action space.
                   If provided, this will be used instead of buttons.

    Example:
        # Use discrete action (move left)
        DoomAction(action_id=0)

        # Use button combination (move forward and shoot)
        DoomAction(buttons=[1, 0, 0, 1])
    """

    buttons: Optional[List[int]] = None
    action_id: Optional[int] = None


@dataclass(kw_only=True)
class DoomObservation(Observation):
    """
    Observation from the Doom environment.

    Contains the screen buffer, game variables, and episode information.

    Attributes:
        screen_buffer: Flattened screen pixels as a list of integers.
                      Shape is [height, width, channels] before flattening.
        screen_shape: Original shape of the screen [height, width, channels].
        game_variables: Current values of game variables (health, ammo, etc.).
        available_actions: List of available action IDs if using discrete actions.
        episode_finished: Whether the episode has ended.
    """

    screen_buffer: List[int]
    screen_shape: List[int]
    game_variables: List[float] = None
    available_actions: List[int] = None
    episode_finished: bool = False