SHARE
TWEET

Untitled

a guest Aug 22nd, 2019 74 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.        
  31.             if (arr == undefined)
  32.             {
  33.                 arr = new Array();
  34.                 for (var i = 0; i < 80; i++)
  35.                     {
  36.                     arr[i] = new Array();
  37.                     for (var j = 0; j < 80; j++)
  38.                         arr[i][j] = 0;
  39.                     }
  40.             }
  41.            
  42.             var min = 9999;
  43.             var x = me.getX();
  44.             var y = me.getY();
  45.             if (y > 15) return;
  46.             var dir = '';
  47.             if (me.canMove('up') && arr[y-1][x] < min) {
  48.                 min = arr[y-1][x]; dir='up'; }
  49.             if (me.canMove('left') && arr[y][x-1] < min) {
  50.                 min = arr[y][x-1]; dir='left';}
  51.            if (me.canMove('down') && arr[y+1][x] <= min) {
  52.                 min = arr[y+1][x]; dir='down'; }
  53.             if (me.canMove('right') && arr[y][x+1] <= min) {
  54.                 min = arr[y][x+1]; dir='right';}
  55.             arr[y][x]++;
  56.             me.move(dir);
  57.             }
  58.             });
  59.            
  60.             var arr;
  61.             map.getPlayer().setPhoneCallback(function () {
  62.             {
  63.             map.setSquareColor(map.getPlayer().getX()-1, map.getPlayer().getY()
  64.             , '#fff');
  65.  
  66.         }
  67.     });
  68.  
  69.     map.defineObject('barrier', {
  70.         'symbol': '░',
  71.         'color': 'purple',
  72.         'impassable': true,
  73.         'passableFor': ['robot']
  74.     });
  75.  
  76.     map.placeObject(0, map.getHeight() - 1, 'exit');
  77.     map.placeObject(1, 1, 'robot');
  78.     map.placeObject(map.getWidth() - 2, 8, 'blueKey');
  79.     map.placeObject(map.getWidth() - 2, 9, 'barrier');
  80.  
  81.     var autoGeneratedMaze = new ROT.Map.DividedMaze(map.getWidth(), 10);
  82.     autoGeneratedMaze.create( function (x, y, mapValue) {
  83.         // don't write maze over robot or barrier
  84.         if ((x == 1 && y == 1) || (x == map.getWidth() - 2 && y >= 8)) {
  85.             return 0;
  86.         } else if (mapValue === 1) { //0 is empty space 1 is wall
  87.             map.placeObject(x,y, 'block');
  88.         } else {
  89.             map.placeObject(x,y,'empty');
  90.         }
  91.     });
  92. }
  93.  
  94. function validateLevel(map) {
  95.     map.validateExactlyXManyObjects(1, 'exit');
  96.     map.validateExactlyXManyObjects(1, 'robot');
  97.     map.validateAtMostXObjects(1, 'blueKey');
  98. }
  99.  
  100. function onExit(map) {
  101.     if (!map.getPlayer().hasItem('blueKey')) {
  102.         map.writeStatus("We need to get that key!");
  103.         return false;
  104.     } else {
  105.         return true;
  106.     }
  107. }
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