From 2779ed234c8c77d5062127ad8effbf9b71c6b8d2 Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 16 Nov 2019 12:16:07 -0700 Subject: [PATCH] added death end --- console_play.py | 6 +++++- data/scraper/scraper.py | 28 ++++++++++++++++++++++++++-- story/utils.py | 8 ++++++++ 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/console_play.py b/console_play.py index 9fe8457..3cc23fa 100644 --- a/console_play.py +++ b/console_play.py @@ -35,7 +35,11 @@ def play_unconstrained(): #action = first_to_second_person(action) result = story_manager.act(action) - print(result) + if player_died(result): + print(result + "\nGAME OVER") + break + else: + print(result) if __name__ == '__main__': diff --git a/data/scraper/scraper.py b/data/scraper/scraper.py index efdd9eb..58d5381 100644 --- a/data/scraper/scraper.py +++ b/data/scraper/scraper.py @@ -146,12 +146,36 @@ urls = ["http://chooseyourstory.com/story/viewer/default.aspx?StoryId=10638", "http://chooseyourstory.com/story/viewer/default.aspx?StoryId=10359", "http://chooseyourstory.com/story/viewer/default.aspx?StoryId=5466", "http://chooseyourstory.com/story/viewer/default.aspx?StoryId=28030", - "http://chooseyourstory.com/story/viewer/default.aspx?StoryId=56515" + "http://chooseyourstory.com/story/viewer/default.aspx?StoryId=56515", + "http://chooseyourstory.com/story/viewer/default.aspx?StoryId=7480", + "http://chooseyourstory.com/story/viewer/default.aspx?StoryId=7566", + "http://chooseyourstory.com/story/viewer/default.aspx?StoryId=53134", + "http://chooseyourstory.com/story/viewer/default.aspx?StoryId=11413", + "http://chooseyourstory.com/story/viewer/default.aspx?StoryId=470", + "http://chooseyourstory.com/story/viewer/default.aspx?StoryId=8041", + "http://chooseyourstory.com/story/viewer/default.aspx?StoryId=22", + "http://chooseyourstory.com/story/viewer/default.aspx?StoryId=47011", + "http://chooseyourstory.com/story/viewer/default.aspx?StoryId=45866", + "http://chooseyourstory.com/story/viewer/default.aspx?StoryId=8", + "http://chooseyourstory.com/story/viewer/default.aspx?StoryId=55043", + "http://chooseyourstory.com/story/viewer/default.aspx?StoryId=6376", + "http://chooseyourstory.com/story/viewer/default.aspx?StoryId=36791", + "http://chooseyourstory.com/story/viewer/default.aspx?StoryId=34193", + "http://chooseyourstory.com/story/viewer/default.aspx?StoryId=10885", + "http://chooseyourstory.com/story/viewer/default.aspx?StoryId=21879", + "http://chooseyourstory.com/story/viewer/default.aspx?StoryId=7567", + "http://chooseyourstory.com/story/viewer/default.aspx?StoryId=51926", + "http://chooseyourstory.com/story/viewer/default.aspx?StoryId=8035", + "http://chooseyourstory.com/story/viewer/default.aspx?StoryId=8038", + "http://chooseyourstory.com/story/viewer/default.aspx?StoryId=2276", + "http://chooseyourstory.com/story/viewer/default.aspx?StoryId=56742", + "http://chooseyourstory.com/story/viewer/default.aspx?StoryId=14013" ] for i in range(19, len(urls)): print("****** Extracting Adventure ", urls[i], " ***********") tree = scraper.BuildStoryTree(urls[i]) - save_tree(tree, "stories/story" + str(i) + ".json") +, +save_tree(tree, "stories/story" + str(i) + ".json") print("done") diff --git a/story/utils.py b/story/utils.py index 2c7bf52..049a72b 100644 --- a/story/utils.py +++ b/story/utils.py @@ -33,6 +33,14 @@ def get_action_verbs(key): return data_loaded["action_verbs"][key] +def player_died(text): + + dead_phrases = ["you died", "you are dead", "You died", "You are dead", "You're dead", "you're dead"] + for phrase in dead_phrases: + if phrase in text: + return True + + def get_ctrl_verbs(key): with open(YAML_FILE, 'r') as stream: data_loaded = yaml.safe_load(stream)