public static boolean doWeNeedGenerator() throws GameActionException { if (rc.readBroadcast(Constants.campChannel) == Constants.campGenInProduction) return false; if (Clock.getRoundNum() - allInRound < 80) return false; if (rc.readBroadcast(Constants.commandChannel) == Constants.commandRally && rc.getTeamPower() > powerThreshold) return false; if (rc.getTeamPower() < minPowerThreshold && Clock.getRoundNum() > minRoundThreshold) { return true; } gencount = 0; soldiercount = 0; othercount = 0; Robot[] robos = rc.senseNearbyGameObjects(Robot.class, new MapLocation(0, 0), 1000000, rc.getTeam()); for (Robot r : robos) { RobotType rt = rc.senseRobotInfo(r).type; if (rt == RobotType.GENERATOR) ++gencount; else if (rt == RobotType.SOLDIER) ++soldiercount; else ++othercount; } double decay = .8; if (rc.hasUpgrade(Upgrade.FUSION)) { decay = .99; } if ((40 + (10 * gencount) - (1.6 * soldiercount) - (1 * othercount)) * decay < 1) { return true; } return false; }
private static void expand() throws GameActionException { // rallyPoint = findClosestLocation(rc.senseAllEncampmentSquares()); if (!localscan) { rallyPoint = findClosestEmptyCamp(); } if (rc.getLocation().distanceSquaredTo(rallyPoint) < 1) // if we are at the location of the rally point { if (!localscan) { rallyPoint = findFurthestLocalCamp(); localscan = true; } } if (rc.getLocation().distanceSquaredTo(rallyPoint) < 1) // if we are at the location of the rally point { if (rc.isActive()) // if we are allowed to capture { if (rc.senseCaptureCost() + 1.8 * getNumberOfAlliedRobosAfterMe() < rc.getTeamPower()) // if we have enough power to capture { int readIn = rc.readBroadcast(Constants.campChannel); if (readIn == Constants.campGen) { rc.broadcast(Constants.campChannel, Constants.campGenInProduction); rc.captureEncampment(RobotType.GENERATOR); } else if (readIn == Constants.campGenInProduction) { rc.captureEncampment(RobotType.SUPPLIER); } else if (readIn == Constants.campSupplier) { rc.captureEncampment(RobotType.SUPPLIER); } else // TODO: transmissions may be being scrambled, for now just make supplier { rc.captureEncampment(RobotType.SUPPLIER); } } } } else if (rc.senseNearbyGameObjects(Robot.class, rallyPoint, 0, rc.getTeam()).length > 0) // if there is an allied robot on our rally point { rallyPoint = findClosestEmptyCamp(); if (rallyPoint == null) { rallyPoint = findRallyPoint(); } goToLocation(rallyPoint); } else { goToLocation(rallyPoint); } }
public static void expandIndividual() throws GameActionException { MapLocation expandLocation = new MapLocation( rc.readBroadcast(Constants.singleExpandXChannel), rc.readBroadcast(Constants.singleExpandYChannel)); rc.broadcast(Constants.commandChannel, Constants.commandRally); while (true) { if (rc.getLocation().distanceSquaredTo(expandLocation) < 1) // if we are at the location of the rally point { if (rc.isActive()) // if we are allowed to capture { if (rc.senseCaptureCost() + 1.8 * getNumberOfAlliedRobosAfterMe() < rc.getTeamPower()) // if we have enough power to capture { int readIn = rc.readBroadcast(Constants.campChannel); if (readIn == Constants.campGen) { rc.broadcast(Constants.campChannel, Constants.campGenInProduction); rc.captureEncampment(RobotType.GENERATOR); } else if (readIn == Constants.campGenInProduction) { rc.captureEncampment(RobotType.SUPPLIER); } else if (readIn == Constants.campSupplier) { rc.captureEncampment(RobotType.SUPPLIER); } else // TODO: transmissions may be being scrambled, for now just make supplier { rc.captureEncampment(RobotType.SUPPLIER); } break; } } } else if (rc.senseNearbyGameObjects(Robot.class, expandLocation, 0, rc.getTeam()).length > 0) // if there is an allied robot on our rally point { expandLocation = findClosestEmptyCamp(); if (expandLocation == null) { expandLocation = findRallyPoint(); } goToLocation(expandLocation); } else { goToLocation(expandLocation); } rc.yield(); } }
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(); } }