Skip to content

Commit

Permalink
Only consider quest with win events when checking for quest completion
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcCote committed Feb 13, 2019
1 parent 76b7060 commit a3d8db6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
9 changes: 7 additions & 2 deletions textworld/generator/game.py
Expand Up @@ -803,6 +803,11 @@ def winning_policy(self) -> Optional[List[Action]]:

return min(winning_policies, key=lambda policy: len(policy))

@property
def completable(self) -> bool:
""" Check if the quest has winning events. """
return len(self.win_events) > 0

@property
def done(self) -> bool:
""" Check if the quest is done (i.e. completed, failed or unfinishable). """
Expand Down Expand Up @@ -872,7 +877,7 @@ def completed(self) -> bool:
if not self.tracking_quests:
return False # There is nothing to be "completed".

return all(qp.completed for qp in self.quest_progressions)
return all(qp.completed for qp in self.quest_progressions if qp.completable)

@property
def failed(self) -> bool:
Expand Down Expand Up @@ -917,7 +922,7 @@ def winning_policy(self) -> Optional[List[Action]]:
return None

# Greedily build a new winning policy by merging all quest trees.
trees = [quest._tree for quest in self.quest_progressions if not quest.done]
trees = [quest._tree for quest in self.quest_progressions if quest.completable and not quest.done]
if None in trees:
# Some quests don't have triggering policy.
return None
Expand Down
5 changes: 1 addition & 4 deletions textworld/generator/tests/test_game.py
Expand Up @@ -620,16 +620,13 @@ def setUpClass(cls):
cls.questB = Quest(win_events=[cls.eventB], fail_events=[cls.losing_eventB])
cls.questC = Quest(win_events=[], fail_events=[cls.losing_eventA, cls.losing_eventB])

commands = ["open wooden door", "go west", "take lettuce", "go east", "insert lettuce into chest"]
cls.questC = M.new_quest_using_commands(commands)

commands = ["open wooden door", "go west", "take carrot", "eat carrot"]
cls.eating_carrot = M.new_event_using_commands(commands)
commands = ["open wooden door", "go west", "take lettuce", "eat lettuce"]
cls.eating_lettuce = M.new_event_using_commands(commands)
commands = ["open wooden door", "go west", "take lettuce", "go east", "insert lettuce into chest"]

M.quests = [cls.questA, cls.questB]
M.quests = [cls.questA, cls.questB, cls.questC]
cls.game = M.build()

def test_completed(self):
Expand Down

0 comments on commit a3d8db6

Please sign in to comment.