Spaces:
Sleeping
Sleeping
| # tests/runtime/test_memory_frames_overlay.py | |
| """errand_runner memory render: generic `cells` overlay + npc agent colours. | |
| Legacy turns (no cells, kind in {agent,predator}) stay byte-identical. | |
| """ | |
| from proteus.game.runtime.memory import ( | |
| AgentFrame, MemoryCheckpoint, MemoryTurn, memory_frames, | |
| ) | |
| _LEGEND = {5: ".", 1: "A", 2: "B", 3: "#", 14: "F"} | |
| _GRID = (12, 12) | |
| def _ck(turn): | |
| return MemoryCheckpoint( | |
| model="m", scenario="errand_runner", difficulty="easy", created_at="x", | |
| outcome="survived", transparent_prompt="p", memory_turns=[turn], | |
| ) | |
| def test_cells_overlay_painted_over_background(): | |
| turn = MemoryTurn( | |
| turn_idx=1, frame_ascii="", action="up", focal_pos=(0, 0), predator_pos=(0, 0), | |
| agents=[AgentFrame(id="a0", kind="agent", pos=(0, 0), size=2)], | |
| cells=[(7, 3, 8), (7, 4, 8), (7, 5, 8)], # red (8) traffic-light bar | |
| ) | |
| grid = memory_frames(_ck(turn), legend=_LEGEND, grid_size=_GRID)[0]["grid"] | |
| assert grid[3][7] == 8 and grid[4][7] == 8 and grid[5][7] == 8 | |
| def test_agents_paint_over_cells(): | |
| # A candidate body on a road cell must render as the body, not the road. | |
| turn = MemoryTurn( | |
| turn_idx=1, frame_ascii="", action="up", focal_pos=(0, 0), predator_pos=(0, 0), | |
| agents=[AgentFrame(id="a0", kind="agent", pos=(2, 2), size=2, is_chosen=True)], | |
| cells=[(2, 2, 3)], # neutral road under the agent's top-left cell | |
| ) | |
| grid = memory_frames(_ck(turn), legend=_LEGEND, grid_size=_GRID)[0]["grid"] | |
| assert grid[2][2] == 1 # focal colour wins over the overlay | |
| def test_npc_down_is_yellow_and_active_is_green(): | |
| turn = MemoryTurn( | |
| turn_idx=1, frame_ascii="", action="up", focal_pos=(0, 0), predator_pos=(0, 0), | |
| agents=[ | |
| AgentFrame(id="ped", kind="npc_down", pos=(2, 2), size=2), | |
| AgentFrame(id="ped2", kind="npc_active", pos=(8, 8), size=2), | |
| ], | |
| ) | |
| grid = memory_frames(_ck(turn), legend=_LEGEND, grid_size=_GRID)[0]["grid"] | |
| assert grid[2][2] == 11 # npc_down -> yellow | |
| assert grid[8][8] == 14 # npc_active -> green | |
| def test_legacy_turn_without_cells_unaffected(): | |
| turn = MemoryTurn(turn_idx=1, frame_ascii="", action="up", focal_pos=(0, 0), | |
| predator_pos=(0, 0), | |
| agents=[AgentFrame(id="a0", kind="agent", pos=(0, 0), size=2)]) | |
| out = memory_frames(_ck(turn), legend=_LEGEND, grid_size=_GRID)[0] | |
| assert "grid" in out and out["events"] == [] | |