Advertisement
Guest User

Untitled

a guest
Jan 24th, 2015
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     /* draw the map on canvas */
  2.     Draw.init();
  3.     Draw.canvasdraw(document.getElementById("Canvas1"));
  4.  
  5.     /* draws the player on start location */
  6.     Draw.drawmove(document.getElementById("Canvas1"),agent.currPos.x,agent.currPos.y)
  7.  
  8.     var game = setInterval(gameLoop, 1000);
  9.     /* create a new agent */
  10.     function gameLoop(){
  11.         if(steps > MAX_STEPS) {
  12.             console.log("--------------------------------------");
  13.             console.log("I couldn't find the gold :(");
  14.             console.log("--------------------------------------");
  15.             clearInterval(game);
  16.         }
  17.  
  18.         /* move */
  19.         agent.move();
  20.         Draw.drawmove(document.getElementById("Canvas1"),"forward",agent.currPos.x,agent.currPos.y);
  21.         Map.gatherAdjacentInfo(agent);
  22.  
  23.         /* see if the agent is still alive */
  24.         if(Map.tiles[agent.currPos.x][agent.currPos.y].hasPit) {
  25.             console.log("--------------------------------------");
  26.             console.log("Aaaahhhh!");
  27.             console.log("--------------------------------------");
  28.             clearInterval(game);
  29.         }
  30.  
  31.         if(Map.tiles[agent.currPos.x][agent.currPos.y].hasWumpus) {
  32.             console.log("--------------------------------");
  33.             console.log("Noo! The agent has been eaten by the Wumpus!");
  34.             console.log("--------------------------------------");
  35.             clearInterval(game);
  36.         }
  37.         /*-----------------------------------*/
  38.         steps++;
  39.  
  40.         /* going back to the start */
  41.         if(agent.hasGold) {
  42.             console.log("--------------------------------------");
  43.             console.log("Going back to the start...");
  44.             console.log("--------------------------------------");
  45.  
  46.             while(SearchTree.closedList.length > 0) {
  47.                 if(agent.currPos.x == 3 && agent.currPos.y == 0) break;
  48.                 else {
  49.                     agent.goBack();
  50.                     Draw.drawmove(document.getElementById("Canvas1"),"backward",agent.currPos.x,agent.currPos.y);
  51.                 }
  52.             }
  53.  
  54.             console.log("--------------------------------------");
  55.             console.log("Woohoo!! I am rich!!");
  56.             console.log("--------------------------------------");
  57.             clearInterval(game);
  58.         }
  59.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement