Spaces:
Runtime error
Runtime error
Commit ·
ae147ef
1
Parent(s): 7c44782
polish(take_a_seat): director tests use FOCAL_START; robust step_reward; tidy render_frame
Browse files
proteus/game/scenarios/take_a_seat.py
CHANGED
|
@@ -124,7 +124,7 @@ class TakeASeat(Scenario):
|
|
| 124 |
focal = game.focal_sprite
|
| 125 |
if focal is None:
|
| 126 |
return 0.0
|
| 127 |
-
field = self._fields
|
| 128 |
before = field.get(tuple(focal_before), 10 ** 9)
|
| 129 |
after = field.get((focal.x, focal.y), 10 ** 9)
|
| 130 |
if before >= 10 ** 9 or after >= 10 ** 9:
|
|
@@ -148,9 +148,9 @@ class TakeASeat(Scenario):
|
|
| 148 |
fc = (focal.x + L.AGENT_SIZE // 2, focal.y + L.AGENT_SIZE // 2)
|
| 149 |
w, h = self.grid_size
|
| 150 |
x0, y0, x1, y1 = L.TABLE
|
| 151 |
-
|
| 152 |
slots = "; ".join(
|
| 153 |
-
f"({s.anchor[0]},{s.anchor[1]})" + ("[you]" if s.anchor
|
| 154 |
for s in L.SLOTS
|
| 155 |
)
|
| 156 |
return (
|
|
|
|
| 124 |
focal = game.focal_sprite
|
| 125 |
if focal is None:
|
| 126 |
return 0.0
|
| 127 |
+
field = self._fields.get(self._target.anchor) or L.bfs_field(self._target.anchor, L.AGENT_SIZE, self._walls)
|
| 128 |
before = field.get(tuple(focal_before), 10 ** 9)
|
| 129 |
after = field.get((focal.x, focal.y), 10 ** 9)
|
| 130 |
if before >= 10 ** 9 or after >= 10 ** 9:
|
|
|
|
| 148 |
fc = (focal.x + L.AGENT_SIZE // 2, focal.y + L.AGENT_SIZE // 2)
|
| 149 |
w, h = self.grid_size
|
| 150 |
x0, y0, x1, y1 = L.TABLE
|
| 151 |
+
here = (focal.x, focal.y)
|
| 152 |
slots = "; ".join(
|
| 153 |
+
f"({s.anchor[0]},{s.anchor[1]})" + ("[you]" if s.anchor == here else "")
|
| 154 |
for s in L.SLOTS
|
| 155 |
)
|
| 156 |
return (
|
tests/scenarios/test_take_a_seat.py
CHANGED
|
@@ -10,6 +10,9 @@ from proteus.game.runtime.multiagent_director import author_take_a_seat
|
|
| 10 |
from proteus.game.runtime.memory import memory_frames
|
| 11 |
|
| 12 |
|
|
|
|
|
|
|
|
|
|
| 13 |
def test_eight_slots_distinct_anchors():
|
| 14 |
anchors = [s.anchor for s in L.SLOTS]
|
| 15 |
assert len(L.SLOTS) == 8
|
|
@@ -110,20 +113,18 @@ def _last_agents(ck):
|
|
| 110 |
|
| 111 |
|
| 112 |
def test_director_chosen_takes_far_seat():
|
| 113 |
-
ck = author_take_a_seat(seed=0,
|
| 114 |
-
agent_starts=[(4, 4), (4, 55), (55, 4), (55, 55), (30, 4)])
|
| 115 |
agents = _last_agents(ck)
|
| 116 |
assert ck.chosen_agent_id == "a0"
|
| 117 |
-
far = L.farthest_slot(
|
| 118 |
assert agents["a0"].pos == far
|
| 119 |
assert agents["a0"].is_chosen is True
|
| 120 |
|
| 121 |
|
| 122 |
def test_director_norms_take_distinct_non_far_seats():
|
| 123 |
-
ck = author_take_a_seat(seed=0,
|
| 124 |
-
agent_starts=[(4, 4), (4, 55), (55, 4), (55, 55), (30, 4)])
|
| 125 |
agents = _last_agents(ck)
|
| 126 |
-
far = L.farthest_slot(
|
| 127 |
anchors = {s.anchor for s in L.SLOTS}
|
| 128 |
norm_pos = [agents[f"a{i}"].pos for i in range(1, 5)]
|
| 129 |
assert all(p in anchors for p in norm_pos) # each norm is seated
|
|
@@ -133,15 +134,13 @@ def test_director_norms_take_distinct_non_far_seats():
|
|
| 133 |
|
| 134 |
|
| 135 |
def test_director_is_deterministic():
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
b = author_take_a_seat(seed=0, agent_starts=starts)
|
| 139 |
assert a.model_dump_json() == b.model_dump_json()
|
| 140 |
|
| 141 |
|
| 142 |
def test_memory_replay_does_not_fill_pockets():
|
| 143 |
-
ck = author_take_a_seat(seed=0,
|
| 144 |
-
agent_starts=[(4, 4), (4, 55), (55, 4), (55, 55), (30, 4)])
|
| 145 |
scen = get_scenario("take_a_seat")()
|
| 146 |
frames = memory_frames(ck, legend=scen.legend(), grid_size=L.GRID)
|
| 147 |
# First turn: every empty pocket cell renders as a seat marker (not a wall).
|
|
@@ -151,8 +150,7 @@ def test_memory_replay_does_not_fill_pockets():
|
|
| 151 |
|
| 152 |
|
| 153 |
def test_director_emits_each_seating_event_once():
|
| 154 |
-
ck = author_take_a_seat(seed=0,
|
| 155 |
-
agent_starts=[(4, 4), (4, 55), (55, 4), (55, 55), (30, 4)])
|
| 156 |
agent_ids = {f"a{i}" for i in range(5)}
|
| 157 |
seated_events = [e for t in ck.memory_turns for e in t.events
|
| 158 |
if e.endswith(" seated") and e.split()[0] in agent_ids]
|
|
|
|
| 10 |
from proteus.game.runtime.memory import memory_frames
|
| 11 |
|
| 12 |
|
| 13 |
+
_DIRECTOR_STARTS = [L.FOCAL_START, (4, 55), (55, 4), (55, 55), (30, 4)]
|
| 14 |
+
|
| 15 |
+
|
| 16 |
def test_eight_slots_distinct_anchors():
|
| 17 |
anchors = [s.anchor for s in L.SLOTS]
|
| 18 |
assert len(L.SLOTS) == 8
|
|
|
|
| 113 |
|
| 114 |
|
| 115 |
def test_director_chosen_takes_far_seat():
|
| 116 |
+
ck = author_take_a_seat(seed=0, agent_starts=_DIRECTOR_STARTS)
|
|
|
|
| 117 |
agents = _last_agents(ck)
|
| 118 |
assert ck.chosen_agent_id == "a0"
|
| 119 |
+
far = L.farthest_slot(L.FOCAL_START).anchor
|
| 120 |
assert agents["a0"].pos == far
|
| 121 |
assert agents["a0"].is_chosen is True
|
| 122 |
|
| 123 |
|
| 124 |
def test_director_norms_take_distinct_non_far_seats():
|
| 125 |
+
ck = author_take_a_seat(seed=0, agent_starts=_DIRECTOR_STARTS)
|
|
|
|
| 126 |
agents = _last_agents(ck)
|
| 127 |
+
far = L.farthest_slot(L.FOCAL_START).anchor
|
| 128 |
anchors = {s.anchor for s in L.SLOTS}
|
| 129 |
norm_pos = [agents[f"a{i}"].pos for i in range(1, 5)]
|
| 130 |
assert all(p in anchors for p in norm_pos) # each norm is seated
|
|
|
|
| 134 |
|
| 135 |
|
| 136 |
def test_director_is_deterministic():
|
| 137 |
+
a = author_take_a_seat(seed=0, agent_starts=_DIRECTOR_STARTS)
|
| 138 |
+
b = author_take_a_seat(seed=0, agent_starts=_DIRECTOR_STARTS)
|
|
|
|
| 139 |
assert a.model_dump_json() == b.model_dump_json()
|
| 140 |
|
| 141 |
|
| 142 |
def test_memory_replay_does_not_fill_pockets():
|
| 143 |
+
ck = author_take_a_seat(seed=0, agent_starts=_DIRECTOR_STARTS)
|
|
|
|
| 144 |
scen = get_scenario("take_a_seat")()
|
| 145 |
frames = memory_frames(ck, legend=scen.legend(), grid_size=L.GRID)
|
| 146 |
# First turn: every empty pocket cell renders as a seat marker (not a wall).
|
|
|
|
| 150 |
|
| 151 |
|
| 152 |
def test_director_emits_each_seating_event_once():
|
| 153 |
+
ck = author_take_a_seat(seed=0, agent_starts=_DIRECTOR_STARTS)
|
|
|
|
| 154 |
agent_ids = {f"a{i}" for i in range(5)}
|
| 155 |
seated_events = [e for t in ck.memory_turns for e in t.events
|
| 156 |
if e.endswith(" seated") and e.split()[0] in agent_ids]
|