Exemplo n.º 1
0
    def test_failed(self):
        quest = QuestProgression(self.quest, KnowledgeBase.default())
        quest = self._apply_actions_to_quest(self.eating_carrot.actions, quest)
        assert not quest.completed
        assert quest.failed
        assert quest.winning_policy is None

        quest = QuestProgression(self.quest, KnowledgeBase.default())
        quest = self._apply_actions_to_quest(self.eating_lettuce.actions, quest)
        assert not quest.completed
        assert quest.failed
        assert quest.winning_policy is None
Exemplo n.º 2
0
    def test_completed(self):
        quest = QuestProgression(self.quest, KnowledgeBase.default())
        quest = self._apply_actions_to_quest(self.eventA.actions, quest)
        assert quest.completed
        assert not quest.failed
        assert quest.winning_policy is None

        # Alternative winning strategy.
        quest = QuestProgression(self.quest, KnowledgeBase.default())
        quest = self._apply_actions_to_quest(self.eventB.actions, quest)
        assert quest.completed
        assert not quest.failed
        assert quest.winning_policy is None
Exemplo n.º 3
0
    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
Exemplo n.º 4
0
    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
Exemplo n.º 5
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:]
Exemplo n.º 6
0
 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:]