File size: 2,490 Bytes
a629d19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# 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"] == []