SHARE
TWEET

Untitled

a guest Feb 22nd, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * robotMaze.js
  3.  *
  4.  * The blue key is inside a labyrinth, and extracting
  5.  * it will not be easy.
  6.  *
  7.  * It's a good thing that you're a AI expert, or
  8.  * we would have to leave empty-handed.
  9.  */
  10.  
  11. function startLevel(map) {
  12.     // Hint: you can press R or 5 to "rest" and not move the
  13.     // player, while the robot moves around.
  14.  
  15.     map.getRandomInt = function(min, max) {
  16.         return Math.floor(Math.random() * (max - min + 1)) + min;
  17.     }
  18.  
  19.     map.placePlayer(map.getWidth()-1, map.getHeight()-1);
  20.     var player = map.getPlayer();
  21.  
  22.     map.defineObject('robot', {
  23.         'type': 'dynamic',
  24.         'symbol': 'R',
  25.         'color': 'gray',
  26.         'onCollision': function (player, me) {
  27.             me.giveItemTo(player, 'blueKey');
  28.         },
  29.         'behavior': function (me) {
  30.             // move randomly
  31.             var moves = map.getAdjacentEmptyCells(me.getX(), me.getY());
  32.             console.log(moves);
  33.             // getAdjacentEmptyCells gives array of ((x, y), direction) pairs
  34.             //me.move(moves[map.getRandomInt(0, moves.length - 1)][1]);
  35.             me.move(directions[dir]);
  36.         }
  37.     });
  38.         var directions = ['right', 'down', 'left', 'up'];
  39.         var dir = 0;
  40.         player.setPhoneCallback(function () {
  41.           dir = (dir + 1) % directions.length;
  42.           console.log('------');
  43.           console.log(dir);
  44.           console.log(directions[dir]);
  45.           console.log('------');
  46.           if(false) {
  47.         }
  48.     });
  49.  
  50.     map.defineObject('barrier', {
  51.         'symbol': '░',
  52.         'color': 'purple',
  53.         'impassable': true,
  54.         'passableFor': ['robot']
  55.     });
  56.  
  57.     map.placeObject(0, map.getHeight() - 1, 'exit');
  58.     map.placeObject(1, 1, 'robot');
  59.     map.placeObject(map.getWidth() - 2, 8, 'blueKey');
  60.     map.placeObject(map.getWidth() - 2, 9, 'barrier');
  61.  
  62.     var autoGeneratedMaze = new ROT.Map.DividedMaze(map.getWidth(), 10);
  63.     autoGeneratedMaze.create( function (x, y, mapValue) {
  64.         // don't write maze over robot or barrier
  65.         if ((x == 1 && y == 1) || (x == map.getWidth() - 2 && y >= 8)) {
  66.             return 0;
  67.         } else if (mapValue === 1) { //0 is empty space 1 is wall
  68.             map.placeObject(x,y, 'block');
  69.         } else {
  70.             map.placeObject(x,y,'empty');
  71.         }
  72.     });
  73. }
  74.  
  75. function validateLevel(map) {
  76.     map.validateExactlyXManyObjects(1, 'exit');
  77.     map.validateExactlyXManyObjects(1, 'robot');
  78.     map.validateAtMostXObjects(1, 'blueKey');
  79. }
  80.  
  81. function onExit(map) {
  82.     if (!map.getPlayer().hasItem('blueKey')) {
  83.         map.writeStatus("We need to get that key!");
  84.         return false;
  85.     } else {
  86.         return true;
  87.     }
  88. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top