def test_winning_policy(self): kb = KnowledgeBase.default() quest = QuestProgression(self.quest, kb) quest = self._apply_actions_to_quest(quest.winning_policy, quest) assert quest.completed assert not quest.failed assert quest.winning_policy is None # Winning policy should be the shortest one leading to a winning event. state = self.game.world.state.copy() quest = QuestProgression(self.quest, KnowledgeBase.default()) for i, action in enumerate(self.eventB.actions): if i < 2: assert quest.winning_policy == self.eventA.actions else: # After taking the lettuce and putting it in the chest, # QuestB becomes the shortest one to complete. assert quest.winning_policy == self.eventB.actions[i:] assert not quest.done state.apply(action) quest.update(action, state) assert quest.done assert quest.completed assert not quest.failed assert quest.winning_policy is None
def test_failing_quest(self): quest = QuestProgression(self.quest, KnowledgeBase.default()) state = self.game.state.copy() for action in self.eating_quest.actions: state.apply(action) if action.name.startswith("eat"): quest.update(action, state) assert len(quest.winning_policy) == 0 assert quest.done assert not quest.completed assert not quest.failed assert quest.unfinishable break assert not quest.done assert len(quest.winning_policy) > 0
def test_winning_policy(self): quest = QuestProgression(self.quest) assert quest.winning_policy == self.quest.actions quest.update(self.quest.actions[0]) assert quest.winning_policy == self.quest.actions[1:]
def test_winning_policy(self): quest = QuestProgression(self.quest, KnowledgeBase.default()) assert quest.winning_policy == self.quest.actions quest.update(self.quest.actions[0], state=State()) assert tuple(quest.winning_policy) == self.quest.actions[1:]