public static boolean expandOrRally() throws GameActionException // true for expand { // rush distance // double rushDistance = rc.senseHQLocation().distanceSquaredTo(rc.senseEnemyHQLocation()); // number of encampments if (!expandPhase) { singleExpand(); return false; } int numAlliedCamps = rc.senseAlliedEncampmentSquares().length; if (numAlliedCamps > 13) { rc.broadcast(Constants.commandChannel, Constants.commandRally); expandPhase = false; return false; } if (numAlliedCamps >= optimalBuildings) { rc.broadcast(Constants.commandChannel, Constants.commandRally); expandPhase = false; return false; } rc.broadcast(Constants.commandChannel, Constants.commandExpand); return true; }
public static void singleExpand() throws GameActionException { int numCamps = rc.senseAlliedEncampmentSquares().length; if (numCamps >= optimalBuildings + farAwayButSafeBuildings) return; if (numCamps < optimalBuildings) {} if (false) { // figure out condition MapLocation expansion = null; expansion = findClosestEmptyCamp(); rc.broadcast(Constants.commandChannel, Constants.commandBuildIndividual); rc.broadcast(Constants.singleExpandXChannel, expansion.x); rc.broadcast(Constants.singleExpandYChannel, expansion.y); } }
public static void run(RobotController myRC) { rc = myRC; rallyPoint = findRallyPoint(); while (true) { try { if (rc.getType() == RobotType.SOLDIER) { if (rc.senseEncampmentSquare(rc.getLocation())) { if (rc.getTeamPower() > 10 * (rc.senseAlliedEncampmentSquares().length + 10)) { rc.captureEncampment(RobotType.SUPPLIER); } else { rc.captureEncampment(RobotType.GENERATOR); } } else { Robot[] enemyRobots = rc.senseNearbyGameObjects(Robot.class, 100000, rc.getTeam().opponent()); if (enemyRobots.length == 0 || (enemyRobots.length == 1 && rc.senseRobotInfo(enemyRobots[0]).type == RobotType.HQ)) { // no enemies nearby Robot[] alliedRobots = rc.senseNearbyGameObjects(Robot.class, 1000000, rc.getTeam()); if (alliedRobots.length < 5 * (rc.senseAlliedEncampmentSquares().length) + 1) { if (Math.random() < 0.1 && alliedRobots.length < 20) { if (rc.senseMine(rc.getLocation()) == null) { rc.layMine(); } } goToLocation(rallyPoint); } else { goToLocation(rc.senseEnemyHQLocation()); } } else { // someone spotted int closestDist = 100000; MapLocation closestEnemy = null; for (int i = 0; i < enemyRobots.length; i++) { Robot arobot = enemyRobots[i]; RobotInfo arobotInfo = rc.senseRobotInfo(arobot); int dist = arobotInfo.location.distanceSquaredTo(rc.getLocation()); if (dist < closestDist) { closestDist = dist; closestEnemy = arobotInfo.location; } } Robot[] nearbyAllies = rc.senseNearbyGameObjects(Robot.class, 64, rc.getTeam()); if (nearbyAllies.length > 2.5 * enemyRobots.length) { if (closestDist > 4) { goToLocation(closestEnemy); } } goToLocationAvoidMines(closestEnemy); } } } else { hqCode(); } } catch (Exception e) { // System.out.println("caught exception before it killed us:"); // e.printStackTrace(); } rc.yield(); } }