Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function clean(bot, target, cleaners) {
- return grid.filter(c => c.id === target.id && !c.reserved).reduce((best, n) => {
- const distance = bot.distance(pos);
- const closest = Math.min(...cleaners.map(b => b.distance(pos)));
- const wrongness = distance - closest;
- if (wrongness < best.wrongness || (wrongness === best.wrongness && (distance < best.distance))) {
- best.arr = [];
- }
- }, {arr: [], wrongness: Infinity, distance: Infinity});
- return grid.reduce((best, c, i) => {
- const pos = XY.fromIndex(i);
- const closest = Math.min(...cleaners.map(b => b.distance(pos)));
- const distance = bot.distance(pos);
- const wrongness = distance - closest;
- const distanceFromTarget = target.distance(pos);
- if (c.id === target.id && !c.reserved && (wrongness < best.wrongness || (wrongness === best.wrongness && (distance < best.distance || (distance === best.distance && distanceFromTarget > best.distanceFromTarget))))) {
- return {wrongness: wrongness, distance: distance, distanceFromTarget: distanceFromTarget, pos: pos};
- } else {
- return best;
- }
- }, {wrongness: Infinity, distance: Infinity, distanceFromTarget: -Infinity, pos: bot}).pos;
- }
- function roam(bot) {
- const dangerousBots = bots.filter(b => !b.member && separation(b.id, bot.id) !== 2);
- return grid.reduce((best, c, i) => {
- const pos = XY.fromIndex(i);
- const val = value(c.id, bot);
- const distance = bot.distance(pos);
- const comfyness = pos.getNeighbors().reduce((sum, next) => sum + (value(at(next).id, bot) <= 2), 0);
- const closestBotDist = Math.min(...dangerousBots.map(b => b.distance(pos)));
- 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))))))) {
- return {distance: distance, val: val, comfyness: comfyness, closestBotDist: closestBotDist, pos: pos};
- } else {
- return best;
- }
- }, {distance: Infinity, val: -Infinity, comfyness: -Infinity, closestBotDist: -Infinity, pos: bot}).pos;
- }
Advertisement
Add Comment
Please, Sign In to add comment