From 648e1b8d38d07ce73fa95fbe30a31a95a0077e2d Mon Sep 17 00:00:00 2001 From: KoalaTrapLord Date: Thu, 12 Mar 2026 18:25:22 +0000 Subject: [PATCH] =?UTF-8?q?Fix=20simulator=20button=20stuck=20on=20Running?= =?UTF-8?q?=20=E2=80=94=20to=5Fdict()=20backward=20compat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GameResult.to_dict() now returns both legacy keys (winner, playerA, playerB) that the UI expects AND new N-player keys (winningSeat, playerResults) for the Java BatchResult schema. --- src/commander_ai_lab/sim/models.py | 31 +++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/commander_ai_lab/sim/models.py b/src/commander_ai_lab/sim/models.py index 5b7b001..4f5c2bc 100644 --- a/src/commander_ai_lab/sim/models.py +++ b/src/commander_ai_lab/sim/models.py @@ -306,12 +306,37 @@ class GameResult: return p.eliminated if p else False def to_dict(self) -> dict: - """Serialize to dict matching Java BatchResult.GameResult schema.""" - d = { - "winningSeat": self.winner_seat, + """Serialize to dict. + + Returns both the legacy 2-player keys (winner, playerA, playerB) + that the existing UI and lab_api consumers expect AND the new + N-player 'playerResults' array for the Java BatchResult schema. + """ + d: dict = { + # Legacy keys (UI expects these) + "winner": self.winner_seat, "turns": self.turns, + # New N-player keys (Java BatchResult schema) + "winningSeat": self.winner_seat, "playerResults": [p.to_dict() for p in self.players], } + + # Legacy playerA / playerB dicts for the UI + pa = self.player(0) + pb = self.player(1) + d["playerA"] = { + "name": pa.name if pa else "", + "life": pa.life if pa else 0, + "eliminated": pa.eliminated if pa else False, + "stats": pa.stats.to_dict() if pa and pa.stats else {}, + } + d["playerB"] = { + "name": pb.name if pb else "", + "life": pb.life if pb else 0, + "eliminated": pb.eliminated if pb else False, + "stats": pb.stats.to_dict() if pb and pb.stats else {}, + } + if self.game_log: d["gameLog"] = self.game_log return d