# tests/engine/test_turn_order.py """predator-first reorders the turn: advance_threat sees the focal's PRE-move cell.""" import random from proteus.game.engine.difficulty import Difficulty from proteus.game.engine.grid import MotiveGridGame from proteus.game.scenarios.base import get_scenario import proteus.game.scenarios # noqa: F401 (register scenarios) def _focal_cell_seen_by_threat(turn_order: str, action: str = "up"): scen = get_scenario("template")() scen.turn_order = turn_order # instance override game = MotiveGridGame(scen, random.Random(0), Difficulty.EASY, max_steps=10) seen = {} real_advance = scen.advance_threat def spy(g): f = g.focal_sprite seen["focal"] = (f.x, f.y) real_advance(g) scen.advance_threat = spy # shadow the bound method on this instance before = (game.focal_sprite.x, game.focal_sprite.y) game.apply_motive_action(action) return before, seen["focal"] def test_predator_first_threat_sees_premove_focal(): before, seen = _focal_cell_seen_by_threat("predator_first", "up") assert seen == before # predator advanced BEFORE the focal moved def test_focal_first_threat_sees_postmove_focal(): before, seen = _focal_cell_seen_by_threat("focal_first", "up") assert seen != before # legacy: focal moved first, predator chased the new cell