Guest User

Untitled

a guest
Aug 26th, 2018
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function clean(bot, target, cleaners) {
  2.   return grid.filter(c => c.id === target.id && !c.reserved).reduce((best, n) => {
  3.     const distance = bot.distance(pos);
  4.     const closest = Math.min(...cleaners.map(b => b.distance(pos)));
  5.     const wrongness = distance - closest;
  6.     if (wrongness < best.wrongness || (wrongness === best.wrongness && (distance < best.distance))) {
  7.       best.arr = [];
  8.     }
  9.   }, {arr: [], wrongness: Infinity, distance: Infinity});
  10.   return grid.reduce((best, c, i) => {
  11.     const pos = XY.fromIndex(i);
  12.     const closest = Math.min(...cleaners.map(b => b.distance(pos)));
  13.     const distance = bot.distance(pos);
  14.     const wrongness = distance - closest;
  15.     const distanceFromTarget = target.distance(pos);
  16.     if (c.id === target.id && !c.reserved && (wrongness < best.wrongness || (wrongness === best.wrongness && (distance < best.distance || (distance === best.distance && distanceFromTarget > best.distanceFromTarget))))) {
  17.       return {wrongness: wrongness, distance: distance, distanceFromTarget: distanceFromTarget, pos: pos};
  18.     } else {
  19.       return best;
  20.     }
  21.   }, {wrongness: Infinity, distance: Infinity, distanceFromTarget: -Infinity, pos: bot}).pos;
  22. }
  23. function roam(bot) {
  24.   const dangerousBots = bots.filter(b => !b.member && separation(b.id, bot.id) !== 2);
  25.   return grid.reduce((best, c, i) => {
  26.     const pos = XY.fromIndex(i);
  27.     const val = value(c.id, bot);
  28.     const distance = bot.distance(pos);
  29.     const comfyness = pos.getNeighbors().reduce((sum, next) => sum + (value(at(next).id, bot) <= 2), 0);
  30.     const closestBotDist = Math.min(...dangerousBots.map(b => b.distance(pos)));
  31.     if (val >= 4 && !swarm.find(m => m.id === c.id) && !c.bot && (distance < best.distance || (distance === best.distance && (val > best.val || (val === best.val && (comfyness > best.comfyness || (comfyness === best.comfyness && closestBotDist > best.closestBotDist))))))) {
  32.       return {distance: distance, val: val, comfyness: comfyness, closestBotDist: closestBotDist, pos: pos};
  33.     } else {
  34.       return best;
  35.     }
  36.   }, {distance: Infinity, val: -Infinity, comfyness: -Infinity, closestBotDist: -Infinity, pos: bot}).pos;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment