def _all_assignments()

in textworld/logic/__init__.py [0:0]


    def _all_assignments(self,
                         placeholders: List[Placeholder],
                         mapping: Dict[Placeholder, Variable],
                         used_vars: Set[Variable],
                         partial: bool,
                         allow_partial: Callable[[Placeholder], bool] = None,
                         ) -> Iterable[Mapping[Placeholder, Optional[Variable]]]:
        """
        Find all possible assignments of the given placeholders, without regard to whether any predicates match.
        """

        if allow_partial is None:
            allow_partial = lambda ph: True  # noqa: E731

        candidates = []
        for ph in placeholders:
            matched_vars = set()
            for type in self._logic.types.get(ph.type).subtypes:
                matched_vars |= self.variables_of_type(type.name)
            matched_vars -= used_vars
            if partial and allow_partial(ph):
                # Allow new variables to be created
                matched_vars.add(ph)
            candidates.append(list(matched_vars))

        for assignment in unique_product(*candidates):
            for ph, var in zip(placeholders, assignment):
                if var == ph:
                    mapping[ph] = None
                elif var not in used_vars:
                    mapping[ph] = var
                    used_vars.add(var)
                else:
                    # Distinct placeholders can't be assigned the same variable
                    break
            else:
                yield mapping.copy()

            for ph in placeholders:
                used_vars.discard(mapping.get(ph))

        for ph in placeholders:
            mapping.pop(ph, None)