Files
dojo_cate/tests/test_movement.py
T
eisterman 0ca905eb71 Speed up the simulator 5-7x with identical games (6.10)
Precompute board adjacency and square sets, look up opponents once per
move, and cache walks that exclude only the start square. Every game is
unchanged for the same seed, checked with agents/scripts/fingerprint_games.py.
Plan: skip catch-up 6.9 (D44), stop running the random lineup (D45).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 17:02:53 +02:00

62 lines
1.9 KiB
Python

from scripted import fixture_board
from dojo.board import Board, Pos, edge
from dojo.movement import walks
BOARD = fixture_board()
def test_walks_have_exact_length_and_never_repeat_a_square() -> None:
start = Pos(4, 4)
paths = walks(BOARD, start, 4, {start}, can_enter_dojo=False)
assert paths
for path in paths:
assert len(path) == 4
assert len({start, *path}) == 5
for a, b in zip((start, *path), path, strict=False):
assert b in set(BOARD.neighbours(a))
def test_visited_squares_are_never_entered() -> None:
start = Pos(4, 4)
visited = {start, Pos(4, 5), Pos(3, 4)}
paths = walks(BOARD, start, 3, visited, can_enter_dojo=False)
assert all(not visited & set(path) for path in paths)
def test_dojo_is_a_wall_unless_it_may_be_entered() -> None:
start = Pos(4, 7)
closed = walks(BOARD, start, 5, {start}, can_enter_dojo=False)
opened = walks(BOARD, start, 5, {start}, can_enter_dojo=True)
assert not any(BOARD.dojo & set(path) for path in closed)
into_dojo = [path for path in opened if path[-1] in BOARD.dojo]
assert (Pos(5, 7), Pos(6, 7)) in into_dojo
assert all(cell not in BOARD.dojo for path in into_dojo for cell in path[:-1])
assert set(opened) - set(into_dojo) == set(closed)
def test_boxed_in_pawn_moves_as_far_as_possible() -> None:
walls = frozenset(edge(Pos(0, c), Pos(1, c)) for c in range(3))
corridor = Board(cells=((".",) * 3,) * 3, walls=walls, tunnels={})
paths = walks(corridor, Pos(0, 0), 5, {Pos(0, 0)}, can_enter_dojo=False)
assert paths == [(Pos(0, 1), Pos(0, 2))]
def test_reused_walks_match_a_fresh_search_and_are_independent_copies() -> None:
start = Pos(4, 4)
off_board = Pos(-1, -1)
walks(BOARD, start, 6, {start}, can_enter_dojo=True).clear()
reused = walks(BOARD, start, 6, {start}, can_enter_dojo=True)
assert reused
assert reused == walks(BOARD, start, 6, {start, off_board}, can_enter_dojo=True)