diff --git a/generator/ctrl/model/fastBPE b/generator/ctrl/model/fastBPE new file mode 160000 index 0000000..1fd3318 --- /dev/null +++ b/generator/ctrl/model/fastBPE @@ -0,0 +1 @@ +Subproject commit 1fd33189c126dae356b9e187d93d93302fa45cef diff --git a/generator/ctrl/training_utils/action_results.tfrecords b/generator/ctrl/training_utils/action_results.tfrecords new file mode 100644 index 0000000..e69de29 diff --git a/generator/gpt2/gpt2_generator.py b/generator/gpt2/gpt2_generator.py index f64deef..c52814d 100644 --- a/generator/gpt2/gpt2_generator.py +++ b/generator/gpt2/gpt2_generator.py @@ -86,7 +86,7 @@ class GPT2Generator: def generate(self, prompt, options=None, seed=1): - debug_print = False + debug_print = True prefix = self.prompt_replace(prompt) if debug_print: diff --git a/play.py b/play.py index 07d59e2..75dc75e 100644 --- a/play.py +++ b/play.py @@ -24,7 +24,7 @@ def select_game(): if choice == len(settings): console_print("Enter a sentence or two that describes the context of who your character is. Ex. ' " + - "You are a knight living in the king of Larion. You have a sword and shield. '") + "You are a knight living in the king of Larion. You have a sword and shield.'") context = input("Context: ") console_print("Enter the first couple sentences to start your adventure off. Ex. " + "'You enter the forest searching for the dragon and see' ") @@ -53,7 +53,8 @@ def select_game(): def instructions(): text = "\nAI Dungeon 2 Instructions:" text += '\n* Enter actions starting with a verb ex. "go to the tavern" or "attack the orc."' - text += '\n* If you want to say something then enter \'say "(thing you want to say)"\'' + text += '\n* To speak enter \'say "(thing you want to say)"\' or just "(thing you want to say)" ' + text += '\n* Enter "revert" for any action if you want to undo the last action and result.' text += '\n* Finally if you want to end your game and start a new one just enter "restart" for any action. ' return text @@ -94,9 +95,27 @@ def play_aidungeon_2(): break elif action == "quit": exit() - + elif action == "revert": - if action != "": + if len(story_manager.story.actions) is 0: + console_print("You can't go back any farther. ") + continue + + story_manager.story.actions = story_manager.story.actions[:-1] + story_manager.story.results = story_manager.story.results[:-1] + console_print("Last action reverted. ") + if len(story_manager.story.results) > 0: + console_print(story_manager.story.results[-1]) + else: + console_print(story_manager.story.story_start) + continue + elif action == "": + action = "" + + elif action[0] == '"': + action = "You say " + action + + else: action = action.strip() action = action[0].lower() + action[1:] @@ -115,6 +134,10 @@ def play_aidungeon_2(): if player_won(result): console_print(result + "\n CONGRATS YOU WIN") break + elif player_died(result): + console_print(result) + console_print("YOU DIED. GAME OVER") + break else: console_print(result) diff --git a/story/utils.py b/story/utils.py index ba5a46e..e936512 100644 --- a/story/utils.py +++ b/story/utils.py @@ -37,8 +37,16 @@ def get_num_options(num): def player_died(text): + reg_phrases = ["You[a-zA-Z ]* die.", "you[a-zA-Z ]* die.", "You[a-zA-Z ]* die ", "you[a-zA-Z ]* die ",] + + for phrase in reg_phrases: + reg_expr = re.compile(phrase) + matches = re.findall(reg_expr, text) + if len(matches) > 0: + return True + dead_phrases = ["you die", "You die", "you died", "you are dead", "You died", "You are dead", "You're dead", - "you're dead", "you have died", "You have died"] + "you're dead", "you have died", "You have died", "finish you off", "Your death", "your death"] for phrase in dead_phrases: if phrase in text: return True @@ -78,6 +86,12 @@ def split_first_sentence(text): return text[0:split_point], text[split_point:] +def cut_trailing_action(text): + lines = text.split("\n") + last_line = lines[-1] + if "you ask." in last_line or "You ask." in last_line or "you say." in last_line or "You say." in last_line: + text = "\n".join(lines[0:-1]) + return text def cut_trailing_sentence(text): text = standardize_punctuation(text) @@ -94,7 +108,9 @@ def cut_trailing_sentence(text): if last_punc > 0: text = text[0:last_punc+1] - return cut_trailing_quotes(text) + text = cut_trailing_quotes(text) + text = cut_trailing_action(text) + return text def replace_outside_quotes(text, current_word, repl_word):