Robot Rumble ALPHA
discord
try it!
boards
tutorial
docs
login
/
signup
let ourRobots = null; let enemyRobots = null; function initTurn(state) { ourRobots = state.objsByTeam(state.ourTeam); enemyRobots = state.objsByTeam(state.otherTeam); } function robot(state, unit) { let closest = closestEnemy(unit); let escapeSpawnDirection = awayFromBorder(unit, state); if (unit.coords.walkingDistanceTo(closest.coords) <= 3) { debug.locate(unit); debug.locate(closest); let enemyDirection = unit.coords.directionTo(closest.coords); let outputDirection = enemyDirection.opposite; while(!canGo(unit, outputDirection, state) || outputDirection == enemyDirection) { // rotate until there is good spot to go outputDirection = outputDirection.rotateCw; } return Action.move(outputDirection); } else if (escapeSpawnDirection != null) { return Action.move(escapeSpawnDirection); } return null; } function closestEnemy(unit) { let closest = null; let closestDistance = 100000; enemyRobots.forEach(function(enemy) { let distance = enemy.coords.walkingDistanceTo(unit.coords); if (distance < closestDistance) { closest = enemy; closestDistance = distance; } }); return closest; } // checks if unit is trying to go out of the map function canGo(unit, direction, state) { let objFromCoords = state.objByCoords(direction.toCoords.add(unit.coords)); if (objFromCoords == null) { return true; } return false; } // if it's next to a border it will return a direction to get away // otherwise it will return null function awayFromBorder(unit, state) { // edges of the map == ObjType.Terrain let northObj = state.objByCoords(Direction.North.toCoords.add(unit.coords)); let eastObj = state.objByCoords(Direction.East.toCoords.add(unit.coords)); let southObj = state.objByCoords(Direction.South.toCoords.add(unit.coords)); let westObj = state.objByCoords(Direction.West.toCoords.add(unit.coords)); if (northObj != null && northObj.objType == ObjType.Terrain) { return Direction.South; } else if (eastObj != null && eastObj.objType == ObjType.Terrain) { return Direction.West; } else if (southObj != null && southObj.objType == ObjType.Terrain) { return Direction.North; } else if (westObj != null && westObj.objType == ObjType.Terrain) { return Direction.East; } return null; }
Made with <3 by Anton and Noa
github org