Spaces:
Paused
Paused
Download games/base.py from igardner/StockAnalysis: direct link, hf CLI and curl.
- Browser
- Download file 1.6 kB
-
https://huggingface.co/spaces/igardner/StockAnalysis/resolve/main/games/base.py
- Command line
-
hf download hf://spaces/igardner/StockAnalysis/games/base.py
-
curl -L -o base.py https://huggingface.co/spaces/igardner/StockAnalysis/resolve/main/games/base.py
1.6 kB
| from dataclasses import dataclass, field | |
| from typing import Any, Dict, List, Optional | |
| class GameMetadata: | |
| game_type: str | |
| name: str | |
| description: str = "" | |
| min_players: int = 5 | |
| max_players: int = 15 | |
| version: str = "0.1.0" | |
| author: str = "" | |
| tags: List[str] = field(default_factory=list) | |
| configurable: bool = True | |
| class GameBase: | |
| metadata = GameMetadata(game_type="base", name="Base Game") | |
| def __init__(self, game_id: int, room_id: int, config: Optional[Dict[str, Any]] = None): | |
| self.game_id = game_id | |
| self.room_id = room_id | |
| self.config = config or {} | |
| self.state: Dict[str, Any] = {} | |
| def initialize(self, players: List[Dict[str, Any]]) -> Dict[str, Any]: | |
| raise NotImplementedError | |
| def get_state(self) -> Dict[str, Any]: | |
| return self.state | |
| def load_state(self, state: Dict[str, Any]) -> None: | |
| """Restore persisted server state before handling an action.""" | |
| self.state = state or {} | |
| def handle_action(self, user_id: int, action: str, payload: Dict[str, Any]) -> Dict[str, Any]: | |
| raise NotImplementedError | |
| def check_end_conditions(self) -> Optional[Dict[str, Any]]: | |
| return None | |
| def get_public_state(self, viewer_user_id: int) -> Dict[str, Any]: | |
| # Never expose raw persisted state by default: games may keep secret | |
| # roles, actions, or model-derived signals in that object. | |
| return { | |
| "game_id": self.game_id, | |
| "room_id": self.room_id, | |
| "phase": self.state.get("phase", "setup"), | |
| } | |