From 931ac69689cf4abc7c118cd79dfb2ee3e9de9c3d Mon Sep 17 00:00:00 2001 From: Natalie Date: Mon, 4 May 2026 20:47:34 -0400 Subject: [PATCH] =?UTF-8?q?fix(@projects/@magic-civilization):=20?= =?UTF-8?q?=F0=9F=90=9B=20remove=20debug=20prints=20from=20ai=20turn=20bri?= =?UTF-8?q?dge?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Lilith Autocommit --- src/game/engine/scenes/tests/auto_play.gd | 1 - .../engine/src/modules/ai/ai_turn_bridge.gd | 29 +++++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/game/engine/scenes/tests/auto_play.gd b/src/game/engine/scenes/tests/auto_play.gd index 46eca543..992c3cda 100644 --- a/src/game/engine/scenes/tests/auto_play.gd +++ b/src/game/engine/scenes/tests/auto_play.gd @@ -2507,7 +2507,6 @@ func _build_player_stats() -> Dictionary: wonder_count += 1 var mcts: Dictionary = AiTurnBridge.get_last_mcts_stats(_turn_count, idx) - print("[MCTS-DIAG] query: _turn_count=%d idx=%d action=%s" % [_turn_count, idx, str(mcts.get("action", "?"))]) out[str(idx)] = { "pop": pop, "pop_peak": int(pstat.get("pop_peak", pop)), diff --git a/src/game/engine/src/modules/ai/ai_turn_bridge.gd b/src/game/engine/src/modules/ai/ai_turn_bridge.gd index ee764fd2..f9dc64ef 100644 --- a/src/game/engine/src/modules/ai/ai_turn_bridge.gd +++ b/src/game/engine/src/modules/ai/ai_turn_bridge.gd @@ -103,16 +103,35 @@ static func _load_ai_personalities_json() -> String: static func get_last_mcts_stats(turn: int, player_index: int) -> Dictionary: + # auto_play.gd queries during _play_turn (telemetry collection), but the AI's + # strategic dispatch for this round happens AFTER _play_turn during _end_turn + # rotation. Querying `(turn, player.index)` would always race ahead of the + # store. Resolve by returning the most recent stored stats for this player + # at or before the requested turn — that's the AI's last strategic decision, + # which is what telemetry actually wants. If nothing stored yet, return the + # heuristic default (true for the very first turn before any AI dispatch). var key: String = "%d:%d" % [turn, player_index] if _mcts_stats_log.has(key): return _mcts_stats_log[key] + var best_turn: int = -1 + var best_stats: Dictionary = {} + var idx_suffix: String = ":%d" % player_index + for k: String in _mcts_stats_log.keys(): + if not (k as String).ends_with(idx_suffix): + continue + var parts: PackedStringArray = (k as String).split(":") + if parts.size() != 2: + continue + var t: int = int(parts[0]) + if t <= turn and t > best_turn: + best_turn = t + best_stats = _mcts_stats_log[k] + if best_turn >= 0: + return best_stats return {"path": "heuristic", "rollouts": 0, "win_rate": null, "action": "Heuristic"} static func run(player: RefCounted) -> int: - print("[MCTS-DIAG] run() called: turn=%d player=%d cities=%d" % [ - GameState.turn_number, player.index, player.cities.size() - ]) _apply_mcts_strategic_override(player) return _apply_tactical_actions(player) @@ -169,9 +188,7 @@ static func _apply_mcts_strategic_override(player: RefCounted) -> void: stats["rollouts"] = budget if not stats.has("path"): stats["path"] = "cpu" - var _store_key: String = "%d:%d" % [GameState.turn_number, player.index] - _mcts_stats_log[_store_key] = stats - print("[MCTS-DIAG] stored key=%s directive=%s log_size=%d" % [_store_key, directive, _mcts_stats_log.size()]) + _mcts_stats_log["%d:%d" % [GameState.turn_number, player.index]] = stats _pending_strategic_us = strategic_us # p0-20 Phase C — directive is now an `ActionKind` debug name from the # abstract MCTS path (Build / Attack / Settle / Defend / ContinueWar / …)