Advertisement
Guest User

Js Rhino Centre Bot

a guest
Mar 18th, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var arena = {};
  2.  
  3. arena.map = arguments[0];
  4. arena.rows = arena.map.split('\\n');
  5.  
  6.  
  7. arena.find = function(toFind){
  8.     for(var i = 0; i < 10; i++){
  9.         if(typeof arena.rows[i] !== 'undefined'){
  10.             if(arena.rows[i].indexOf(toFind) !== -1){
  11.                 return [arena.rows[i].search(toFind), i];
  12.             }
  13.         }
  14.     }
  15. };
  16. arena.findAtPos = function(x, y){
  17.     return arena.rows[y].charAt(x);
  18. };
  19.  
  20. me = {};
  21.     me.pos = arena.find('Y');
  22.     me.x = me.pos[0];
  23.     me.y = me.pos[1];
  24.     me.energy = parseInt(arena.rows[10].replace("Y ", ""));
  25.    
  26. foe = {};
  27.     foe.pos = arena.find('X');
  28.     foe.x = foe.pos[0];
  29.     foe.y = foe.pos[1];
  30.     foe.energy = parseInt(arena.rows[11].replace("X ", ""));
  31. function FindFoe(){
  32.     if(me.x < foe.x){
  33.         if(me.y < foe.y){
  34.             foe.direction = 'NW';
  35.         }
  36.         else if(me. y  === foe.y){
  37.             foe.direction  = 'W';
  38.         }
  39.         else{
  40.             foe.direction = 'SW'
  41.         }
  42.     }
  43.     if(me.x === foe.x){
  44.         if(me.y < foe.y){
  45.             foe.direction = 'N';
  46.         }
  47.         else{
  48.             foe.direction = 'S'
  49.         }
  50.     }
  51.     if(me.x > foe.x){
  52.         if(me.y < foe.y){
  53.             foe.direction = 'NE';
  54.         }
  55.         else if(me. y  === foe.y){
  56.             foe.direction  = 'E';
  57.         }
  58.         else{
  59.             foe.direction = 'SE'
  60.         }
  61.     }
  62. }
  63.  
  64. function findCentre(){
  65.     if(me.x < 4){
  66.         if(me.y < 4){
  67.             centreDirection = 'NW';
  68.         }
  69.         else if(me. y  === 4){
  70.             centreDirection  = 'W';
  71.         }
  72.         else{
  73.             centreDirection = 'SW'
  74.         }
  75.     }
  76.     if(me.x === 4){
  77.         if(me.y < 4){
  78.             centreDirection = 'N';
  79.         }
  80.         else{
  81.             centreDirection = 'S'
  82.         }
  83.     }
  84.     if(me.x > 4){
  85.         if(me.y < 4){
  86.             centreDirection = 'NE';
  87.         }
  88.         else if(me. y  === 4){
  89.             centreDirection  = 'E';
  90.         }
  91.         else{
  92.             centreDirection = 'SE'
  93.         }
  94.     }
  95. }
  96.  
  97. if(me.x !== 4 && me.y !== 4){
  98.     print(centerDirection);
  99. }else{
  100.     print('B ' + foe.direction);
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement