From 447a222b57e498f7904033c59e68d21d6a246abd Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Tue, 12 Aug 2025 12:33:24 -0400 Subject: Items and connections in the apworld --- apworld/rules.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 apworld/rules.py (limited to 'apworld/rules.py') 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 @@ +from collections.abc import Callable +from typing import TYPE_CHECKING + +from BaseClasses import CollectionState +from .player_logic import AccessRequirements + +if TYPE_CHECKING: + from . import Lingo2World + + +def lingo2_can_satisfy_requirements(state: CollectionState, reqs: AccessRequirements, world: "Lingo2World") -> bool: + if not all(state.has(item, world.player) for item in reqs.items): + return False + + if not all(state.can_reach_region(region_name, world.player) for region_name in reqs.rooms): + return False + + # TODO: symbols, letters + + for disjunction in reqs.or_logic: + if not any(lingo2_can_satisfy_requirements(state, sub_reqs, world) for sub_reqs in disjunction): + return False + + return True + +def make_location_lambda(reqs: AccessRequirements, world: "Lingo2World") -> Callable[[CollectionState], bool]: + return lambda state: lingo2_can_satisfy_requirements(state, reqs, world) -- cgit 1.4.1