diff --git a/__pycache__/generator.cpython-37.pyc b/__pycache__/generator.cpython-37.pyc index a2c23a6..9569240 100644 Binary files a/__pycache__/generator.cpython-37.pyc and b/__pycache__/generator.cpython-37.pyc differ diff --git a/main.py b/main.py index c4472fc..c44e0b1 100644 --- a/main.py +++ b/main.py @@ -31,6 +31,7 @@ from flask import Flask, render_template, request app = Flask(__name__) phrases = [" You attack", " You use", " You tell", " You use"] +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"] session = None generator = None @@ -45,17 +46,29 @@ def root(): @app.route('/generate', methods=['POST']) def story_request(): print("****Generating Story****") - prompt = request.form["prompt"] # given prompt - gen_actions = request.form["actions"] # given prompt - - print("\n Given prompt is: \n",prompt," ","\n") + seed = request.form["seed"] + gen_actions = request.form["actions"] generator = get_generator() if gen_actions == "true": + initial_prompt_num = int(request.form["prompt_num"]) + prompt = request.form["prompt"] + choices = json.loads(request.form["choices"]) # used for caching lookup + + # TODO implement caching based on seed, prompt_num and choices + + + action_results = [generator.generate_action_result(prompt, phrase) for phrase in phrases] response = json.dumps(action_results) else: + prompt_num = int(request.form["prompt_num"]) + + # TODO implement caching based on seed, and prompt_num + + + prompt = prompts[prompt_num] response = generator.generate_story_block(prompt) print("\nGenerated response is: \n", response) diff --git a/static/script.js b/static/script.js index 356af10..6fd6a47 100644 --- a/static/script.js +++ b/static/script.js @@ -1,4 +1,4 @@ -initial_prompt = "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" +var 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"] start_text = "Adventurer@AIDungeon:~$ ./EnterDungeon \n
" @@ -7,6 +7,10 @@ var acceptInput=false var inputStr = "" 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 = 100 +var seed = Math.floor(Math.random() * (+seed_max - +seed_min)) + +seed_min; var StoryTracker = { firstStory: null, @@ -14,13 +18,14 @@ var StoryTracker = { lastAction: null, actions: [], results: [], + choices: [], action_int: 0, - startPrompt: initial_prompt, + startPrompt: prompts[prompt_num], getFirstStory:function(){ console.log("Requesting first story") - Typer.appendToText(initial_prompt) - StoryTracker.requestStory(initial_prompt) + Typer.appendToText(StoryTracker.startPrompt) + StoryTracker.requestFirstStory(StoryTracker.startPrompt) }, @@ -46,7 +51,6 @@ 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 @@ -58,43 +62,27 @@ var StoryTracker = { StoryTracker.action_int = 0 acceptInput = true - if( /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ) { - setTimeout(StoryTracker.mobileButton, 1000); - } - } } }, - mobileButton:function(){ - - if (Typer.index >= Typer.text.length -1){ - inputStr = window.prompt("What is your choice?","0"); - StoryTracker.processInput() - } - else{ - setTimeout(StoryTracker.mobileButton, 1000); - } - }, - makeActionRequests:function(prompt){ StoryTracker.actions = [] StoryTracker.results = [] - StoryTracker.requestAction(prompt) - - + StoryTracker.requestActions(prompt, JSON.stringify(StoryTracker.choices)) }, + - requestStory:function(prompt){ - $.post("/generate", {actions: false, prompt}, + requestFirstStory:function(prompt){ + $.post("/generate", {actions: false, seed, prompt_num}, StoryTracker.addNextStory) }, - requestAction:function(prompt){ - $.post("/generate", {actions: true, prompt}, + requestActions:function(prompt, choices){ + $.post("/generate", {actions: true, seed, prompt_num, prompt, choices}, StoryTracker.addNextAction) }, @@ -104,6 +92,7 @@ var StoryTracker = { if(choice_int >= 0 && choice_int <= 3){ console.log("choice_int is %d", choice_int) + StoryTracker.actions.push(choice_int) StoryTracker.lastAction = StoryTracker.actions[choice_int] StoryTracker.lastStory = StoryTracker.results[choice_int] StoryTracker.makeActionRequests(StoryTracker.firstStory + StoryTracker.lastStory) @@ -117,10 +106,6 @@ var StoryTracker = { Typer.appendToText("\nWhich action do you choose? ") acceptInput=true - if( /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ) { - setTimeout(StoryTracker.mobileButton, 1000); - } - } @@ -193,7 +178,7 @@ function writeAppend(str){ function startTyping(){ - addTextTimer = setInterval("typeWords()", 50) + addTextTimer = setInterval("typeWords()", 40) }