mirror of
https://github.com/wassname/Clover-Edition.git
synced 2026-09-09 11:13:26 +08:00
update
This commit is contained in:
@@ -1,59 +0,0 @@
|
||||
from story.story_manager import *
|
||||
from generator.gpt2.gpt2_generator import *
|
||||
|
||||
def console_print(text, width=75):
|
||||
last_newline = 0
|
||||
i = 0
|
||||
while i < len(text):
|
||||
if text[i] == "\n":
|
||||
last_newline = 0
|
||||
elif last_newline > width and text[i] == " ":
|
||||
text = text[:i] + "\n" + text[i:]
|
||||
last_newline = 0
|
||||
else:
|
||||
last_newline += 1
|
||||
i += 1
|
||||
print(text)
|
||||
|
||||
|
||||
def play_unconstrained():
|
||||
|
||||
print("Initializing AI Dungeon! (This might take a few minutes)")
|
||||
generator = GPT2Generator()
|
||||
prompt = get_story_start("knight")
|
||||
context = get_context("knight")
|
||||
story_manager = UnconstrainedStoryManager(generator)
|
||||
story_manager.start_new_story(prompt, context=context)
|
||||
|
||||
with open('opening.txt', 'r') as file:
|
||||
starter = file.read()
|
||||
|
||||
print(starter)
|
||||
|
||||
print("\n")
|
||||
console_print(context + str(story_manager.story))
|
||||
while True:
|
||||
action = input("> ")
|
||||
|
||||
if action != "":
|
||||
action = action.strip()
|
||||
|
||||
action = first_to_second_person(action)
|
||||
|
||||
if "You" not in action:
|
||||
action = "You " + action
|
||||
|
||||
action = "\n> " + action + "\n"
|
||||
|
||||
|
||||
result = "\n" + story_manager.act(action)
|
||||
if player_died(result):
|
||||
console_print(result + "\nGAME OVER")
|
||||
break
|
||||
else:
|
||||
console_print(result)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
play_unconstrained()
|
||||
|
||||
@@ -17,7 +17,7 @@ def penalize_used(logits, output):
|
||||
|
||||
return tf.compat.v1.where(
|
||||
bool_tensor,
|
||||
logits / 1.15,
|
||||
logits / 1.2,
|
||||
logits)
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ from story.story_manager import *
|
||||
from generator.gpt2.gpt2_generator import *
|
||||
from story.utils import *
|
||||
from story.custom_story import *
|
||||
from termios import tcflush, TCIFLUSH
|
||||
import time,sys
|
||||
|
||||
def select_game():
|
||||
print("Which game would you like to play?")
|
||||
@@ -50,6 +52,7 @@ def play_aidungeon_2():
|
||||
print("\n")
|
||||
console_print(context + str(story_manager.story))
|
||||
while True:
|
||||
tcflush(sys.stdin, TCIFLUSH)
|
||||
action = input("> ")
|
||||
if action == "restart":
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user