Advertisement
Guest User

Vampire

a guest
Aug 17th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var TARGET_ARRANGEMENT_RAIL = [
  2.     [3,5,6,1,6,7,6,2,8],
  3.     [3,5,6,4,6,7,6,2,8],
  4.     [1,6,7,6,2,8,3,5,6],
  5.     [4,6,7,6,2,8,3,5,6],
  6.     [6,2,8,3,5,6,1,6,7],
  7.     [6,2,8,3,5,6,4,6,7]
  8. ];
  9. var TARGET_COLOURS_RAIL = colour_band([6, 5, 2]);
  10. var rail_miners = {
  11.   likely_nest: function(colours) {
  12.     var bestScore = 0;
  13.     TARGET_ARRANGEMENT_RAIL.forEach(function (arrangement) {
  14.         ROTATIONS.forEach(function (rot){
  15.             var score = 0;
  16.             for(var i = 0; i < 9; i++) {
  17.                 score += arrangement[i] == view[rot[i]].color?1:0;
  18.             }
  19.             if(score > bestScore) {
  20.                 bestScore = score;
  21.             }
  22.         });
  23.     });
  24.     if(bestScore >= 6) {
  25.         return true;
  26.     }
  27.  
  28.     return false;
  29.   },
  30.  
  31.   likely_victim: function(victim_pos) {
  32.     var c0 = TARGET_COLOURS_RAIL.next(WHITE);
  33.     var c1 = TARGET_COLOURS_RAIL.next(c0);
  34.     if(view[victim_pos].color !== c0) {
  35.       return false;
  36.     }
  37.     for(var i = 0; i < 9; ++ i) {
  38.       if(i !== victim_pos && near(i, victim_pos) && view[i].color === c1) {
  39.         return true;
  40.       }
  41.     }
  42.     return false;
  43.   },
  44.  
  45.   follow_victim: function(me, buddies, colours, victim_pos) {
  46.     if(me.type === THIEF && !buddies[QUEEN]) {
  47.       // Queen may be on other side of victim; try orbiting to find her
  48.       return try_all_angles([
  49.         (rot) => ((victim_pos === rot[1]) ? {cell: rot[0]} : null),
  50.         (rot) => ((victim_pos === rot[0]) ? {cell: rot[3]} : null)
  51.       ]);
  52.     }
  53.  
  54.     if(me.type === QUEEN && !buddies[THIEF] && me.food > 0) {
  55.       // Make a buddy to help us steal
  56.       return best_of([
  57.         try_all_cells((i) => (near(i, victim_pos) ? {cell: i, type: THIEF} : null), true),
  58.         try_all_cells((i) => ({cell: i, type: THIEF}), true)
  59.       ]);
  60.     }
  61.  
  62.     return best_of([
  63.       // Ziggurat will try to drown us in workers; make sure we have plenty
  64.       // of our own (but only if it's worth it)
  65.       (view[victim_pos].ant.food > 4) &&
  66.         try_all_cells((i) => (near(i, victim_pos) ? {cell: i, type: THIEF} : null), true),
  67.  
  68.       // Continue to steal and get fat
  69.       NOP
  70.     ]);
  71.   },
  72.  
  73.   find_victim: function(me, buddies, colours) {
  74.     var current = view[CENTRE].color;
  75.  
  76.     // Easier to navigate alone, and thief reaching queen first would be a
  77.     // disaster, so the thief just gives up.
  78.     if(me.type === THIEF) {
  79.       return go_anywhere;
  80.     }
  81.  
  82.     var target = colour_band_prev(TARGET_COLOURS_RAIL, current);
  83.     var antitarget = colour_band_prev(TARGET_COLOURS_RAIL, target);
  84.     var ret = best_of([
  85.       try_all_cells((i) => ((i % 2 == 1 && view[i].color == target && view[8-i].color == antitarget) ? {cell: i} : null)),
  86.       //try_all_cells((i) => ((view[i].color == current) ? {cell: i} : null)),
  87.  
  88.       // Random walk to avoid getting stuck
  89.       {cell:4}
  90.     ]);
  91.  
  92.     if(ret == null || ret.cell == 4) {
  93.       var numAnts = 0;
  94.       for(var na = 0; na < 9; na++) {
  95.         if(view[na].ant != null) numAnts++;
  96.       }
  97.       if(numAnts == 1) ret = go_anywhere;
  98.     }
  99.     return ret;
  100.   }
  101. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement