Robot Rumble ALPHA
discord
try it!
boards
tutorial
docs
login
/
signup
const pathfindTo = (state, from, to) => { let queue = []; let discovered = new Set(); discovered.add(from.toString()); queue.push(from); while (queue.length > 0) { let node = queue.shift(); if (node.walkingDistanceTo(to) == 0) { let path = [node]; while(node.parent) { node = node.parent; path.push(node); } return path; } for (let direction of [Direction.North, Direction.South, Direction.West, Direction.East]) { let newNode = node.add(direction.toCoords); let obj = state.objByCoords(newNode); let isSameTeam = obj != null && obj.objType == ObjType.Unit && obj.team == state.ourTeam; // console.log(obj?.objType == ObjType.Terrain); if (obj?.objType != ObjType.Terrain && (!isSameTeam) && !discovered.has(newNode.toString())) { discovered.add(newNode.toString()); newNode.parent = node; queue.push(newNode); } } } return []; }; function robot(state, unit) { let enemies = state.objsByTeam(state.otherTeam) let closestEnemy = _.minBy(enemies, e => e.coords.distanceTo(unit.coords) ); let distance = unit.coords.distanceTo(closestEnemy.coords); if (distance === 1) return Action.attack(unit.coords.directionTo(closestEnemy.coords)); else { const path = pathfindTo(state, unit.coords, closestEnemy.coords); debug.log("Path", path); debug.log("Direction", path[path.length - 2]); if (path.length === 0) return null; return Action.move(unit.coords.directionTo(path[path.length - 2])); } let direction = unit.coords.directionTo(closestEnemy.coords); }
Made with <3 by Anton and Noa
github org