27 lines
1.2 KiB
Python
27 lines
1.2 KiB
Python
|
|
"""Parse et normalise l'état de jeu brut en GameState typé."""
|
||
|
|
from backend.ai.engine.decision_engine import GameState
|
||
|
|
|
||
|
|
|
||
|
|
class StateAnalyzer:
|
||
|
|
"""Convertit les données brutes (API, OCR, manuel) en GameState."""
|
||
|
|
|
||
|
|
async def parse(self, raw: dict) -> GameState:
|
||
|
|
return GameState(
|
||
|
|
turn=int(raw.get("turn", 0)),
|
||
|
|
tavern_tier=int(raw.get("tavern_tier", 1)),
|
||
|
|
gold=int(raw.get("gold", 3)),
|
||
|
|
hero_id=str(raw.get("hero_id", "")),
|
||
|
|
hero_hp=int(raw.get("hero_hp", 40)),
|
||
|
|
tavern_minions=list(raw.get("tavern_minions", [])),
|
||
|
|
board_minions=list(raw.get("board_minions", [])),
|
||
|
|
hand_minions=list(raw.get("hand_minions", [])),
|
||
|
|
freeze=bool(raw.get("freeze", False)),
|
||
|
|
can_upgrade=bool(raw.get("can_upgrade", True)),
|
||
|
|
upgrade_cost=int(raw.get("upgrade_cost", 5)),
|
||
|
|
available_spells=list(raw.get("available_spells", [])),
|
||
|
|
opponent_boards=list(raw.get("opponent_boards", [])),
|
||
|
|
current_placement=int(raw.get("current_placement", 5)),
|
||
|
|
player_count=int(raw.get("player_count", 8)),
|
||
|
|
phase=str(raw.get("phase", "recruit")),
|
||
|
|
)
|