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 SoldierRobot(RobotController rc) throws GameActionException { super(rc); NavSystem.init(this); if (Clock.getRoundNum() < 10) { soldierState = soldierState.SCOUTING; } else { ChannelType channel = EncampmentJobSystem.findJob(); if (channel != null) { unassigned = false; EncampmentJobSystem.updateJobTaken(); } // TODO: this will f**k up if we ever build artillery for non-nuke bots // LEARN THE STRATEGY Message message = BroadcastSystem.read(ChannelType.STRATEGY); if (message.isValid && message.body < Strategy.values().length && message.body >= 0) { strategy = Strategy.values()[message.body]; } else { // we couldn't read the strategy channel MapLocation[] alliedEncampmentSquares = rc.senseAlliedEncampmentSquares(); if (alliedEncampmentSquares.length == 0) { strategy = Strategy.ECON; } else { Robot robot = (Robot) rc.senseObjectAtLocation(alliedEncampmentSquares[0]); RobotInfo robotInfo = rc.senseRobotInfo(robot); if (robotInfo.type == RobotType.ARTILLERY) { strategy = Strategy.NUKE; } else { strategy = Strategy.ECON; } } } // rc.setIndicatorString(2, strategy.toString()); rallyPoint = findRallyPoint(); rSquared = DataCache.rushDistSquared / 4; initializeMining(); } }
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(); } }
public static MapLocation[] getAlliedEncampments() { if (alliedEncampments == null) { alliedEncampments = RC.senseAlliedEncampmentSquares(); } return alliedEncampments; }