Spaces:
Runtime error
Runtime error
Commit ·
e902aac
1
Parent(s): f9924aa
test(cp6): lock optimal!=habit handover invariant for all difficulty bands
Browse files
tests/grid/test_difficulty_layouts.py
CHANGED
|
@@ -62,3 +62,35 @@ def test_each_band_is_deterministic():
|
|
| 62 |
g1, _ = _game(d, seed=7)
|
| 63 |
g2, _ = _game(d, seed=7)
|
| 64 |
assert np.array_equal(g1.current_grid(), g2.current_grid())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
g1, _ = _game(d, seed=7)
|
| 63 |
g2, _ = _game(d, seed=7)
|
| 64 |
assert np.array_equal(g1.current_grid(), g2.current_grid())
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
def _drive_to_handover(difficulty, seed=42):
|
| 68 |
+
"""Replay the Cut pre-roll (scripted 'left') to the handover state."""
|
| 69 |
+
s = _scenario()
|
| 70 |
+
game = MotiveGridGame(s, random.Random(seed), difficulty, max_steps=40)
|
| 71 |
+
for _ in range(s.cut_length(difficulty)):
|
| 72 |
+
action = s.cut_focal_policy(game)
|
| 73 |
+
game.apply_motive_action(action)
|
| 74 |
+
s.record_focal_move(action)
|
| 75 |
+
return game, s
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def test_invariant_optimal_differs_from_habit_each_band():
|
| 79 |
+
# The whole discrimination metric depends on optimal != habit at the Cut
|
| 80 |
+
# handover, for EVERY difficulty band.
|
| 81 |
+
for d in _BANDS:
|
| 82 |
+
game, s = _drive_to_handover(d)
|
| 83 |
+
optimal = s.optimal_action(game)
|
| 84 |
+
habit = s.habit_action(game)
|
| 85 |
+
assert optimal != habit, f"{d}: optimal {optimal} == habit {habit}"
|
| 86 |
+
# Habit ('left', the pre-roll direction) must be trapped: moving left
|
| 87 |
+
# is blocked (a wall) so it does not increase distance.
|
| 88 |
+
assert habit == "left"
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
def test_handover_is_deterministic_each_band():
|
| 92 |
+
for d in _BANDS:
|
| 93 |
+
g1, s1 = _drive_to_handover(d, seed=11)
|
| 94 |
+
g2, s2 = _drive_to_handover(d, seed=11)
|
| 95 |
+
assert (g1.focal_sprite.x, g1.focal_sprite.y) == (g2.focal_sprite.x, g2.focal_sprite.y)
|
| 96 |
+
assert (g1.predator_sprite.x, g1.predator_sprite.y) == (g2.predator_sprite.x, g2.predator_sprite.y)
|