in textworld/generator/chaining.py [0:0]
def backtrack(self, node: _Node) -> Iterable[_Node]:
"""
Backtrack to earlier choices to generate parallel quests.
"""
if node.breadth >= self.max_breadth or node.length >= self.max_length:
return
parent = node
parents = []
while parent.dep_parent:
if parent.depth == 1 and not self.options.independent_chains:
break
parents.append(parent)
parent = parent.dep_parent
parents = parents[::-1]
for sibling in parents:
parent = sibling.dep_parent
rules = self.options.get_rules(parent.depth)
assignments = self.all_assignments(node, rules)
if self.rng:
self.rng.shuffle(assignments)
for partial in assignments:
action = self.try_instantiate(node.state, partial)
if not action:
continue
if action in sibling.used:
continue
if not self.check_action(parent, node.state, action):
continue
state = self.apply(node, action)
if not state:
continue
used = sibling.used | {action}
yield _Node(node, parent, state, action, rules, used, node.breadth + 1)