def check_state(self, state: State) -> bool: """Check that a state satisfies the constraints.""" fail = Proposition("fail", []) constraints = state.all_applicable_actions(self.constraints) for constraint in constraints: if state.is_applicable(constraint): # Optimistically delay copying the state copy = state.copy() copy.apply(constraint) if copy.is_fact(fail): return False return True
def is_triggering(self, state: State) -> bool: """ Check if this event would be triggered in a given state. """ return state.is_applicable(self.condition)
def has_failed(self, state: State) -> bool: """ Check whether the quest has failed. """ if self._quest.fail_action is None: return False return state.is_applicable(self._quest.fail_action)
def is_completed(self, state: State) -> bool: """ Check whether the quest is completed. """ return state.is_applicable(self._quest.win_action)