Skip to content

Commit

Permalink
Merge pull request latitudegames#216 from AIDungeon/develop
Browse files Browse the repository at this point in the history
dev -> master
  • Loading branch information
ben-bay authored Dec 23, 2019
2 parents 970a60c + 71da137 commit bcc8420
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 82 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [[Unreleased]](https://github.com/AIDungeon/AIDungeon/compare/master...develop)

## [2.2.0] - 2019-12-19
## [2.2.0] - 2019-12-23

### Added

- `/reset` is a new command with the same functionality as the
old `/restart`, saving the old and beginning a brand new game.
- Ratings after death and winning
- `get_rating` function to `Story` objects.
- Some new word to fantasy grammar.
- New content in fantasy grammar.
- Formal grammars for peasant and rogue contexts/prompts.

## Removed

- F-strings for python 3.4 and 3.5 compatibility
- Trailing comma in function args for 3.5 compatibility

### Fixed

- Typos in story grammar.
Expand Down
2 changes: 1 addition & 1 deletion generator/gpt2/src/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def sample_sequence(
context=None,
temperature=1,
top_k=0,
top_p=1,
top_p=1
):
if start_token is None:
assert context is not None, "Specify exactly one of start_token and context!"
Expand Down
44 changes: 0 additions & 44 deletions other/cacher.py

This file was deleted.

7 changes: 4 additions & 3 deletions play.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,15 @@ def play_aidungeon_2():
console_print("Censor is now enabled.")

else:
console_print(f"Invalid argument: {args[0]}")
console_print("Invalid argument: {}".format(args[0]))

elif command == "save":
if upload_story:
id = story_manager.story.save_to_storage()
console_print("Game saved.")
console_print(
f"To load the game, type 'load' and enter the following ID: {id}"
"To load the game, type 'load' and enter the "
"following ID: {}".format(id)
)
else:
console_print("Saving has been turned off. Cannot save.")
Expand Down Expand Up @@ -307,7 +308,7 @@ def play_aidungeon_2():
continue

else:
console_print(f"Unknown command: {command}")
console_print("Unknown command: {}".format(command))

else:
if action == "":
Expand Down
6 changes: 3 additions & 3 deletions story/grammars/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
def apply_grammar(key, rules):
grammar = tracery.Grammar(rules)
grammar.add_modifiers(base_english)
return grammar.flatten(f"#{key}#")
return grammar.flatten("#{}#".format(key))


def load_rules(setting):
with open(
os.path.join(
os.path.dirname(os.path.abspath(__file__)), f"{setting}_rules.json"
os.path.dirname(os.path.abspath(__file__)), "{}_rules.json".format(setting)
),
"r",
) as f:
Expand All @@ -27,7 +27,7 @@ def generate(setting, character_type, key):
Provides a randomized prompt according to the grammar rules in <setting>_rules.json
"""
rules = load_rules(setting)
artefact = apply_grammar(f"{character_type}_{key}", rules)
artefact = apply_grammar("{}_{}".format(character_type, key), rules)
return artefact


Expand Down
70 changes: 41 additions & 29 deletions story/grammars/fantasy_rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
"artist" : ["artist", "artisan", "fresco painter", "glasspainter", "limner", "painter", "sculptor"],
"writer" : ["composer", "illuminator", "limner", "playwright", "poet", "writer"],
"profession" : ["#writer#", "#artist#", "#fisher#", "#hunter#", "#farmer#"],
"color" : ["black", "white", "red", "gray", "blue", "#uncommon_color#"],
"uncommon_color" : ["green", "brown", "green", "brown", "golden", "silver", "scarlet"],
"weapon" : ["staff", "sword", "spear", "flail", "mace", "dagger", "bow", "arrow", "lance"],
"relative" : ["father", "mother", "brother", "sister", "cousin", "uncle", "aunt"],



Expand All @@ -42,7 +46,8 @@
"celestial" : ["the sun", "the moon", "the stars"],
"domain" : ["#element#", "#more_element#", "#celestial#", "harvest", "fertility", "war", "good fortune", "thresholds", "love", "wisdom", "#profession.s#"],
"god" : ["god", "deity", "goddess"],
"deity" : ["#god# of #domain#"],
"god_adj" : ["just", "cruel", "omniscient", "all-knowing", "mischevious", "wise", "reckless", "omnipotent", "#color#", "prudent", "jealous", "kind", "graceful", "magnificent", "traditional", "famous", "new", "old", "ancient", "wrathful", "fruitful", "gracious"],
"deity" : ["#god# of #domain#", "patron #god# of #domain#", "#god_adj# #god# #fantasy_name#"],
"group" : ["group", "bunch", "delegation", "host"],
"humanoid" : ["elf", "dwarf", "gnome", "halfling", "hobbit", "goblin"],
"noble_class" : ["trader", "noble", "merchant", "soldier", "captain", "aristocrat", "duke", "count", "lord", "priest"],
Expand All @@ -52,24 +57,26 @@
"toast" : ["offers a toast", "gives a speech", "recites a prayer", "announces future plans", "loudly argues", "sings a ballad"],
"grand_home_adj" : ["great", "grand", "large", "spacious"],
"grand_home_adj_opt" : ["#grand_home_adj# ", ""],
"noble_location" : ["with a #group# of #character.s#", "in a #grand_home_adj_opt##nice_home#"],
"festival" : ["#season# festival", "festival of the #deity#", "festival of the year of the #animal#"],
"noble_location" : ["with #group.a# of #character.s#", "in a #grand_home_adj_opt##nice_home#"],
"festival" : ["#season# festival", "festival of the #deity#", "festival of the #animal#", "festival of the year of the #animal#"],
"season_opt" : ["#season# ", ""],
"noble_two" : "Throughout the #realm# it is the #festival#. To celebrate, you are feasting #noble_location#. #subordinate.s.capitalize# bustle #to_fro#.\n\nAs a #character# #toast#, you #action#",
"noble_two" : "Throughout the #realm# it is the #festival#. To celebrate, you are feasting #noble_location#. #subordinate.s.capitalize# bustle #to_fro#.\n\nAs #character.a# #toast#, you #action#",

"week_month" : ["week", "fortnight", "month"],
"week_months" : ["weeks", "fortnights", "months"],
"time_periods" : ["#week_month#", "#two_to_ten# #week_months#"],
"speak" : ["speak", "chat", "talk", "converse", "discuss"],
"chat" : ["speak", "chat", "talk", "converse"],
"ask" : ["ask", "request", "demand"],
"noble_organization" : ["organization", "delegation", "guild", "league", "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#" ,
"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 some #professioe.s#"],
"trustworthy" : ["trustworthy", "reliable", "dependable", "well-intentioned", "worth your time"],
"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 #chat# with you, apparently #matter#. Unsure if #he_she# is #trustworthy#, you finally agree to meet.\n\nAt the meeting, you #action#" ,

"noble_prompt": ["#noble_one#", "#noble_two#", "#noble_three#"],
"noble_four" : "You and your bodyguards are #on_the_way# #towards# #village_full# to celebrate the #festival# with your subjects. You #road_encounter#.\n\nYou #action#",

"noble_context1" : "You are <NAME>, a noble #from_fantasy#. You have a #noble_item1# and a #noble_item2#.",
"noble_context" : ["#[noble_item1:#noble_item#][noble_item2:#noble_item#]noble_context1#"],
"noble_prompt": ["#noble_one#", "#noble_two#", "#noble_three#", "#noble_four##"],

"noble_context" : "You are <NAME>, a noble #from_fantasy#. You have #noble_item.a# and #noble_item.a#.",



Expand All @@ -95,8 +102,8 @@
"place" : ["valley", "forest", "plain", "mountain", "swamp", "river", "cave", "cavern", "lake", "expanse", "cliff"],
"monster_quest" : ["#kill# the #evil_adj# #monster# of Larion. #you_ve.capitalize# heard #he_she_it# lives to the #cardinal_dir# of #the_your# #realm#"],

"artifact_adj" : ["lost", "holy", "gold", "fabled", "mythic", "legendary", "blessed", "cursed", "forgotten"],
"artifact" : ["grail", "fleece", "gauntlet", "banner", "stone", "sword", "helmet", "ring", "book", "chalice", "tome", "gem", "bow"],
"artifact_adj" : ["lost", "holy", "gold", "fabled", "mythic", "legendary", "blessed", "cursed", "forgotten", "#color#"],
"artifact" : ["grail", "fleece", "gauntlet", "banner", "stone", "sword", "helmet", "ring", "book", "chalice", "tome", "gem", "bow", "scepter", "staff"],
"whole_artifact" : "#artifact_adj# #artifact# of #fantasy_name#",
"find" : ["find", "discover", "recover"],
"rumored" : ["is rumored to", "is said to", "was prophesied to"],
Expand All @@ -117,11 +124,11 @@

"quest_type" : ["#monster_quest#", "#artifact_quest#", "#rescue_quest#"],
"could" : ["will", "may", "should", "could"],
"adventure" : ["an adventure", "a quest", "a journey", "a crusade"],
"adventure" : ["adventure", "quest", "journey", "crusade"],
"beginning" : ["going on", "beginning", "setting out on"],
"quest" : ["You are #beginning# #adventure# to #quest_type#. You set out #towards# a #place_adj# #place# that #could# take you there.\n\nAs you approach, you #action#"],
"quest" : ["You are #beginning# #adventure.a# to #quest_type#. You set out #towards# #place_adj.a# #place# that #could# take you there.\n\nAs you approach, you #action#"],
"knight_prompt" : "#quest#",
"knight_context" : "You are <NAME>, a knight #from_fantasy#. You have a #knight_item# and a #knight_item#.",
"knight_context" : "You are <NAME>, a knight #from_fantasy#. You have #knight_item.a# and #knight_item.a#.",



Expand Down Expand Up @@ -151,7 +158,7 @@
"book" : ["#normal_book#", "#spellbook#", "book", "spellbook"],
"magic_discipline" : ["alchemy"],
"through" : ["through", "across", "throughout", "about"],
"wizard_drafts" : ["After a #week_month# of travel you arrive at the ruin ", "Your apprentice has done it again; #he_she# has summoned a being "],
"wizard_drafts" : ["After #week_month.a# of travel you arrive at the ruin ", "Your apprentice has done it again; #he_she# has summoned a being "],
"road" : ["road", "river", "path"],
"wizard_exchange" : ["notes", "spells", "gossip", "goods", "research", "banter", "knowledge"],
"wizard_colleage" : ["another wizard", "a fellow wizard", "a sorcerer", "a #evil_role#", "a #attrib# #char#"],
Expand All @@ -161,48 +168,49 @@
"wandering_opt" : ["#wandering# ", ""],
"troupe" : ["group", "band", "troupe", "crew", "gang", "party"],
"dancer" : ["dancer", "actor", "entertainer"],
"road_encounter" : ["#encounter# #looks_like_opt#a #creature#", "#encounter# a #wandering_opt#troupe of #profession.s#"],
"road_encounter" : ["#encounter# #looks_like_opt##creature.a#", "#encounter# a #wandering_opt#troupe of #profession.s#"],
"wizard_one" : ["You are #on_the_way# #towards# #village_full# to exchange #wizard_exchange# with #wizard_colleage#. You #road_encounter#.\n\nYou #action#"],
"old" : ["old", "aged", "experienced", "elderly", "venerable"],
"around_opt" : [" about", " around", ""],
"wizard_pos" : ["wise", "intelligent", "crafty", "powerful", "magical"],
"wizard_two" : ["You face a #place_adj# #place# as images of #random_object.s# #flicker# #through# your #mind#. What was that? Though #old# and #wizard_pos#, your memory extends only a few #week_months# back. Now you #wander##around_opt#, trying to #remember# what happened.\n\nYou #action#"],
"wizard_two" : ["You face #place_adj.a# #place# as images of #random_object.s# #flicker# #through# your #mind#. What was that? Though #old# and #wizard_pos#, your memory extends only a few #week_months# back. Now you #wander##around_opt#, trying to #remember# what happened.\n\nYou #action#"],
"great" : ["great", "renowned", "world-famous", "legendary"],
"stare" : ["look", "stare", "gaze"],
"sneak" : ["sneak", "creep", "inch", "move", "go"],
"go_near" : ["#stare# at", "#sneak# towards", "approach"],
"private" : ["private", "restricted", "forbidden", "confidential", "secure", "secret", "personal"],
"chamber" : ["chamber", "study", "office", "antechamber", "room", "basement", "attic"],
"great_wizard" : ["#great# #magical_role# #fantasy_name#", "#fantasy_name# the #color.capitalize#"],
"order" : ["order", "command", "remind", "direct", "demand"],
"wizard_three" : "You are apprentice to the #great# #magical_role# #fantasy_name#. Before leaving on an errand, they #order.ed# you to never enter their #private# #chamber#... but your curiosity has gotten the best of you.\n\nAs you #go_near# the door, you #action#",
"wizard_three" : "You are apprentice to the #great_wizard#. Before leaving on an errand, they #order.ed# you to never enter their #private# #chamber#... but your curiosity has gotten the best of you.\n\nAs you #go_near# the door, you #action#",
"wizard_prompt" : ["#wizard_one#", "#wizard_two#", "#wizard_three#"],
"wizard_context" : "You are <NAME>, a wizard #from_fantasy#. You have a #wizard_item# and a #wizard_item#.",
"wizard_context" : "You are <NAME>, a wizard #from_fantasy#. You have #wizard_item.a# and #wizard_item.a#.",


"peasant_item" : ["a #metal_adj_opt#pitchfork", "the shirt on your back", "a #metal_adj_opt#shovel", "a dirty rag", "a #metal_adj_opt#spade", "a #metal_adj_opt#sickle", "shears", "a basket", "a plough", "a #metal_adj_opt#scythe", "a dirty hat"],
"peasant_item" : ["#metal_adj_opt#pitchfork", "shirt on your back", "#metal_adj_opt#shovel", "dirty rag", "#metal_adj_opt#spade", "#metal_adj_opt#sickle", "shears", "basket", "plough", "#metal_adj_opt#scythe", "dirty hat"],
"farm_animal" : ["pig", "cow", "chicken", "llama", "goat", "horse", "donkey", "rabbit", "hog", "mule", "sow"],
"farm_animal_sing" : ["sheep", "livestock", "cattle"],
"farm_animal_type" : ["#farm_animal.s#", "#farm_animal_sing#"],
"woolen" : ["sheep", "goats", "llamas"],
"milky" : ["cows", "goats"],
"working" : ["working", "toiling", "laboring", "sweating"],
"morning_time" : ["at the break of dawn", "at daybreak", "early", "early in the morning"],
"morning_time" : ["at the break of dawn", "at daybreak", "early", "early in the morning", "at the cock's crow"],
"field_verb" : ["plowing", "tilling", "cultivating", "caring for"],
"peasant_work" : ["feeding the #farm_animal_type#", "#field_verb# the fields", "harvesting the crops", "planting new crops", "#working# in the fields", "shearing the #woolen#", "milking the #milky#"],
"peasant_work" : ["feeding the #farm_animal_type#", "#field_verb# the fields", "harvesting the crops", "planting new crops", "#working# in the fields", "shearing the #woolen#", "milking the #milky#", "shoveling dung"],
"begin" : ["begin", "go about", "start", "get to", "get about"],
"second_thing" : ["For a while, you have wanted to run away.", "In the distance, your master is yelling at some other workers.", "The sun beats down upon you.", "This has been your daily routine since you were young."],
"second_thing" : ["For a while, you have wanted to run away.", "In the distance, your master is yelling at some other workers.", "The sun beats down upon you.", "This has been your daily routine since you were young.", "You mutter a prayer to the #deity#."],
"peasant_prompt" : "You wake up #morning_time# and #begin# #peasant_work#. #second_thing# You #action#",
"peasant_context" : "You are <NAME>, a peasant #from_fantasy#. You have #peasant_item# and #peasant_item#.",
"peasant_context" : "You are <NAME>, a peasant #from_fantasy#. You have #peasant_item.a# and #peasant_item.a#.",



"rogue_item" : ["a pair of gloves", "a cloak", "a deck of cards", "a dagger", "lockpick", "a mask", "a shawl", "a pipe", "a key", "a length of rope", "darts", "a sickle", "a mace"],
"rogue_item" : ["pair of gloves", "cloak", "deck of cards", "dagger", "lockpick", "mask", "shawl", "pipe", "key", "length of rope", "bundle of darts", "sickle", "mace"],
"walk" : ["walk","go"],
"street" : ["street", "streets", "square", "road"],
"city" : ["city", "town", "village", "market"],
"steal" : ["steal from", "shoplift", "burgle", "break into"],
"rob" : ["steal from", "rob", "jump", "pickpocket", "con"],
"target" : ["someplace to #steal#", "someone to #rob#"],
"target" : ["someplace to #steal#", "someone to #rob#", "some #profession# to #rob#"],
"along" : ["along", "down"],
"townsfolk" : ["townsfolk", "local vendors", "people", "crowd", "populace"],
"amongst" : ["amongst", "in the midst of", "among"],
Expand All @@ -217,8 +225,12 @@
"stealing" : ["stealing", "mischief", "pickpocketing"],
"inn_adj" : ["your favorite", "a nearby", "a crowded", "a busy", "a cheap"],
"rogue_two" : "After a #day# of #stealing#, you head towards #inn_adj# inn to stay for the night. #position.capitalize# you #action#",
"rogue_three" : "Today you decided that simple #stealing# isn't enough anymore. You long for a more ambitious goal: taking for yourself #whole_artifact#. You #action#",
"isnt" : ["isn't", "is not"],
"enough" : ["enough", "sufficient", "good enough"],
"not_enough" : ["#isnt# #enough#", "#isnt# #enough# anymore"],
"simple" : ["simple", "basic", "general", "standard"],
"rogue_three" : "This #time# you decided that #simple# #stealing# #not_enough#. You long for a more ambitious goal: taking for yourself #whole_artifact#.\n\nYou #action#",
"rogue_prompt" : ["#rogue_one#","#rogue_two#", "#rogue_three#"],
"rogue_context" : "You are <NAME>, a rogue #from_fantasy#. You have #rogue_item# and #rogue_item#."
"rogue_context" : "You are <NAME>, a rogue #from_fantasy#. You have #rogue_item.a# and #rogue_item.a#."
}

0 comments on commit bcc8420

Please sign in to comment.