diff --git a/src/game/engine/scenes/tests/auto_play.gd b/src/game/engine/scenes/tests/auto_play.gd index ccf56754..8585b009 100644 --- a/src/game/engine/scenes/tests/auto_play.gd +++ b/src/game/engine/scenes/tests/auto_play.gd @@ -495,13 +495,26 @@ func _find_attack_target(player: RefCounted) -> Vector2i: var best_pos: Vector2i = Vector2i(-1, -1) var best_dist: int = 999 - # Target nearest enemy city (skip pathfinding — just use hex distance) + # Target nearest enemy city — try pathfinding first, fall back to hex distance for p: Variant in GameState.players: if p.index == player.index: continue for c: Variant in p.cities: var dist: int = HexUtilsScript.hex_distance(my_pos, c.position) if dist < best_dist: + # Verify reachable by land (short budget to avoid wraparound issues) + if game_map != null: + var reachable: Dictionary = PathfinderScript.movement_range( + game_map, my_pos, dist + 5, "land" + ) + # Check if any reachable hex is within 2 of the target + var can_reach: bool = false + for rpos: Vector2i in reachable: + if HexUtilsScript.hex_distance(rpos, c.position) <= 2: + can_reach = true + break + if not can_reach: + continue best_dist = dist best_pos = c.position