diff --git a/__pycache__/utils.cpython-36.pyc b/__pycache__/utils.cpython-36.pyc index 8a66c5a..a29c2e3 100644 Binary files a/__pycache__/utils.cpython-36.pyc and b/__pycache__/utils.cpython-36.pyc differ diff --git a/__pycache__/utils.cpython-37.pyc b/__pycache__/utils.cpython-37.pyc index 9adb104..252863a 100644 Binary files a/__pycache__/utils.cpython-37.pyc and b/__pycache__/utils.cpython-37.pyc differ diff --git a/generate.sh b/generate.sh index 10a6973..5a08a09 100755 --- a/generate.sh +++ b/generate.sh @@ -1,6 +1,8 @@ #!/bin/bash -END=25 -for ((I=0;I 1000: + if int(seed) < 0 or int(seed) > 100: print("Invalid seed: " + seed) abort(404) if gen_actions == "true": - prompt = request.form["prompt"] + #prompt = request.form["prompt"] choices = json.loads(request.form["choices"]) print("Getting response for seed ", seed, " prompt_num ", prompt_num, " and choices ", choices) - + action_results = retrieve_from_cache(seed, prompt_num, choices, "choices") if action_results is not None: response = action_results else: + last_action_result = request.form["last_action_result"] + prompt = continuing_prompts[prompt_num] + last_action_result + print("\n\nAction prompt is \n ", prompt) action_results = [generate_action_result(prompt, phrase) for phrase in phrases] response = json.dumps(action_results) cache_file(seed, prompt_num, choices, response, "choices") @@ -185,7 +189,8 @@ def story_request(): if result is not None: response = result else: - response = generate_story_block(prompts[prompt_num]) + prompt = prompts[prompt_num] + response = generate_story_block(prompt) cache_file(seed, prompt_num, [], response, "story") print("\nGenerated response is: \n", response) @@ -199,7 +204,6 @@ def generate_cache(): start_seed = int(sys.argv[1]) end_seed = int(sys.argv[2]) - # Generate story sections prompt_num = 0 action_queue = [] @@ -210,10 +214,12 @@ def generate_cache(): response = result else: prompt = prompts[prompt_num] + #print("\n Story prompt is ", prompt) response = generate_story_block(prompt) + #print("\n Story response is ", response) cache_file(seed, prompt_num, [], response, "story") - action_queue.append([seed,0,[],prompt+response, ""]) + action_queue.append([seed,0,[],response]) while(True): @@ -221,8 +227,7 @@ def generate_cache(): seed = next_gen[0] prompt_num = next_gen[1] choices = next_gen[2] - initial_prompt = next_gen[3] - last_action_result = next_gen[4] + last_action_result = next_gen[3] action_results = retrieve_from_cache(seed, prompt_num, choices, "choices") @@ -230,15 +235,22 @@ def generate_cache(): response = action_results else: + if len(choices) is 0: + prompt = prompts[prompt_num] + last_action_result + else: + prompt = continuing_prompts[prompt_num] + last_action_result + #print("\n\n Action prompt is \n ", prompt) action_results = [generate_action_result(prompt, phrase) for phrase in phrases] response = json.dumps(action_results) + + #print("\n\n Action cache_file(seed, prompt_num, choices, response, "choices") un_jsoned = json.loads(response) for j in range(4): new_choices = choices[:] new_choices.append(j) - action_queue.append([seed, 0, new_choices, initial_prompt, un_jsoned[j]]) + action_queue.append([seed, 0, new_choices, un_jsoned[j][1]]) if __name__ == '__main__': if(len(sys.argv) > 1): diff --git a/static/script.js b/static/script.js index 0a455aa..069d8f9 100644 --- a/static/script.js +++ b/static/script.js @@ -1,20 +1,14 @@ -var prompts = ["You enter a dungeon with your trusty sword and shield. You are searching for the evil necromancer who killed your family and have heard that he resides at the bottom of the dungeon, guarded by legions of the undead. You enter the first door and see"] - start_text = "Adventurer@AIDungeon:~$ ./EnterDungeon \n
" -input_form = '
' - - var acceptInput=false var action_waiting = false var inputStr = "" var typing = false -var should_blink = false -var blinkCounter = 0 var action_list = ["You attack", "You tell", "You use", "You go"] var prompt_num = 0 var seed_max = 100 var seed_min = 0; +prompts = ["You enter a dungeon with your trusty sword and shield. You are searching for the evil necromancer who killed your family. You've heard that he resides at the bottom of the dungeon, guarded by legions of the undead. You enter the first door and see"] if(seed == -1){ var seed = Math.floor(Math.random() * (+seed_max - +seed_min)) + +seed_min; @@ -39,34 +33,26 @@ function buttonCheck(){ } var StoryTracker = { - firstStory: null, - lastStory: null, - lastAction: null, + lastActionResult: "", actions: [], results: [], choices: [], - action_int: 0, - startPrompt: prompts[prompt_num], + // Requests the first story getFirstStory:function(){ console.log("Requesting first story") - Typer.appendToText(StoryTracker.startPrompt) - StoryTracker.requestFirstStory(StoryTracker.startPrompt) + Typer.appendToText(prompts[prompt_num]) + StoryTracker.requestFirstStory() }, - addNextStory:function(story){ - StoryTracker.lastStory = story - if (StoryTracker.firstStory == null){ - StoryTracker.firstStory = StoryTracker.startPrompt + story - } - - StoryTracker.makeActionRequests(StoryTracker.firstStory + StoryTracker.lastStory) + addFirstStory:function(story){ + StoryTracker.lastActionResult = story + StoryTracker.makeActionRequests() Typer.appendToText(story) - action_waiting = true - setTimeout(StoryTracker.actionWait, 10000); }, + // Called after requesting options, prints generating msg if waits too lng actionWait:function(){ if(action_waiting == true){ @@ -80,12 +66,17 @@ var StoryTracker = { }, + // Callback for action request addNextAction:function(action_result){ - action_waiting = false - + // Response receieved no longer waiting var action_results = JSON.parse(action_result) Typer.appendToText("\n\nOptions:") + + action_waiting = false + StoryTracker.actions = [] + StoryTracker.results = [] + for (i = 0; i < 4; i++){ action_result = action_results[i] @@ -93,57 +84,52 @@ var StoryTracker = { action = action_result[0] result = action_result[1] - StoryTracker.actions.push(action) StoryTracker.results.push(result) - var print_action = "\n" + String(StoryTracker.action_int) + ") " + action - StoryTracker.action_int += 1 + var print_action = "\n" + String(i) + ") " + action Typer.appendToText(print_action) - if (StoryTracker.action_int > 3){ + if (i == 3){ Typer.appendToText("\nWhich action do you choose? ") - StoryTracker.action_int = 0 + + // Now we wait for the user to give input to us. acceptInput = true if(isMobileDevice()){ setTimeout(buttonCheck, 500); } } - } - + } }, - makeActionRequests:function(prompt){ - - StoryTracker.actions = [] - StoryTracker.results = [] - - StoryTracker.requestActions(prompt, JSON.stringify(StoryTracker.choices)) + // Make a request to the server for result actions + makeActionRequests:function(){ + action_waiting = true + setTimeout(StoryTracker.actionWait, 10000); + StoryTracker.requestActions(StoryTracker.lastActionResult, JSON.stringify(StoryTracker.choices)) }, - - requestFirstStory:function(prompt){ + requestFirstStory:function(){ $.post("/generate", {actions: false, seed, prompt_num}, - StoryTracker.addNextStory) + StoryTracker.addFirstStory) }, - requestActions:function(prompt, choices){ - $.post("/generate", {actions: true, seed, prompt_num, prompt, choices}, + requestActions:function(last_action_result, choices){ + $.post("/generate", {actions: true, seed, prompt_num, last_action_result, choices}, StoryTracker.addNextAction) }, + // Called once a choice has been made by button or entering. processInput:function(){ var choice_int = parseInt(inputStr, 10) if(choice_int >= 0 && choice_int <= 3){ console.log("choice_int is %d", choice_int) StoryTracker.choices.push(choice_int) - StoryTracker.lastAction = StoryTracker.actions[choice_int] - StoryTracker.lastStory = StoryTracker.results[choice_int] + StoryTracker.lastActionResult = StoryTracker.results[choice_int] StoryTracker.makeActionRequests(StoryTracker.firstStory + StoryTracker.lastStory) action_waiting = true - setTimeout(StoryTracker.actionWait, 10000); Typer.appendToText("\n") - Typer.appendToText(StoryTracker.lastStory) + Typer.appendToText(StoryTracker.lastActionResult) } else{ @@ -164,24 +150,28 @@ var StoryTracker = { } } +// Used to control the terminal like screen typing var Typer={ text: null, - accessCountimer:null, index:0, speed:2, - startBlinker: function(){ - accessCountimer=setInterval(function(){Typer.blinkCursor()},500) - }, - + content:function(){ return $("#console").html() }, appendToText:function(str){ - str = str.replace(".", "." + "") + str = str.replace(".", "." + "") typing = true Typer.text = Typer.text + str; }, + + removeChar:function(){ + var cont=Typer.content() + $("#console").html($("#console").html().substring(0,cont.length-1)) + Typer.text = Typer.text.substring(0, Typer.text.length-1) + Typer.index = Typer.index - 1 + }, addText:function(){ @@ -206,26 +196,6 @@ var Typer={ } }, - - blinkCursor:function(){ - - if(should_blink == true){ - - if(blinkCounter > 10){ - var cont=this.content() - - if(cont.substring(cont.length-1,cont.length)=="|") - $("#console").html($("#console").html().substring(0,cont.length-1)) - - else - $("#console").append("|") - } - else{ - blinkCounter += 1 - } - - } - } } @@ -236,8 +206,7 @@ function writeAppend(str){ function startTyping(){ - addTextTimer = setInterval("typeWords()", 25) - + addTextTimer = setInterval("typeWords()", 20) } @@ -245,6 +214,22 @@ function typeWords() { Typer.addText() } +document.addEventListener("keydown", KeyCheck); + +function KeyCheck(evt) { + evt = evt || window.event + var charCode = evt.keyCode || evt.which + if(charCode == 8){ + if(inputStr.length > 0){ + console.log(inputStr) + inputStr = inputStr.substring(0, inputStr.length-1) + console.log(inputStr) + Typer.removeChar() + } + } +} + + document.onkeypress = function(evt) { if(acceptInput && !isMobileDevice()){ @@ -257,7 +242,6 @@ document.onkeypress = function(evt) { StoryTracker.processInput(inputStr) } else{ - var charStr = String.fromCharCode(charCode) Typer.appendToText(charStr) inputStr = inputStr + charStr @@ -289,7 +273,6 @@ function start(){ StoryTracker.getFirstStory() startTyping() - Typer.startBlinker() console.log("Not mobile device"); document.getElementById('buttons').style.visibility='hidden'; diff --git a/static/style.css b/static/style.css index c263bdc..742c7e1 100644 --- a/static/style.css +++ b/static/style.css @@ -9,14 +9,15 @@ body { width:80%; margin-left:auto; margin-right:auto; - margin-top:calc(30px + 4.0vh);; + margin-top:calc(30px + 4.0vh); font-size:14px; background-color: #000; } .about { font-family: courier, monospace; - width:750px; + max-width: 800px; + width:80%; margin-left:auto; margin-right:auto; margin-top:100px; @@ -28,7 +29,7 @@ body { } .about h2{ color: #0bc; - font-size:20px; + font-size:16px; } a { @@ -69,26 +70,26 @@ a { #buttons { position: relative; bottom: 0px; - height: 60px; - width: 100%; + height: calc(100px + 12.0vw); + max-width: 800px; + width:80%; color: 334; background-color:#000; - text-align: center; - display: flex; - justify-content: space-between; + margin-left:auto; + margin-right:auto; + display: flex; } button { border-color: #fff; - bottom: 40px; color: #fff; - margin-top: 40px; - margin-left: 4%; - margin-right: 4%; - margin-bottom: 20px; + margin-top: 60px; + margin-left: 3.0vw; + margin-right: 3.0vw; + margin-bottom: 30px; background-color: #111; - width: 18%; - height: 100px; + width: 14.0vw; + height: 12.0vw; text-align: center; border-radius: 25px; font-size:30px; @@ -118,8 +119,7 @@ button:focus{ text-align: center; padding: 10px 5px; text-decoration: none; - font-size:calc(14px + 0.5vh ); - min-font-size: + font-size:18px; } /* Change the color of links on hover */ diff --git a/templates/about.html b/templates/about.html index 0c42a64..abdcf28 100644 --- a/templates/about.html +++ b/templates/about.html @@ -1,10 +1,23 @@ + + + + + About
- Home + Home Support
@@ -18,8 +31,11 @@

As you can probably tell there's still a ways to go before AI will be your group's dungeon master, but even after running hundreds of adventures it still manages to surprise me in interesting ways. I've had a lot of fun making this and hope you enjoy it too. -


If you want to contact me about suggested improvements, comments, etc... feel free to email me about them. Nick Walton "nickwalton00@gmail.com". Also special thanks to Alan Walton and Max Robinson for their help and contributions. - +

Warning: The GPT-2 model was trained on a huge amount of internet text so there might be offensive content. + +

If you want to contact me about suggested improvements, comments, etc... feel free to email me about them at aidungeon.io@gmail.com. + +

AI Dungeon was created by Nick Walton with the support of the BYU Percepton Cognition and Control Lab, Alan Walton and Max Robinson.
diff --git a/templates/index.html b/templates/index.html index 6159914..8800ab6 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,6 +1,18 @@ + + + + Dungeon