From 25e5f8849ff4a93daba7da107c4deb61c6facae3 Mon Sep 17 00:00:00 2001 From: autocommit Date: Sun, 12 Apr 2026 23:32:26 -0700 Subject: [PATCH] =?UTF-8?q?test(scenes):=20=E2=9C=85=20Add=20test=20cases?= =?UTF-8?q?=20for=20AI-driven=20auto-play=20city=20founding=20behavior=20v?= =?UTF-8?q?alidation?= 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 | 35 ++++++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/src/game/engine/scenes/tests/auto_play.gd b/src/game/engine/scenes/tests/auto_play.gd index 870aca92..de6b3da4 100644 --- a/src/game/engine/scenes/tests/auto_play.gd +++ b/src/game/engine/scenes/tests/auto_play.gd @@ -302,6 +302,32 @@ func _pick_research(player: RefCounted) -> void: print(" Researching: %s (cost %d)" % [best_id, best_cost]) +func _score_site(pos: Vector2i, game_map: RefCounted) -> float: + ## Score a hex as a city site. Food*2 + production*1.5 + resources. + var tile: Resource = game_map.get_tile(pos) + if tile == null: + return 0.0 + var water: Array = ["ocean", "coast", "deep_ocean", "lake"] + if tile.biome_id in water: + return 0.0 + var score: float = 0.0 + var y: Dictionary = tile.get_yields(-1) + score += float(y.get("food", 0)) * 2.0 + float(y.get("production", 0)) * 1.5 + for n: Vector2i in HexUtilsScript.get_neighbors(pos): + var norm: Vector2i = HexUtilsScript.normalize_position(n, game_map.width, game_map.height, game_map.wrap_mode) + var nt: Resource = game_map.get_tile(norm) + if nt == null: + continue + if nt.biome_id in water: + score += 0.5 + continue + var ny: Dictionary = nt.get_yields(-1) + score += float(ny.get("food", 0)) * 0.5 + float(ny.get("production", 0)) * 0.3 + if nt.resource_id != "": + score += 2.0 + return score + + func _has_settler(player: RefCounted) -> bool: for u: Variant in player.units: if u.get("can_found_city") == true and u.is_alive(): @@ -362,21 +388,22 @@ func _manage_production(city: Variant) -> void: func _command_unit(unit: Variant, player: RefCounted, game_map: RefCounted) -> void: if unit.get("can_found_city") == true: - # Move settler away from existing cities, then found + # Check distance from existing cities var too_close: bool = false for c: Variant in player.cities: if HexUtilsScript.hex_distance(unit.position, c.position) < 5: too_close = true break - if too_close: + # Score current tile quality + var site_quality: float = _score_site(unit.position, game_map) + if too_close or site_quality < 3.0: _explore(unit, player, game_map) else: - # Found city here if _world_map != null and _world_map.has_method("_select_unit"): _world_map._select_unit(unit) if _world_map != null and _world_map.has_method("_on_found_city_pressed"): _world_map._on_found_city_pressed() - print(" Founded new city at %s" % unit.position) + print(" Founded city at %s (quality=%.1f)" % [unit.position, site_quality]) return var target_pos: Vector2i = _find_attack_target(player)