diff options
Diffstat (limited to 'apworld/rules.py')
| -rw-r--r-- | apworld/rules.py | 27 |
1 files changed, 27 insertions, 0 deletions
| diff --git a/apworld/rules.py b/apworld/rules.py new file mode 100644 index 0000000..05689e9 --- /dev/null +++ b/apworld/rules.py | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | from collections.abc import Callable | ||
| 2 | from typing import TYPE_CHECKING | ||
| 3 | |||
| 4 | from BaseClasses import CollectionState | ||
| 5 | from .player_logic import AccessRequirements | ||
| 6 | |||
| 7 | if TYPE_CHECKING: | ||
| 8 | from . import Lingo2World | ||
| 9 | |||
| 10 | |||
| 11 | def lingo2_can_satisfy_requirements(state: CollectionState, reqs: AccessRequirements, world: "Lingo2World") -> bool: | ||
| 12 | if not all(state.has(item, world.player) for item in reqs.items): | ||
| 13 | return False | ||
| 14 | |||
| 15 | if not all(state.can_reach_region(region_name, world.player) for region_name in reqs.rooms): | ||
| 16 | return False | ||
| 17 | |||
| 18 | # TODO: symbols, letters | ||
| 19 | |||
| 20 | for disjunction in reqs.or_logic: | ||
| 21 | if not any(lingo2_can_satisfy_requirements(state, sub_reqs, world) for sub_reqs in disjunction): | ||
| 22 | return False | ||
| 23 | |||
| 24 | return True | ||
| 25 | |||
| 26 | def make_location_lambda(reqs: AccessRequirements, world: "Lingo2World") -> Callable[[CollectionState], bool]: | ||
| 27 | return lambda state: lingo2_can_satisfy_requirements(state, reqs, world) | ||
