mirror of
https://github.com/wassname/Clover-Edition.git
synced 2026-09-09 11:13:26 +08:00
Develop (#13)
* various small changes * various small changes * update * update * update * update * update
This commit is contained in:
@@ -23,11 +23,10 @@ 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.'")
|
||||
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' ")
|
||||
context = ""
|
||||
console_print("\nEnter a prompt that describes who you are and the first couple sentences of where you start "
|
||||
"out ex:\n 'You are a knight in the kingdom of Larion. You are hunting the evil dragon who has been " +
|
||||
"terrorizing the kingdom. You enter the forest searching for the dragon and see' ")
|
||||
prompt = input("Starting Prompt: ")
|
||||
return context, prompt
|
||||
|
||||
@@ -125,6 +124,12 @@ def play_aidungeon_2():
|
||||
console_print("\nLoading Game...\n")
|
||||
console_print(result)
|
||||
|
||||
elif len(action.split(" ")) == 2 and action.split(" ")[0] == "load":
|
||||
load_ID = action.split(" ")[1]
|
||||
result = story_manager.story.load_from_storage(load_ID)
|
||||
console_print("\nLoading Game...\n")
|
||||
console_print(result)
|
||||
|
||||
elif action == "print":
|
||||
print("\nPRINTING\n")
|
||||
print(str(story_manager.story))
|
||||
@@ -168,6 +173,13 @@ def play_aidungeon_2():
|
||||
action = "\n> " + action + "\n"
|
||||
|
||||
result = "\n" + story_manager.act(action)
|
||||
if len(story_manager.story.results) >= 2:
|
||||
similarity = get_similarity(story_manager.story.results[-1], story_manager.story.results[-2])
|
||||
if similarity > 0.9:
|
||||
story_manager.story.actions = story_manager.story.actions[:-1]
|
||||
story_manager.story.results = story_manager.story.results[:-1]
|
||||
console_print("Woops that action caused the model to start looping. Try a different action to prevent that.")
|
||||
continue
|
||||
|
||||
if player_won(result):
|
||||
console_print(result + "\n CONGRATS YOU WIN")
|
||||
@@ -175,7 +187,16 @@ def play_aidungeon_2():
|
||||
elif player_died(result):
|
||||
console_print(result)
|
||||
console_print("YOU DIED. GAME OVER")
|
||||
break
|
||||
console_print("\nOptions:")
|
||||
console_print('0) Start a new game')
|
||||
console_print('1) "I\'m not dead yet!" (If you didn\'t actually die) ')
|
||||
console_print('Which do you choose? ')
|
||||
choice = get_num_options(2)
|
||||
if choice == 0:
|
||||
break
|
||||
else:
|
||||
console_print("Sorry about that...where were we?")
|
||||
console_print(result)
|
||||
|
||||
else:
|
||||
console_print(result)
|
||||
|
||||
@@ -84,7 +84,7 @@ class Story():
|
||||
def __str__(self):
|
||||
story_list = [self.story_start]
|
||||
for i in range(len(self.results)):
|
||||
story_list.append("\n> " + self.actions[i] + "\n")
|
||||
story_list.append("\n" + self.actions[i] + "\n")
|
||||
story_list.append("\n" + self.results[i])
|
||||
|
||||
return "".join(story_list)
|
||||
|
||||
+7
-3
@@ -1,6 +1,7 @@
|
||||
# coding: utf-8
|
||||
# coding: utf-8
|
||||
import re
|
||||
import yaml
|
||||
from difflib import SequenceMatcher
|
||||
|
||||
YAML_FILE = "story/story_data.yaml"
|
||||
|
||||
@@ -21,6 +22,9 @@ def console_print(text, width=75):
|
||||
i += 1
|
||||
print(text)
|
||||
|
||||
def get_similarity(a, b):
|
||||
return SequenceMatcher(None, a, b).ratio()
|
||||
|
||||
def get_num_options(num):
|
||||
|
||||
while True:
|
||||
@@ -99,7 +103,7 @@ def cut_trailing_sentence(text):
|
||||
if last_punc <= 0:
|
||||
last_punc = len(text)-1
|
||||
|
||||
et_token = text.rfind("<|endoftext|>")
|
||||
et_token = text.rfind("<")
|
||||
if et_token > 0:
|
||||
last_punc = min(last_punc, et_token-1)
|
||||
|
||||
@@ -107,7 +111,7 @@ def cut_trailing_sentence(text):
|
||||
if act_token > 0:
|
||||
last_punc = min(last_punc, act_token-1)
|
||||
|
||||
text = text[:last_punc+1]
|
||||
text = text[:last_punc]
|
||||
|
||||
text = cut_trailing_quotes(text)
|
||||
text = cut_trailing_action(text)
|
||||
|
||||
Reference in New Issue
Block a user