Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: #132 #135

Merged
merged 1 commit into from Feb 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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