From 47937f5d96a333cfb3d5979ec7de4f825d9d8761 Mon Sep 17 00:00:00 2001 From: AccidentallyOnPurpose <4935931+AccidentallyOnPurpose@users.noreply.github.com4935931+AccidentallyOnPurpose@users.noreply.github.com> Date: Tue, 24 Dec 2019 11:01:45 +0800 Subject: [PATCH] add d20 for action --- README.md | 1 + play.py | 43 +++++++++++++++++++++++++++++++++++-------- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 8a56a08..1a18902 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ A fork of AIDungeon2, now with huggingface's transformers repo using pytorch gpt * Complete rewrite of the user interface * Color text output * Suggested actions + * Roll 20 sided dice for speech or action * Console Bell when AI finishes * Much improved prompt selection * Ability to save custom prompts diff --git a/play.py b/play.py index 59c70d2..a52619b 100644 --- a/play.py +++ b/play.py @@ -1,4 +1,5 @@ import gc +import random import textwrap from pathlib import Path from random import shuffle @@ -235,21 +236,47 @@ def play(): elif action in [str(i) for i in range(len(suggested_actions))]: action = suggested_actions[int(action)] - elif action[0] == '"': - action = "You say " + action + # Roll a 20 sided dice to make things interesting + d = random.randint(1, 20) + logger.debug("roll d20=%s", d) + if action[0] == '"': + if d == 1: + verbs_say_d01 = ["mumble", "prattle", "incoherently say", "whine", "ramble", "wheeze"] + verb = random.sample(verbs_say_d01, 1)[0] + action = "You "+verb+" " + action + elif d == 20: + verbs_say_d20 = ["successfully", "persuasively", "expertly", "conclusively", "dramatically", "adroitly", "aptly"] + verb = random.sample(verbs_say_d20, 1)[0] + action = "You "+verb+" say " + action + else: + action = "You say " + action else: action = action.strip() - action = action[0].lower() + action[1:] - - if "You" not in action[:6] and "I" not in action[:6]: - action = "You " + action + action = first_to_second_person(action) + if not action.lower().startswith("you ") and not action.lower().startswith("i "): + action = action[0].lower() + action[1:] + # roll a d20 + if d == 1: + verb_action_d01 = ["disastrously", "incompetently", "dangerously", "stupidly", "horribly", "miserably", "sadly"] + verb = random.sample(verb_action_d01, 1)[0] + action = "You "+verb+" fail to " + action + elif d < 5: + action = "You start to " + action + elif d < 10: + action = "You attempt to " + action + elif d < 15: + action = "You try to " + action + elif d < 20: + action = "You " + action + else: + verb_action_d20 = ["successfully", "expertly", "conclusively", "adroitly", "aptly", "masterfully"] + verb = random.sample(verb_action_d20, 1)[0] + action = "You "+verb+" " + action if action[-1] not in [".", "?", "!"]: action = action + "." - action = first_to_second_person(action) - action = "\n> " + action + "\n" colPrint("\n>> " + action.lstrip(), colors["transformed-user-text"])