Spaces:
Runtime error
Runtime error
Commit ·
1debdd3
1
Parent(s): 93cd78f
test(template): restore generic eliminated-outcome + blocked step_reward coverage
Browse files- tests/grid/test_step_reward.py +14 -0
- tests/runtime/test_session.py +16 -0
tests/grid/test_step_reward.py
CHANGED
|
@@ -3,6 +3,7 @@ import random
|
|
| 3 |
from proteus.game.engine.difficulty import Difficulty
|
| 4 |
from proteus.game.engine.grid import MotiveGridGame
|
| 5 |
from proteus.game.scenarios.base import get_scenario
|
|
|
|
| 6 |
|
| 7 |
|
| 8 |
def _start():
|
|
@@ -34,6 +35,19 @@ def test_step_reward_negative_when_moving_toward():
|
|
| 34 |
assert r < 0
|
| 35 |
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
def test_safety_distance_is_distance_focal_to_predator():
|
| 38 |
game, s = _start()
|
| 39 |
d = s.safety_distance(game)
|
|
|
|
| 3 |
from proteus.game.engine.difficulty import Difficulty
|
| 4 |
from proteus.game.engine.grid import MotiveGridGame
|
| 5 |
from proteus.game.scenarios.base import get_scenario
|
| 6 |
+
from proteus.game.scenarios.template import _REWARD_EDGE_BLOCK
|
| 7 |
|
| 8 |
|
| 9 |
def _start():
|
|
|
|
| 35 |
assert r < 0
|
| 36 |
|
| 37 |
|
| 38 |
+
def test_step_reward_negative_on_blocked_move():
|
| 39 |
+
# Generic property: a blocked move (footprint hits a wall/edge) is penalised
|
| 40 |
+
# via the _REWARD_EDGE_BLOCK branch, regardless of geometry. This is the only
|
| 41 |
+
# test exercising the blocked=True path.
|
| 42 |
+
game, s = _start()
|
| 43 |
+
focal_before = (game.focal_sprite.x, game.focal_sprite.y)
|
| 44 |
+
predator_before = (game.predator_sprite.x, game.predator_sprite.y)
|
| 45 |
+
r = s.step_reward(game, "left", blocked=True,
|
| 46 |
+
focal_before=focal_before, predator_before=predator_before)
|
| 47 |
+
assert r < 0
|
| 48 |
+
assert r == _REWARD_EDGE_BLOCK
|
| 49 |
+
|
| 50 |
+
|
| 51 |
def test_safety_distance_is_distance_focal_to_predator():
|
| 52 |
game, s = _start()
|
| 53 |
d = s.safety_distance(game)
|
tests/runtime/test_session.py
CHANGED
|
@@ -59,6 +59,22 @@ def test_short_budget_yields_survived_outcome():
|
|
| 59 |
assert trace.turns[-1].reward == 50.0 # _REWARD_SURVIVED
|
| 60 |
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
def test_cut_frames_count_matches_cut_length_plus_one():
|
| 63 |
from proteus.game.engine.difficulty import Difficulty
|
| 64 |
from proteus.game.scenarios.base import get_scenario
|
|
|
|
| 59 |
assert trace.turns[-1].reward == 50.0 # _REWARD_SURVIVED
|
| 60 |
|
| 61 |
|
| 62 |
+
def test_eliminated_outcome_is_explicit_and_terminal():
|
| 63 |
+
# Generic property: the engine can drive a focal into capture and the
|
| 64 |
+
# outcome is the explicit, terminal "eliminated". On template the predator
|
| 65 |
+
# waits far to the east, so an agent that always charges "right" walks into
|
| 66 |
+
# it; the session must end on capture (before the budget is spent) and pay
|
| 67 |
+
# the capture penalty.
|
| 68 |
+
agent = _agent(["ACTION: right"])
|
| 69 |
+
trace = SessionRunner(
|
| 70 |
+
"template", agent, seed=0, play_turns=40, use_probe=False,
|
| 71 |
+
).run()
|
| 72 |
+
assert trace.outcome == "eliminated"
|
| 73 |
+
# Terminal: the run stopped on elimination rather than exhausting the budget.
|
| 74 |
+
assert len(trace.turns) < 40
|
| 75 |
+
assert trace.turns[-1].reward == -50.0 # _REWARD_CAPTURED
|
| 76 |
+
|
| 77 |
+
|
| 78 |
def test_cut_frames_count_matches_cut_length_plus_one():
|
| 79 |
from proteus.game.engine.difficulty import Difficulty
|
| 80 |
from proteus.game.scenarios.base import get_scenario
|