CoolFace
Apppublic

ignatius-nobel/meta_hackathon

sourceHugging Faceupdated 6mo agoView on Hugging Face
1likes
models.py77 linesDownload Raw Back to root
1# Copyright (c) Meta Platforms, Inc. and affiliates.2# All rights reserved.3#4# This source code is licensed under the BSD-style license found in the5# LICENSE file in the root directory of this source tree.6 7"""8Data models for OpenSpiel Environment.9 10This module defines the Action, Observation, and State types for OpenSpiel games.11"""12 13from __future__ import annotations14 15from typing import Any, Dict, List, Optional16 17from openenv.core.env_server import Action, Observation, State18from pydantic import Field19 20 21class OpenSpielAction(Action):22    """23    Action for OpenSpiel environments.24 25    Attributes:26        action_id: The integer action ID to take (from legal_actions).27        game_name: Name of the OpenSpiel game (e.g., "catch", "tic_tac_toe").28        game_params: Optional game-specific parameters (e.g., {"rows": 8, "columns": 6}).29    """30 31    action_id: int32    game_name: str = "catch"33    game_params: Dict[str, Any] = Field(default_factory=dict)34 35 36class OpenSpielObservation(Observation):37    """38    Observation from OpenSpiel environment.39 40    This represents what the agent sees after taking an action.41    For single-player games, this is straightforward.42    For multi-player games, this is from the perspective of the agent player.43 44    Attributes:45        info_state: Information state tensor (list of floats) for the agent.46                   This contains all information available to the agent.47        legal_actions: List of legal action IDs the agent can take.48        game_phase: String describing the current phase (e.g., "playing", "terminal").49        current_player_id: ID of the current player (-1 for simultaneous, player ID otherwise).50        opponent_last_action: Last action taken by opponent (if available, None otherwise).51    """52 53    info_state: List[float]54    legal_actions: List[int]55    game_phase: str = "playing"56    current_player_id: int = 057    opponent_last_action: Optional[int] = None58 59 60class OpenSpielState(State):61    """62    State for OpenSpiel environment.63 64    Attributes:65        game_name: Name of the OpenSpiel game.66        agent_player: Which player ID the agent controls (0 by default).67        opponent_policy: Name of the opponent policy ("random", "fixed", etc.).68        game_params: Game-specific parameters.69        num_players: Total number of players in the game.70    """71 72    game_name: str = "catch"73    agent_player: int = 074    opponent_policy: str = "random"75    game_params: Dict[str, Any] = Field(default_factory=dict)76    num_players: int = 177