Spaces:
Runtime error
Runtime error
| # tests/runtime/test_director_no_overlap.py | |
| """Authored memory must never show two ALIVE agents with overlapping footprints. | |
| Agent movement in the director only checked grid bounds, never collisions with | |
| other agents, so two agents' NxN footprints could overlap in a rendered frame. | |
| This is a physics bug: agents are solid bodies. The predator is exempt | |
| (overlap with a distractor is the kill mechanic). | |
| """ | |
| import pytest | |
| from proteus.game.runtime.multiagent_director import ( | |
| author_predator_chase, | |
| author_resource_race, | |
| ) | |
| _PRED_STARTS = [(10, 30), (14, 38), (18, 24), (12, 46)] | |
| _PRED = (54, 31) | |
| _RES_STARTS = [(8, 52), (20, 10), (40, 50), (55, 20), (30, 30)] | |
| _RES = (54, 12) | |
| _SEEDS = (0, 3, 7) | |
| def _footprints_overlap(ax, ay, asz, bx, by, bsz): | |
| return ax < bx + bsz and bx < ax + asz and ay < by + bsz and by < ay + asz | |
| def _first_agent_overlap(ck): | |
| """Return (turn_idx, id_a, id_b) of the first alive agent-agent overlap, or None.""" | |
| for t in ck.memory_turns: | |
| live = [a for a in t.agents if a.kind == "agent" and a.alive] | |
| for i in range(len(live)): | |
| for j in range(i + 1, len(live)): | |
| a, b = live[i], live[j] | |
| if _footprints_overlap( | |
| a.pos[0], a.pos[1], a.size, b.pos[0], b.pos[1], b.size | |
| ): | |
| return (t.turn_idx, a.id, b.id) | |
| return None | |
| def test_predator_chase_no_agent_overlap(seed): | |
| ck = author_predator_chase( | |
| seed=seed, agent_starts=_PRED_STARTS, predator_start=_PRED | |
| ) | |
| overlap = _first_agent_overlap(ck) | |
| assert overlap is None, f"agent overlap at turn {overlap}" | |
| def test_resource_race_no_agent_overlap(seed): | |
| ck = author_resource_race(seed=seed, agent_starts=_RES_STARTS, resource=_RES) | |
| overlap = _first_agent_overlap(ck) | |
| assert overlap is None, f"agent overlap at turn {overlap}" | |