| """ |
| DroneState - Standardized data structure for Game judgment system. |
| |
| This module defines the immutable data structures that flow from |
| DroneSheet middleware to the Game module. |
| """ |
|
|
| from dataclasses import dataclass, field |
| from typing import Dict, List, Optional, Any |
|
|
|
|
| @dataclass(frozen=True) |
| class EnvironmentEffects: |
| """ |
| Environment effects computed by SCM. |
| |
| This is what SCM writes into DroneSheet. |
| """ |
| |
| component_damage: Dict[str, int] = field(default_factory=dict) |
|
|
| |
| detection_modifier: float = 1.0 |
| base_detection_prob: float = 0.70 |
|
|
| |
| combat_damage_modifier: float = 1.0 |
| combat_rounds_modifier: float = 1.0 |
| combat_accuracy_modifier: float = 1.0 |
|
|
| |
| navigation_modifier: float = 1.0 |
|
|
| |
| camera_effectiveness: float = 1.0 |
| gun_effectiveness: float = 1.0 |
| antenna_effectiveness: float = 1.0 |
|
|
| |
| weather_pattern: float = 0.5 |
| raw_environment: Dict[str, float] = field(default_factory=dict) |
|
|
| |
| damage_log: List[str] = field(default_factory=list) |
|
|
|
|
| @dataclass(frozen=True) |
| class DroneState: |
| """ |
| Standardized input for Game judgment system. |
| |
| This is an IMMUTABLE snapshot of drone state at judgment time. |
| Game module receives this and returns JudgmentResult. |
| |
| Design principle: Game knows NOTHING about SCM or environment. |
| All effects are pre-computed and encoded in this state. |
| """ |
|
|
| |
| hp: Dict[str, int] |
|
|
| |
| def_values: Dict[str, int] = field(default_factory=dict) |
|
|
| |
| agility: float = 1.0 |
| detection_probability: float = 0.15 |
| combat_rounds: int = 3 |
|
|
| |
| antenna_emitting: bool = True |
| antenna_hp: int = 50 |
|
|
| |
| combat_damage_modifier: float = 1.0 |
| combat_accuracy_modifier: float = 1.0 |
|
|
| |
| camera_power: float = 1.0 |
| gun_power: float = 1.0 |
|
|
| |
| weather_pattern: float = 0.5 |
| environment_visible: Dict[str, float] = field(default_factory=dict) |
|
|
| @property |
| def critical_hp(self) -> Dict[str, int]: |
| """Return only critical component HP values.""" |
| critical = ['engine', 'cockpit', 'wing', 'body'] |
| return {k: v for k, v in self.hp.items() if k in critical} |
|
|
| @property |
| def total_hp(self) -> int: |
| """Total HP across all components.""" |
| return sum(self.hp.values()) |
|
|
| @property |
| def total_def(self) -> int: |
| """Total DEF across all components.""" |
| return sum(self.def_values.values()) |
|
|
| @property |
| def is_functional(self) -> bool: |
| """Check if drone has minimum functionality.""" |
| return all(self.hp.get(c, 0) > 0 for c in ['engine', 'cockpit']) |
|
|
|
|
| @dataclass |
| class JudgmentResult: |
| """ |
| Result from Game judgment system. |
| |
| This is what Game.judge_survival() returns. |
| """ |
| status: str |
| fail_reason: Optional[str] = None |
| final_hp: Dict[str, int] = field(default_factory=dict) |
|
|
| |
| was_detected: bool = False |
| hit_count: int = 0 |
| damage_taken: int = 0 |
|
|
| |
| combat_log: List[str] = field(default_factory=list) |
| damage_log: List[str] = field(default_factory=list) |
|
|
| @property |
| def survived(self) -> bool: |
| """Did the drone survive?""" |
| return self.status == "RETURNED" |
|
|
|
|
| @dataclass |
| class CombatResult: |
| """ |
| Result from combat simulation. |
| """ |
| hit_count: int = 0 |
| damage_by_component: Dict[str, int] = field(default_factory=dict) |
| total_damage: int = 0 |
| combat_log: List[str] = field(default_factory=list) |
| rounds_fought: int = 0 |
|
|