about summary refs log tree commit diff stats
path: root/apworld/rules.py
blob: 0bff05649b8fe1f0b34095fcd89fcb522553811e (plain) (blame)
1
2
3
4
5
6pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc00
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.has(item, world.player, amount) for item, amount in reqs.progressives.items()):
        return False

    if not all(state.can_reach_region(region_name, world.player) for region_name in reqs.rooms):
        return False

    for letter_key, letter_level in reqs.letters.items():
        if not state.has(letter_key, world.player, letter_level):
            return False

    if reqs.cyans:
        if not any(state.has(letter, world.player, amount)
                   for letter, amount in world.player_logic.double_letter_amount.items()):
            return False

    if len(reqs.or_logic) > 0:
        if not all(any(lingo2_can_satisfy_requirements(state, sub_reqs, world) for sub_reqs in subjunction)
                   for subjunction in reqs.or_logic):
            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)