// if soldier is in range of stuff but doesn't see it, sets it to null public static void resetLocations(RobotController rc) throws GameActionException { if (nearestTurretLocation != null && myLoc.distanceSquaredTo(nearestTurretLocation) <= 13 && (rc.senseRobotAtLocation(nearestTurretLocation) == null || rc.senseRobotAtLocation(nearestTurretLocation).type != RobotType.TURRET || !rc.senseRobotAtLocation(nearestTurretLocation).team.equals(enemyTeam))) { if (nearestTurretLocation.equals(currentDestination)) currentDestination = null; nearestTurretLocation = null; } if (nearestEnemyLocation != null && myLoc.distanceSquaredTo(nearestEnemyLocation) <= 13 && (rc.senseRobotAtLocation(nearestEnemyLocation) == null || !rc.senseRobotAtLocation(nearestEnemyLocation).team.equals(enemyTeam))) { if (nearestEnemyLocation.equals(currentDestination)) currentDestination = null; nearestEnemyLocation = null; } if (nearestDenLocation != null && rc.canSense(nearestDenLocation) && (rc.senseRobotAtLocation(nearestDenLocation) == null || rc.senseRobotAtLocation(nearestDenLocation).type != RobotType.ZOMBIEDEN)) { if (nearestDenLocation.equals(currentDestination)) currentDestination = null; nearestDenLocation = null; } if (nearestDistressedArchon != null && myLoc.distanceSquaredTo(nearestDistressedArchon) <= 13 && (rc.senseRobotAtLocation(nearestDistressedArchon) == null || !rc.senseRobotAtLocation(nearestDistressedArchon).team.equals(enemyTeam)) || distressedArchonTurns > 5) { if (nearestDistressedArchon != null && nearestDistressedArchon.equals(currentDestination)) currentDestination = null; nearestDistressedArchon = null; distressedArchonTurns = 0; } }
static void activateCommon(RobotController rc, MapLocation loc) throws GameActionException { rc.activate(loc); lastBuiltLocation = loc; RobotInfo info = rc.senseRobotAtLocation(lastBuiltLocation); addInfo(info); lastBuiltId = info.ID; }
static void buildCommon(RobotController rc, Direction dir, RobotType robotType) throws GameActionException { rc.build(dir, robotType); lastBuiltLocation = rc.getLocation().add(dir); RobotInfo info = rc.senseRobotAtLocation(lastBuiltLocation); addInfo(info); lastBuiltId = info.ID; }
private static boolean isBlockingSomeone(RobotController rc, MapLocation target) throws GameActionException { Direction dir = myLoc.directionTo(target); MapLocation behind = myLoc.add(dir.opposite()); MapLocation left = behind.add(dir.rotateLeft()); MapLocation right = behind.add(dir.rotateRight()); // There is someone behind us if (rc.senseRobotAtLocation(behind) != null) { // If there is stuff blocking on both sides, then blocking if (!rc.canMove(myLoc.directionTo(left)) && !rc.canMove(myLoc.directionTo(right))) { return true; } } return false; }
private static void removeTurretLocations(RobotController rc) throws GameActionException { MapLocation[] removedLocations = new MapLocation[turretLocations.size()]; int removedLength = 0; for (MapLocation location : turretLocations) { if (rc.canSenseLocation(location)) { RobotInfo info = rc.senseRobotAtLocation(location); if (info == null) { removedLocations[removedLength++] = location; } else if (info.team != enemyTeam || (info.team == enemyTeam && info.type != RobotType.TURRET)) { removedLocations[removedLength++] = location; } } } for (int i = 0; i < removedLength; i++) { turretLocations.remove(removedLocations[i]); } }
protected void gatherMapInfo(MapLocation targetObjLoc) throws GameActionException { // This is for a single place, used for rescue updates if (rc.canSense(targetObjLoc)) { RobotInfo targetRobot = rc.senseRobotAtLocation(targetObjLoc); if (targetRobot != null) { if (targetRobot.team.equals(Team.NEUTRAL)) { // IS a neutral robot memory.addNeutralRobotMapInfo(targetObjLoc, targetRobot); } else if (targetRobot.team.equals(Team.ZOMBIE)) { memory.addMapInfo( targetObjLoc, (int) targetRobot.health, RobotConstants.mapTypes.ZOMBIE_DEN); } } memory.addMapInfo( targetObjLoc, (int) rc.senseRubble(targetObjLoc), RobotConstants.mapTypes.RUBBLE); memory.addMapInfo( targetObjLoc, (int) rc.senseParts(targetObjLoc), RobotConstants.mapTypes.PARTS); } }
private static void rushMicro(RobotController rc, RobotInfo[] hostiles) throws GameActionException { // Prioritizes attacking turrets. RobotInfo bestEnemy = null; boolean canAttackBestEnemy = false; int bestEnemyDist = 10000; // only care if can't hit for (RobotInfo hostile : hostiles) { // Can attack this enemy. int dist = myLoc.distanceSquaredTo(hostile.location); // Summary: // Prioritizes enemies over zombies. // Prioritizes turret enemies over other enemies. // Prioritizes lowest health enemy last if (dist <= attackRadius) { if (bestEnemy != null) { if (bestEnemy.team == enemyTeam) { // best is already enemy if (hostile.team == enemyTeam) { // found an enemy if (countsAsTurret(bestEnemy.type)) { if (countsAsTurret(hostile.type)) { // Take lowest health if (bestEnemy.health > hostile.health) bestEnemy = hostile; } } else { if (countsAsTurret(hostile.type)) { bestEnemy = hostile; } else { // Take lowest health if (bestEnemy.health > hostile.health) bestEnemy = hostile; } } } } else { // best is not an enemy! if (hostile.team == enemyTeam) { // found an enemy bestEnemy = hostile; } else { // Take lowest health if (bestEnemy.health > hostile.health) bestEnemy = hostile; } } } else { bestEnemy = hostile; } canAttackBestEnemy = true; } else { // Only update best enemy if you can't attack best enemy if (!canAttackBestEnemy) { if (bestEnemy != null) { // Pick the closest one if (bestEnemyDist > dist) { bestEnemyDist = dist; bestEnemy = hostile; } } else { bestEnemyDist = dist; bestEnemy = hostile; } } } } rc.setIndicatorString(0, "Round: " + rc.getRoundNum() + ", Best enemy: " + bestEnemy); if (rc.isCoreReady()) { // If there is a best enemy, attack him. if (bestEnemy != null) { // Move closer only if blocking someone. if (rc.canAttackLocation(bestEnemy.location)) { if (isBlockingSomeone(rc, bestEnemy.location)) { Direction desired = myLoc.directionTo(bestEnemy.location); Direction dir = Movement.getBestMoveableDirection(desired, rc, 2); if (dir != Direction.NONE) { rc.move(dir); } else if (shouldMine(rc, desired)) { rc.clearRubble(desired); } else if (shouldMine(rc, desired.rotateLeft())) { rc.clearRubble(desired.rotateLeft()); } else if (shouldMine(rc, desired.rotateRight())) { rc.clearRubble(desired.rotateRight()); } } } // If can't attack it, move closer! else { Direction desired = myLoc.directionTo(bestEnemy.location); Direction dir = Movement.getBestMoveableDirection(desired, rc, 2); if (dir != Direction.NONE) { rc.move(dir); } else if (shouldMine(rc, desired)) { rc.clearRubble(desired); } else if (shouldMine(rc, desired.rotateLeft())) { rc.clearRubble(dir.rotateLeft()); } else if (shouldMine(rc, desired.rotateRight())) { rc.clearRubble(desired.rotateRight()); } } } // Otherwise move closer to destination else { if (currentDestination != null) { RobotInfo info = null; if (rc.canSenseLocation(currentDestination)) { info = rc.senseRobotAtLocation(currentDestination); } if (info != null) { // If can attack it, just only move closer if blocking someone behind. if (rc.canAttackLocation(info.location)) { if (isBlockingSomeone(rc, currentDestination)) { Direction desired = myLoc.directionTo(currentDestination); Direction dir = Movement.getBestMoveableDirection(desired, rc, 2); if (dir != Direction.NONE) { rc.move(dir); } else if (shouldMine(rc, desired)) { rc.clearRubble(desired); } else if (shouldMine(rc, desired.rotateLeft())) { rc.clearRubble(desired.rotateLeft()); } else if (shouldMine(rc, desired.rotateRight())) { rc.clearRubble(desired.rotateRight()); } } } // If can't attack it, move closer! else { Direction desired = myLoc.directionTo(currentDestination); Direction dir = Movement.getBestMoveableDirection(desired, rc, 2); if (dir != Direction.NONE) { rc.move(dir); } else if (shouldMine(rc, desired)) { rc.clearRubble(desired); } else if (shouldMine(rc, desired.rotateLeft())) { rc.clearRubble(desired.rotateLeft()); } else if (shouldMine(rc, desired.rotateRight())) { rc.clearRubble(desired.rotateRight()); } } } // If not there, just move closer. else { Direction desired = myLoc.directionTo(currentDestination); Direction dir = Movement.getBestMoveableDirection(desired, rc, 2); if (dir != Direction.NONE) { rc.move(dir); } else if (shouldMine(rc, desired)) { rc.clearRubble(desired); } else if (shouldMine(rc, desired.rotateLeft())) { rc.clearRubble(desired.rotateLeft()); } else if (shouldMine(rc, desired.rotateRight())) { rc.clearRubble(desired.rotateRight()); } } } } } // Attack whenever you can. if (bestEnemy != null) { if (rc.isWeaponReady()) { if (rc.canAttackLocation(bestEnemy.location)) { broadcastingAttack(rc, bestEnemy); } } } }
public int bugMove(RobotController rc, MapLocation end) { try { MapLocation curLoc = rc.getLocation(); int dist = curLoc.distanceSquaredTo(end); Direction dir = curLoc.directionTo(end); for (int i = 0; i < prevDistanceN; i++) { if (dist == prevDistanceN) { if (rc.isCoreReady()) { if (rc.senseRobotAtLocation(curLoc.add(dir)) == null) { rc.clearRubble(dir); for (int j = prevDistanceN - 1; j > 0; j--) { prevDistance[j] = prevDistance[j - 1]; } } } return dist; } } for (int j = prevDistanceN - 1; j > 0; j--) { prevDistance[j] = prevDistance[j - 1]; } // Direction dir = start.directionTo(end); int c = 0; while (!rc.canMove(dir)) { dir = dir.rotateRight(); if (c == 3) { dir = dir.rotateRight(); c++; } if (c > 6) { break; } c++; } if (c < 7) { if (rc.isCoreReady()) { rc.move(dir); return dist; } } else { if (rc.isCoreReady()) { MapLocation nextLoc = curLoc.add(dir); if (rc.onTheMap(nextLoc)) { if (rc.senseRobotAtLocation(nextLoc) == null) { rc.clearRubble(dir); for (int j = prevDistanceN - 1; j > 0; j--) { prevDistance[j] = prevDistance[j - 1]; } } } } return dist; } } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } return 99999; }