test(@projects/@magic-civilization): ⛵ p3-18 P5b — GUT proof the rendered pathfinder embark gate works
test_pathfinder_embark.gd: over an ocean-column map, a land unit finds no path without embark (embark_level 0), fords the column with embark (level > 0) and reaches the far landmass; naval movement is unaffected by the embark arg. Verified headless against the rebuilt dylib: GUT 732 passing / 0 failed (+3 from 729 — these tests; no regression). UI embark now matches the authoritative headless sim. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
7d40c2ce86
commit
b02274f920
1 changed files with 53 additions and 0 deletions
53
src/game/engine/tests/unit/test_pathfinder_embark.gd
Normal file
53
src/game/engine/tests/unit/test_pathfinder_embark.gd
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
extends GutTest
|
||||
## p3-18 — the rendered pathfinder (`pathfinder.gd`) lets a land unit enter water
|
||||
## only when its owner can embark (`embark_level > 0`). The embark level itself is
|
||||
## computed in Rust (`GdTechWeb.embark_level`, data-driven from tech mechanics);
|
||||
## this verifies the thin GDScript gate consumes it so UI movement matches the
|
||||
## authoritative headless sim's embark rule.
|
||||
|
||||
const GameMapScript: GDScript = preload("res://engine/src/map/game_map.gd")
|
||||
const TileScript: GDScript = preload("res://engine/src/map/tile.gd")
|
||||
const PathfinderScript: GDScript = preload("res://engine/src/map/pathfinder.gd")
|
||||
|
||||
|
||||
## A vertical ocean wall: col 0 land | col 1 ocean (all rows) | col 2 land. Any
|
||||
## path from col 0 to col 2 must cross the ocean column.
|
||||
func _ocean_wall_map() -> GameMap:
|
||||
var m: GameMap = GameMapScript.new()
|
||||
m.initialize(3, 3, 0) # WrapMode.NONE
|
||||
for q: int in range(3):
|
||||
for r: int in range(3):
|
||||
var t: Tile = TileScript.new()
|
||||
t.position = Vector2i(q, r)
|
||||
t.biome_id = "ocean" if q == 1 else "plains"
|
||||
m.tiles[Vector2i(q, r)] = t
|
||||
return m
|
||||
|
||||
|
||||
func test_land_unit_blocked_by_water_without_embark() -> void:
|
||||
var m: GameMap = _ocean_wall_map()
|
||||
var path: Array[Vector2i] = PathfinderScript.find_path(
|
||||
m, Vector2i(0, 0), Vector2i(2, 0), 20, "land", 0
|
||||
)
|
||||
assert_eq(path.size(), 0, "no embark → the ocean column blocks the land unit")
|
||||
|
||||
|
||||
func test_land_unit_crosses_water_with_embark() -> void:
|
||||
var m: GameMap = _ocean_wall_map()
|
||||
var path: Array[Vector2i] = PathfinderScript.find_path(
|
||||
m, Vector2i(0, 0), Vector2i(2, 0), 20, "land", 1
|
||||
)
|
||||
assert_gt(path.size(), 0, "embark_level > 0 → land unit fords the ocean column")
|
||||
assert_eq(
|
||||
path[path.size() - 1], Vector2i(2, 0), "embarked land unit reaches the far landmass"
|
||||
)
|
||||
|
||||
|
||||
func test_naval_unit_ignores_embark_level() -> void:
|
||||
# Naval movement is unchanged by the embark arg (it always needs water).
|
||||
var m: GameMap = _ocean_wall_map()
|
||||
# A naval unit can sit on / traverse the ocean column regardless of embark.
|
||||
var on_water: Array[Vector2i] = PathfinderScript.find_path(
|
||||
m, Vector2i(1, 0), Vector2i(1, 2), 20, "naval", 0
|
||||
)
|
||||
assert_gt(on_water.size(), 0, "naval unit traverses water with embark_level 0")
|
||||
Loading…
Add table
Reference in a new issue