File size: 1,244 Bytes
812398b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# 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.

from __future__ import annotations

from dataclasses import dataclass
from enum import Enum
from typing import Optional

try:
    from openenv.core.env_server.types import Action, Observation
    from pydantic import Field
except ImportError:
    from core.env_server.types import Action, Observation
    from pydantic import Field


# --- Action Models ---
class MoveAction(str, Enum):
    UP = "UP"
    DOWN = "DOWN"
    LEFT = "LEFT"
    RIGHT = "RIGHT"


class GridWorldAction(Action):
    action: MoveAction = Field(..., description="The direction to move the agent.")


# --- Observation Model ---
class GridWorldObservation(Observation):
    x: int = Field(..., description="Current X position")
    y: int = Field(..., description="Current Y position")
    message: str = Field("", description="Status message")
    # Reward must be a float, default to 0.0 (not None)

    reward: float = Field(0.0, description="Reward received from the last action")
    done: bool = Field(False, description="Whether the episode has ended")