test(scenes): Add test cases for AI-driven auto-play city founding behavior validation

Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
autocommit 2026-04-12 23:32:26 -07:00
parent 93c27b60db
commit 25e5f8849f

View file

@ -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)