ai-code-battle/bots/kamikaze/grid.js
jedarden f11d00a177 feat(bot): add Assassin bot (Rust) — decapitation archetype
All units rush the nearest enemy core via BFS, ignoring enemy units
and economy. No perimeter defense — full commitment to core destruction.
Targets persist across turns for consistent pathing.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-22 16:55:33 -04:00

29 lines
757 B
JavaScript

function toroidalDelta(a, b, size) {
const d = Math.abs(a - b);
return Math.min(d, size - d);
}
function distance2(r1, c1, r2, c2, rows, cols) {
const dr = toroidalDelta(r1, r2, rows);
const dc = toroidalDelta(c1, c2, cols);
return dr * dr + dc;
}
function manhattan(r1, c1, r2, c2, rows, cols) {
return toroidalDelta(r1, r2, rows) + toroidalDelta(c1, c2, cols);
}
function moveDir(row, col, dir, rows, cols) {
switch (dir) {
case "N": return [(row - 1 + rows) % rows, col];
case "E": return [row, (col + 1) % cols];
case "S": return [(row + 1) % rows, col];
case "W": return [row, (col - 1 + cols) % cols];
}
}
function posKey(r, c) {
return `${r},${c}`;
}
module.exports = { distance2, manhattan, moveDir, posKey };