Spaces:
Sleeping
Sleeping
| """Scripted memory policies produce distinct, on-motive 100-turn trajectories.""" | |
| from __future__ import annotations | |
| import proteus.game.scenarios # noqa: F401 (registers scenarios) | |
| from proteus.game.engine.difficulty import Difficulty | |
| from proteus.game.runtime.memory_gen import generate_memory | |
| from proteus.game.runtime.memory_policies import ( | |
| available_policies, get_policy, | |
| ) | |
| def _run(name, seed=7): | |
| return generate_memory( | |
| "template", None, difficulty=Difficulty.EASY, seed=seed, | |
| memory_turns=100, model_name=f"policy:{name}", | |
| policy=get_policy(name), clock=lambda: "T", | |
| ) | |
| def _food_dist(pos, foods): | |
| c = (pos[0] + 1, pos[1] + 1) | |
| return min(abs(c[0] - fx) + abs(c[1] - fy) for fx, fy in foods) | |
| def test_registry_lists_three_policies(): | |
| assert available_policies() == ["food_rush", "survival_dynamic", "survival_refuge"] | |
| def test_survival_dynamic_keeps_moving(): | |
| ck = _run("survival_dynamic") | |
| acts = [t.action for t in ck.memory_turns] | |
| moved = sum(1 for a in acts if a != "stay") | |
| assert len(acts) == 100 and ck.outcome == "survived" | |
| assert moved >= 90, "dynamic evasion should keep moving, not freeze" | |
| def test_survival_refuge_reaches_a_refuge_and_stays(): | |
| ck = _run("survival_refuge") | |
| acts = [t.action for t in ck.memory_turns] | |
| assert ck.outcome == "survived" | |
| assert acts[-5:] == ["stay"] * 5, "should settle in a refuge and stop moving" | |
| assert sum(1 for a in acts if a != "stay") >= 1, "but it does move to get there first" | |
| def test_food_rush_approaches_food_ignoring_predator(): | |
| ck = _run("food_rush") | |
| foods = ck.food_cells | |
| start = _food_dist(ck.memory_turns[0].focal_pos, foods) | |
| end = _food_dist(ck.memory_turns[-1].focal_pos, foods) | |
| assert end < start, "food-rush should close distance to the nearest food" | |
| def test_unknown_policy_raises(): | |
| import pytest | |
| with pytest.raises(KeyError): | |
| get_policy("bogus") | |