mirror of
https://github.com/wassname/Clover-Edition.git
synced 2026-09-09 11:13:26 +08:00
Develop (#8)
removes final lines with "you say" or "you ask" adds back death checking allows reverting actions
This commit is contained in:
Submodule
+1
Submodule generator/ctrl/model/fastBPE added at 1fd33189c1
@@ -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:
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
+18
-2
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user