Spaces:
Sleeping
Sleeping
| # tests/engine/test_check_success_hook.py | |
| import random | |
| from proteus.game.engine.difficulty import Difficulty | |
| from proteus.game.engine.grid import MotiveGridGame | |
| from proteus.game.scenarios.base import Scenario, get_scenario | |
| import proteus.game.scenarios # noqa: F401 | |
| def test_default_check_success_is_false(): | |
| # Base hook is opt-in: existing scenarios never win early. | |
| scen = get_scenario("resource_race")() | |
| game = MotiveGridGame(scen, random.Random(0), Difficulty.EASY, max_steps=40) | |
| assert scen.check_success(game) is False | |
| def test_check_success_triggers_early_win(): | |
| # A scenario whose check_success returns True wins on the very first step. | |
| base = get_scenario("resource_race")() | |
| class _AlwaysWin(type(base)): # reuse a concrete scenario, override the hook | |
| def check_success(self, game): | |
| return True | |
| scen = _AlwaysWin() | |
| game = MotiveGridGame(scen, random.Random(0), Difficulty.EASY, max_steps=99) | |
| game.apply_motive_action("stay") | |
| assert game.survived is True | |
| assert game.step_count == 1 # won before the step budget | |