Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
LaTueur committed Dec 18, 2019
2 parents e976482 + 859fe52 commit f6015a6
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 46 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [[Unreleased]](https://github.com/AIDungeon/AIDungeon/compare/master...develop)


## [2.1.1] - 2019-12-17

### Fixed

- Bug preventing `Custom` game setting selection from working.
- Code style.

## [2.1.0] - 2019-12-16

### Added
Expand Down
1 change: 1 addition & 0 deletions generator/gpt2/gpt2_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import warnings

import numpy as np

import tensorflow as tf
from generator.gpt2.src import encoder, model, sample
from story.utils import *
Expand Down
1 change: 1 addition & 0 deletions generator/gpt2/src/model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np

import tensorflow as tf
from tensorflow.contrib.training import HParams

Expand Down
73 changes: 39 additions & 34 deletions play.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
import os
import sys
import random
import sys
import time

from generator.gpt2.gpt2_generator import *
Expand Down Expand Up @@ -74,15 +74,7 @@ def select_game():
choice = get_num_options(len(settings) + 1)

if choice == len(settings):

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
return "custom", None, None, None, None

setting_key = list(settings)[choice]

Expand All @@ -99,7 +91,20 @@ def select_game():
return setting_key, character_key, name, character, setting_description


def get_curated_exposition(setting_key, character_key, name, character, setting_description):
def get_custom_prompt():
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


def get_curated_exposition(
setting_key, character_key, name, character, setting_description
):
name_token = "<NAME>"
if (
character_key == "noble"
Expand Down Expand Up @@ -175,8 +180,22 @@ def play_aidungeon_2():

if splash_choice == "new":
print("\n\n")
setting_key, character_key, name, character, setting_description = select_game()
context, prompt = get_curated_exposition(setting_key, character_key, name, character, setting_description)
(
setting_key,
character_key,
name,
character,
setting_description,
) = select_game()

if setting_key == "custom":
context, prompt = get_custom_prompt()

else:
context, prompt = get_curated_exposition(
setting_key, character_key, name, character, setting_description
)

console_print(instructions())
print("\nGenerating story...")

Expand All @@ -202,27 +221,11 @@ def play_aidungeon_2():
command = split[0].lower()
args = split[1:]
if command == "restart":
while True:
try:
rating = input("Please rate the story quality from 1-10: ")
rating_float = max(min(float(rating), 10), 1)
except ValueError:
print("Please return a valid number.")
else:
story_manager.story.rating = rating_float
break
story_manager.story.get_rating()
break

elif command == "quit":
while True:
try:
rating = input("Please rate the story quality from 1-10: ")
rating_float = max(min(float(rating), 10), 1)
except ValueError:
print("Please return a valid number.")
else:
story_manager.story.rating = rating_float
break
story_manager.story.get_rating()
exit()

elif command == "nosaving":
Expand Down Expand Up @@ -307,10 +310,10 @@ def play_aidungeon_2():

else:
action = action.strip()
action = action[0].lower() + action[1:]
action = action[0].upper() + action[1:]

if "You" not in action[:6] and "I" not in action[:6]:
action = "You " + action
if "You" not in action[:6] and "you" not in action[:6] and "I" not in action[:6]:
action = "You " + action[0].lower() + action[1:]

if action[-1] not in [".", "?", "!"]:
action = action + "."
Expand All @@ -334,6 +337,7 @@ def play_aidungeon_2():

if player_won(result):
console_print(result + "\n CONGRATS YOU WIN")
story_manager.story.get_rating()
break
elif player_died(result):
console_print(result)
Expand All @@ -346,6 +350,7 @@ def play_aidungeon_2():
console_print("Which do you choose? ")
choice = get_num_options(2)
if choice == 0:
story_manager.story.get_rating()
break
else:
console_print("Sorry about that...where were we?")
Expand Down
1 change: 0 additions & 1 deletion story/grammars/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,3 @@ def direct(setting, key):
rules = load_rules(setting)
artefact = apply_grammar(key, rules)
return artefact

20 changes: 10 additions & 10 deletions story/grammars/fantasy_rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
"action" : ["#sense#", "#think#"],
"to_fro" : ["to and fro", "back and forth"],
"two_to_ten" : ["two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"],
"realm" : ["realm", "kingdom", "country", "province", "land"],
"realm" : ["realm", "kingdom", "country", "province", "land", "duchy", "barony"],
"season" : ["spring", "summer", "winter", "autumn"],
"animal" : ["lion", "elk", "badger", "fox", "raven", "goat", "wolf", "dove"],
"royalty" : ["king", "queen", "princess", "prince"],
"nobility" : ["duke", "dutchess", "lord", "lady", "count", "countess"],
"nobility" : ["duke", "duchess", "lord", "lady", "count", "countess", "baron", "baroness"],
"from_fantasy" : "from the #realm# of #fantasy_name#",
"fantasy_name" : ["Larion", "Vijeh", "Francia", "Paiva", "Mederos", "Radu", "Hatami", "Shirish", "Saralyn", "Leka", "Rukaj", "Nardis", "Isett", "Jacczak", "Hamma", "Narala", "Alstine", "Gimello", "Elsbury", "Rubino", "Misra", "Paterno", "Gassan", "Galardo", "Raeder", "Garriel", "Routh", "Bindi", "Renfro", "Harnid", "Enlou", "Amato", "Zurito", "Dimyan", "Arteaga", "Isgrigg", "Maida", "Mudra", "Beranek", "Aric", "Sadri", "Javan", "Wedriwin", "Umiemma", "Thaosean", "Alilawia", "Gwoia", "Galuswen", "Astedrinyth", "Wicolian", "Ziadan", "Thema", "Unirakon", "Severiveth", "Onalath", "Aaolla", "Airadan", "Legiallan", "Zayhan", "Afania", "Ibalegord", "Oligolind", "Celadon", "Alaleria", "Ocelith", "Eowaoviel", "Brigobard", "Griwen", "Frykoth", "Crilawen", "Memas", "Adrardong", "Nomaf", "Crirabeth", "Cadaed", "Broethien", "Astok", "Seraria", "Dreratlan", "Frireven", "Birahan", "Horeria", "Areriw", "Jerenia", "Alaodan", "Paeviel", "Cigowyr", "Lariesa", "Eroreth", "Sevoan", "Careg", "Thoijan", "Raywen", "Seikor", "Wilini", "Alerradon", "Unerrarith", "Agrohawyn", "Zilirith", "Brilann", "Eliawien", "Wirakor", "Gaeven", "Kiewin", "Umalia", "Prirep", "Rhalebeth", "Aaylin", "Qelindra", "Adwayder", "Rothien", "Brendabaen", "Galeliven", "Ethaykon", "Waowiel", "Qerijan", "Aavia", "Kaeinnon", "Rhycia", "Gligobard", "Zolle", "Sear", "Haeasien", "Fiakor"],
"town_name" : ["clearkeep", "faybury", "hazelpoint", "scorchfort", "earthpost", "mossband", "deadhelm", "dragonwick", "stormwood", "rosetide", "flatpass", "winteryard", "brinehaven", "springpost", "maplestar", "cavebell", "baregrave", "swampbrook", "wildescar", "nightwind", "oxgate", "lakeford", "cavecliff", "moonbell", "bearwater", "dimchill", "silkrun", "summerbourne", "bayvein", "rockspire", "sandbourne", "glimmerpond", "swyncoast", "snowham", "glassice", "starryholt", "ashhedge", "starryice", "estercastle", "wellpine", "fairfort", "newhill", "miststone", "glasshedge", "silveroak", "byburn", "oakpond", "whitehill", "butterway", "shadowmist", "highpond", "goldcliff", "southstone", "snowhaven", "fayham", "violetwick", "mallowdell", "bluegrass", "coldholt", "woodcourt", "ironmarsh", "brightiron", "beechhollow", "welllyn", "mallowshadow", "goldlight", "fayfall", "mormont", "wyvernburn", "greenmeadow", "wellwood", "westerrose", "westerelf", "snowdeer", "orport", "greenelf", "riverbridge", "highhedge", "mallowholt", "blueglass", "snowbeach", "goldview", "lorview", "rockhedge", "witchmoor", "fallmont", "linacre", "northby", "clearmaple", "woodbridge", "coldmaple", "vertville", "springacre", "shadowsage", "southkeep", "bymeadow", "wolfpond", "woodmallow", "flowerhall", "riverhall", "northwheat", "fallland", "brightland", "orcastle", "bymist", "aldfair", "pryborough", "fairway", "esterapple", "lochland", "newsummer", "landgate", "beachstone", "fairmere", "westwilde", "snowway", "lochoak", "esternesse", "summerriver", "starrylake", "icefort", "newrock", "landbridge", "vertlea", "courtland", "bygriffin", "byhollow", "lochmill", "brightbeach", "mallowhaven", "shadowgold", "deepcrest", "wellbarrow", "summerlake", "waterwick", "summercliff", "bluehurst", "marblerose", "dragonlake", "lightflower", "westerspring", "fairport", "lochby", "wayness", "deernesse", "greyrock", "dellmeadow", "morcliff", "mallowmarsh", "crystalmill", "normont", "fallborough", "flowerlea", "glassmerrow", "aelfort", "greydell", "mallowmarble", "deepsummer", "starryfog", "foxmoor", "deepbell", "highhaven", "seamoor", "brightton", "blackacre", "butterfox", "corburn", "butterhedge", "swynbourne", "dorbank", "shadowkeep", "wildehall", "greenburn", "eastland", "wheathall", "blueholt", "edgenesse", "courtley", "summerby", "pryshore", "edgehaven", "crystalham"],
"creature" : ["bugbear", "centaur", "chimera", "cockatrice", "cyclops", "demon", "devil", "dragon", "dryad", "dwarf", "elemental", "elf", "faun", "giant", "gnome", "goblin", "golem", "gorgon", "griffon", "harpy", "hell hound", "hobgoblin", "imp", "kobold", "lycanthrope", "manticore", "merfolk", "minotaur", "naga", "ogre", "pegasus", "roc", "selkie", "spectre", "troll", "unicorn", "vampire", "wight", "wraith", "zombie"],
"village" : ["village", "town", "city"],
"village" : ["village", "town", "city", "hamlet"],
"village_adj" : ["charming", "sleepy", "little", "small", "bustling", "quaint", "industrious", "festive", "remote", "secluded", "nearby", "close by"],
"village_adj_opt" : ["#village_adj# ", ""],
"village_full" : "the #village_adj_opt##village# of #town_name.capitalize#",
Expand All @@ -34,14 +34,14 @@
"nice_home" : ["keep", "castle", "manor", "mansion", "abbey", "estate", "tower"],
"he_she" : ["he", "she"],
"a_the" : ["a", "the", "your"],
"attacked" : ["under attack", "being invaded", "in danger", "being surrounded"],
"attacked" : ["under attack", "being invaded", "in danger", "being surrounded", "being sieged"],
"noble_one" : ["One morning, you are awakened by one of your #subordinate.s#. #he_she.capitalize# tells you that your #nice_home# is #attacked#. You look out #a_the# window and see"],

"element" : ["fire", "water", "earth", "air"],
"more_element" : ["the underworld", "the sea", "the heavens"],
"celestial" : ["the sun", "the moon", "the stars"],
"domain" : ["#element#", "#more_element#", "#celestial#", "harvest", "fertility", "war", "good fortune", "thresholds", "love"],
"god" : ["god", "deity"],
"domain" : ["#element#", "#more_element#", "#celestial#", "harvest", "fertility", "war", "good fortune", "thresholds", "love", "wisdom", "#profession.s#"],
"god" : ["god", "deity", "godess"],
"deity" : ["#god# of #domain#"],
"group" : ["group", "bunch", "delegation", "host"],
"humanoid" : ["elf", "dwarf", "gnome", "halfling", "hobbit", "goblin"],
Expand All @@ -60,9 +60,9 @@
"week_month" : ["week", "fortnight", "month"],
"week_months" : ["weeks", "fortnights", "months"],
"time_periods" : ["#week_month#", "#two_to_ten# #week_months#"],
"speak" : ["speak", "chat", "talk", "converse"],
"ask" : ["ask", "request"],
"noble_organization" : ["organization", "delegation", "guild"],
"speak" : ["speak", "chat", "talk", "converse", "discuss"],
"ask" : ["ask", "request", "demand"],
"noble_organization" : ["organization", "delegation", "guild", "leage", "faction"],
"matter" : ["about a matter of importance to the #realm#", "on behalf of a foreign #noble_organization# of #humanoid.s#", "with information regarding a rival house", "with demands from your #subordinate.s#"],
"noble_three" : "Every day for the past #week_month#, a certain #character# has come to your #grand_home_adj_opt##nice_home# #ask#ing to #speak# with you, apparently #matter#. Unsure if #he_she# is trustworthy, you finally agree to meet.\n\nAt the meeting, you #action#" ,

Expand All @@ -81,7 +81,7 @@
"good_object_adj" : ["sturdy", "trusty"],
"object_adj" : ["#old_object_adj#", "#good_object_adj#"],
"normal_name" : ["Steve", "Bob", "Richard", "Susan", "Deborah", "Lily"],
"mount" : ["horse", "pony", "donkey"],
"mount" : ["horse", "pony", "donkey", "camel", "mare", "stallion"],
"knight_item" : ["#metal_adj_opt#shield", "shield inscribed with the #crest#", "#metal_adj_opt#helmet", "#metal_adj_opt#sword", "#metal_adj_opt#lance", "#mount#", "squire named #normal_name#", "map of the #realm#", "food ration", "leather saddle"],
"towards" : ["to", "towards"],
"you_ve" : ["you", "you've", "you have"],
Expand Down
18 changes: 17 additions & 1 deletion story/story_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,12 @@ def save_to_storage(self):

FNULL = open(os.devnull, "w")
p = Popen(
["gsutil", "cp", os.path.join(save_path, file_name), "gs://aidungeonstories"],
[
"gsutil",
"cp",
os.path.join(save_path, file_name),
"gs://aidungeonstories",
],
stdout=FNULL,
stderr=subprocess.STDOUT,
)
Expand All @@ -145,6 +150,17 @@ def load_from_storage(self, story_id):
else:
return "Error save not found."

def get_rating(self):
while True:
try:
rating = input("Please rate the story quality from 1-10: ")
rating_float = max(min(float(rating), 10), 1)
except ValueError:
print("Please return a valid number.")
else:
self.rating = rating_float
return


class StoryManager:
def __init__(self, generator):
Expand Down

0 comments on commit f6015a6

Please sign in to comment.