SHARE
TWEET

Untitled

a guest Sep 23rd, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /****************
  2.  * drones101.js *
  3.  ****************
  4.  *
  5.  * Do you remember, my dear Professor, a certain introductory
  6.  * computational rationality class you taught long ago? Assignment
  7.  * #2, behavior functions of autonomous agents? I remember that one
  8.  * fondly - but attack drones are so much easier to reason about
  9.  * when they're not staring you in the face, I would imagine!
  10.  */
  11.  
  12. function startLevel(map) {
  13.     function moveToward(obj, type) {
  14.         var target = obj.findNearest(type);
  15.         var leftDist = obj.getX() - target.x;
  16.         var upDist = obj.getY() - target.y;
  17.  
  18.         var direction;
  19.         if (upDist == 0 && leftDist == 0) {
  20.             return;
  21.         } if (upDist > 0 && upDist >= leftDist) {
  22.             direction = 'up';
  23.         } else if (upDist < 0 && upDist < leftDist) {
  24.             direction = 'down';
  25.         } else if (leftDist > 0 && leftDist >= upDist) {
  26.             direction = 'left';
  27.         } else {
  28.             direction = 'right';
  29.         }
  30.  
  31.         if (obj.canMove(direction)) {
  32.             obj.move(direction);
  33.         }
  34.     }
  35.  
  36.     map.defineObject('attackDrone', {
  37.         'type': 'dynamic',
  38.         'symbol': 'd',
  39.         'color': 'red',
  40.         'onCollision': function (player) {
  41.             player.killedBy('an attack drone');
  42.         },
  43.         'behavior': function (me) {
  44.             moveToward(me, 'player');
  45.         }
  46.     });
  47.  
  48.  
  49.     map.placePlayer(1, 1);
  50.     map.placeObject(map.getWidth()-2, 12, 'attackDrone');
  51.     map.placeObject(map.getWidth()-1, 12, 'exit');
  52.  
  53.     map.placeObject(map.getWidth()-1, 11, 'block');
  54.     map.placeObject(map.getWidth()-2, 11, 'block');
  55.     map.placeObject(map.getWidth()-1, 13, 'block');
  56.     map.placeObject(map.getWidth()-2, 13, 'block');
  57.  
  58.  
  59.     map.defineObject('attackDrone2', {
  60.         'type': 'dynamic',
  61.         'symbol': 'd',
  62.         'color': 'blue',
  63.         'onCollision': function (attackDrone) {
  64.             attackdrone.killedBy('an attack drone');
  65.         },
  66.         'behavior': function (me) {
  67.             moveToward(me, 'attackDrone');
  68.         }
  69.     });
  70.  
  71.  
  72.     map.defineObject('attackDrone3', {
  73.         'type': 'dynamic',
  74.         'symbol': 'd',
  75.         'color': 'blue',
  76.         'onCollision': function (attackDrone) {
  77.             attackdrone.killedBy('an attack drone');
  78.         },
  79.         'behavior': function (me) {
  80.             moveToward(me, 'attackDrone');
  81.         }
  82.     });
  83.  
  84.  
  85.     map.defineObject('attackDrone4', {
  86.         'type': 'dynamic',
  87.         'symbol': 'd',
  88.         'color': 'blue',
  89.         'onCollision': function (attackDrone) {
  90.             attackdrone.killedBy('an attack drone');
  91.         },
  92.         'behavior': function (me) {
  93.             moveToward(me, 'attackDrone');
  94.         }
  95.     });
  96.  
  97.  
  98.     map.defineObject('attackDrone5', {
  99.         'type': 'dynamic',
  100.         'symbol': 'd',
  101.         'color': 'blue',
  102.         'onCollision': function (attackDrone) {
  103.             player.killedBy('an attack drone');
  104.         },
  105.         'behavior': function (me) {
  106.             moveToward(me, 'attackDrone');
  107.         }
  108.     });
  109.  
  110.     map.placeObject(3, 12, 'attackDrone2');
  111. map.placeObject(map.getWidth()/2, 3, 'attackDrone3');
  112.  
  113. //map.placeObject(map.getWidth()-2, 12, 'attackDrone4');
  114.  
  115. map.placeObject(map.getWidth()/2, map.getHeight() -3 , 'attackDrone5');
  116.  
  117.  
  118.  
  119.  
  120. }
  121.  
  122. function validateLevel(map) {
  123.     map.validateExactlyXManyObjects(1, 'exit');
  124. }
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