private static void moveSoldier(RobotController rc) throws GameActionException { // if we have a real current destination rc.setIndicatorString(1, "moving somewhere " + currentDestination + rc.getRoundNum()); if (currentDestination != null) { // if bugging is never initialized or we are switching destinations, reinitialize bugging if (!currentDestination.equals(storedDestination) || bugging == null) { bugging = new Bugging(rc, currentDestination); storedDestination = currentDestination; } // if we are trying to move towards a turret, stay out of range if (rc.isCoreReady()) { if (currentDestination.equals(nearestTurretLocation)) { bugging.turretAvoidMove(turretLocations); } else // if core is ready, then try to move towards destination if (nearestTurretLocation != null) { bugging.turretAvoidMove(turretLocations); } else { bugging.move(); } } } else if (nearestArchonLocation != null) { // we don't actually have a destination, so we want to try to move towards the // closest archon rc.setIndicatorString( 0, "moving to nearest archon " + nearestArchonLocation + rc.getRoundNum()); if (!nearestArchonLocation.equals(storedDestination)) { bugging = new Bugging(rc, nearestArchonLocation); storedDestination = nearestArchonLocation; } // if core is ready, try to move if (rc.isCoreReady() && bugging != null) { if (nearestTurretLocation != null) { bugging.turretAvoidMove(turretLocations); } else if (nearestArchonLocation.equals(bugging.destination) && myLoc.distanceSquaredTo(nearestArchonLocation) > 13) { // if soldier is far, move towards archon bugging.move(); } else if (nearestArchonLocation.equals(bugging.destination) && myLoc.distanceSquaredTo(nearestArchonLocation) < 13) { // if soldier is too close, move towards archon // try to move away from nearest archon if (rc.canMove(nearestArchonLocation.directionTo(myLoc))) { rc.move(nearestArchonLocation.directionTo(myLoc)); } } } } else { // if we literally have nowhere to go rc.setIndicatorString(1, "bugging around friendly " + rc.getRoundNum()); bugAroundFriendly(rc); } }
public static void bugAroundFriendly(RobotController rc) throws GameActionException { RobotInfo[] nearbyFriendlyRobots = rc.senseNearbyRobots(sightRadius, myTeam); if (nearbyFriendlyRobots.length > 0) { RobotInfo nearestFriend = null; for (RobotInfo r : nearbyFriendlyRobots) { if (r.type == RobotType.ARCHON) { nearestFriend = r; } } if (nearestFriend != null && !nearestFriend.location.equals(storedDestination) || bugging == null) { bugging = new Bugging(rc, nearestFriend.location); storedDestination = nearestFriend.location; } if (rc.isCoreReady()) { // don't want to get too close to archon bugging.move(); } } }