public boolean shieldExists() throws GameActionException { shieldLocation = EncampmentJobSystem.readShieldLocation(); if (shieldLocation != null && rc.canSenseSquare(shieldLocation)) { // looks like something exists at the location... GameObject object = rc.senseObjectAtLocation(shieldLocation); if (object != null && rc.senseRobotInfo((Robot) object).type == RobotType.SHIELDS) { // set the shieldQueueLocation int dx = DataCache.enemyHQLocation.x - DataCache.ourHQLocation.x; int dy = DataCache.enemyHQLocation.y - DataCache.ourHQLocation.y; double vectorMag = Math.sqrt(dx * dx + dy * dy); double dxNorm = dx / vectorMag; double dyNorm = dy / vectorMag; int centerx = (int) (shieldLocation.x - 10 * dxNorm); int centery = (int) (shieldLocation.y - 10 * dyNorm); shieldQueueLocation = new MapLocation(centerx, centery); rallyPoint = shieldQueueLocation; return true; } } return false; }
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 setupBFSMode(MapLocation endLocation) throws GameActionException { navMode = NavMode.BFSMODE; destination = endLocation; int[][] encArray = NavSystem.populate5by5board(); int[] goalCoord = NavSystem.locToIndex(rc.getLocation(), destination, 2); BFSRound = 0; BFSIdle = 0; BFSTurns = NavSystem.runBFS(encArray, goalCoord[1], goalCoord[0]); // System.out.println("BFSTurns :" + BFSTurns.length); if (BFSTurns.length == 0) { // if unreachable, tell to HQ and unassign himself // System.out.println("unreachable, unassigned: " + robot.unassigned + " soldierstate: " + // ((SoldierRobot) robot).soldierState); EncampmentJobSystem.postUnreachableMessage(destination); navMode = NavMode.REGULAR; robot.unassigned = true; } }
/** * code to be used by capturers * * @throws GameActionException */ private void captureCode() throws GameActionException { if (!unassigned) { // if assigned to something EncampmentJobSystem.updateJobTaken(); } if (rc.isActive()) { if (rc.senseEncampmentSquare(currentLocation) && currentLocation.equals(EncampmentJobSystem.goalLoc)) { if (rc.getTeamPower() > rc.senseCaptureCost()) { rc.captureEncampment(EncampmentJobSystem.assignedRobotType); } } else { if (rc.senseNearbyGameObjects(Robot.class, 14, rc.getTeam().opponent()).length > 0) { unassigned = true; soldierState = SoldierState.FIGHTING; } if (NavSystem.navMode == NavMode.BFSMODE) { NavSystem.tryBFSNextTurn(); } else if (NavSystem.navMode == NavMode.GETCLOSER) { NavSystem.tryMoveCloser(); } else if (rc.getLocation().distanceSquaredTo(EncampmentJobSystem.goalLoc) <= 8) { NavSystem.setupGetCloser(EncampmentJobSystem.goalLoc); NavSystem.tryMoveCloser(); } else { NavSystem.moveCloserFavorNoMines(EncampmentJobSystem.goalLoc); // if (NavSystem.navMode == NavMode.NEUTRAL){ // NavSystem.setupSmartNav(EncampmentJobSystem.goalLoc); // NavSystem.followWaypoints(); // } else { // NavSystem.followWaypoints(); // } } } } }
public void sendCompletionMessage() { EncampmentJobSystem.postCompletionMessage(rc.getLocation()); }
@Override public void run() { try { // System.out.println("start: " + Clock.getBytecodeNum()); BroadcastSystem.write(powerChannel, (int) rc.getTeamPower()); // System.out.println("end: " + Clock.getBytecodeNum()); DataCache.updateRoundVariables(); // Check if enemy's nuke is half done if (!enemyNukeHalfDone) { enemyNukeHalfDone = rc.senseEnemyNukeHalfDone(); } if (enemyNukeHalfDone) { // Broadcast this BroadcastSystem.write(ChannelType.ENEMY_NUKE_HALF_DONE, 1); } // if (Clock.getRoundNum() < 20) { // BroadcastSystem.write(ChannelType.CHANNEL1, 0); // BroadcastSystem.read(ChannelType.CHANNEL1); // BroadcastSystem.write(ChannelType.CHANNEL1, 0); // } else { // rc.resign(); // } // if (Clock.getRoundNum() % Constants.CHANNEL_CYCLE == 0 && Clock.getRoundNum() > 0) { EncampmentJobSystem.updateJobsOnCycle(); } else { EncampmentJobSystem.updateJobsAfterChecking(); } if (rc.isActive()) { boolean upgrade = false; if (!rc.hasUpgrade(Upgrade.DEFUSION) && enemyNukeHalfDone && DataCache.numAlliedSoldiers > 5) { upgrade = true; rc.researchUpgrade(Upgrade.DEFUSION); } else if (rc.getTeamPower() < 100) { if (!rc.hasUpgrade(Upgrade.DEFUSION)) { upgrade = true; rc.researchUpgrade(Upgrade.DEFUSION); } else if (!rc.hasUpgrade(Upgrade.PICKAXE)) { upgrade = true; rc.researchUpgrade(Upgrade.PICKAXE); } else if (!rc.hasUpgrade(Upgrade.FUSION)) { upgrade = true; rc.researchUpgrade(Upgrade.FUSION); } } if (!upgrade) { // Spawn a soldier Direction desiredDir = rc.getLocation().directionTo(rc.senseEnemyHQLocation()); Direction dir = getSpawnDirection(rc, desiredDir); if (dir != null) { EncampmentJobSystem.updateJobs(); rc.spawn(dir); } } // if (Clock.getRoundNum() < 5) { // Direction dir = rc.getLocation().directionTo(rc.senseEnemyHQLocation()); // rc.spawn(dir); // } } // // TODO: find out what strategy to switch to? // // this.strategy = HQStrategy.xxx // if (rc.isActive()) { // switch (strategy) { // case CREATE_SOLDIER: // create_soldier(); // break; // case RESEARCH_DEFUSION: // if (!rc.hasUpgrade(Upgrade.DEFUSION)) { // rc.researchUpgrade(Upgrade.DEFUSION); // } // break; // case RESEARCH_FUSION: // if (!rc.hasUpgrade(Upgrade.FUSION)) { // rc.researchUpgrade(Upgrade.FUSION); // } // break; // case RESEARCH_NUKE: // if (!rc.hasUpgrade(Upgrade.NUKE)) { // rc.researchUpgrade(Upgrade.NUKE); // } // break; // case RESEARCH_PICKAXE: // if (!rc.hasUpgrade(Upgrade.PICKAXE)) { // rc.researchUpgrade(Upgrade.PICKAXE); // } // break; // case RESEARCH_VISION: // if (!rc.hasUpgrade(Upgrade.VISION)) { // rc.researchUpgrade(Upgrade.VISION); // } // break; // default: // break; // } // } } catch (Exception e) { System.out.println("caught exception before it killed us:"); System.out.println(rc.getRobot().getID()); e.printStackTrace(); } }
public HQRobot(RobotController rc) throws GameActionException { super(rc); HQLocation = rc.getLocation(); EnemyHQLocation = rc.senseEnemyHQLocation(); EncampmentJobSystem.initializeConstants(HQLocation, EnemyHQLocation); }