// In this function the HQ spawns a soldier ideally toward the enemy base but in any direction // otherwise public static void SpawnSoldiers(RobotController rc) { try { if (rc.isActive() && rc.getType() == RobotType.HQ) { Direction toEnemy = rc.getLocation().directionTo(rc.senseEnemyHQLocation()); if (rc.senseObjectAtLocation(rc.getLocation().add(toEnemy)) == null) { } else { for (int i = 0; i < 7; i++) { toEnemy = toEnemy.rotateLeft(); if (rc.senseObjectAtLocation(rc.getLocation().add(toEnemy)) == null) { i = 47; } else if (i == 6) { toEnemy = Direction.NONE; } } } if (toEnemy != Direction.NONE) { if (rc.isActive()) { if (rc.getType() == RobotType.HQ) { rc.spawn(toEnemy); } } } } } catch (Exception e) { e.printStackTrace(); System.out.println("Utility Exception"); } }
public static void fireCircle(RobotController rc, int radius, MapLocation center) { for (int k = 0; k < directions.length; k++) { while (!rc.isActive()) {} MapLocation toFire = center.add(directions[k], radius); try { if (toFire.x >= 0 && toFire.x < rc.getMapWidth() && toFire.y >= 0 && toFire.y < rc.getMapHeight()) { rc.attackSquare(toFire); rc.yield(); } } catch (Exception e) { } while (!rc.isActive()) {} toFire = center; for (int a = 0; a < radius / 2; a++) { toFire = toFire.add(directions[k]); toFire = toFire.add(directions[(k + 1) % directions.length]); } try { if (toFire.x >= 0 && toFire.x < rc.getMapWidth() && toFire.y >= 0 && toFire.y < rc.getMapHeight()) { rc.attackSquare(toFire); rc.yield(); } } catch (Exception e) { } } }
public static void hqCode() throws GameActionException { if (rc.isActive()) { // Spawn a soldier Direction dir = rc.getLocation().directionTo(rc.senseEnemyHQLocation()); if (rc.canMove(dir)) rc.spawn(dir); } }
public void run() { while (true) { if (rc.getType() == RobotType.SOLDIER) { switch (corner) { case 1: Utilities.MoveMapLocation(rc, new MapLocation(2, 2), true); break; case 2: Utilities.MoveMapLocation(rc, new MapLocation(rc.getMapWidth() - 3, 2), true); break; case 3: Utilities.MoveMapLocation(rc, new MapLocation(2, rc.getMapHeight() - 3), true); break; default: Utilities.MoveMapLocation( rc, new MapLocation(rc.getMapWidth() - 3, rc.getMapHeight() - 3), true); break; } if (rc.isActive()) { try { rc.construct(RobotType.PASTR); } catch (Exception e) { } } } } }
/** * @param whereToGo * @throws GameActionException The original/old version of progressMove. */ @SuppressWarnings("unused") private void progressMoveOld(MapLocation whereToGo) throws GameActionException { rc.setIndicatorString(1, "Swarm target: " + whereToGo.toString()); int dist = rc.getLocation().distanceSquaredTo(whereToGo); if (dist > 0 && rc.isActive()) { Direction toTarget = rc.getLocation().directionTo(whereToGo); int[] directionOffsets = {0, 1, -1, 2, -2}; Direction move; MapLocation ahead; for (int offset : directionOffsets) { move = Direction.values()[(toTarget.ordinal() + offset + 8) % 8]; ahead = rc.getLocation().add(move); Team mine = rc.senseMine(ahead); int move_num = move.ordinal(); if (rc.canMove(move) && (mine == rc.getTeam() || mine == null) && move_num != (previousMove + 4) % 8) { previousMove = move_num; rc.move(move); return; } } previousMove = -1; if (rc.canMove(toTarget) || rc.senseMine(rc.getLocation()) == rc.getTeam()) { moveOrDefuse(toTarget); } } }
private static void goToLocationAvoidMines(MapLocation whereToGo) throws GameActionException { int dist = rc.getLocation().distanceSquaredTo(whereToGo); if (dist > 0 && rc.isActive()) { Direction dir = rc.getLocation().directionTo(whereToGo); goDirectionAvoidMines(dir); } }
public static void tryToSpawn() throws GameActionException { if (rc.isActive() && rc.senseRobotCount() < GameConstants.MAX_ROBOTS) { for (int i = 0; i < 8; i++) { Direction trialDir = allDirections[i]; if (rc.canMove(trialDir)) { rc.spawn(trialDir); break; } } } }
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); } }
private static void goToLocation(MapLocation whereToGo) throws GameActionException { MapLocation meee = rc.getLocation(); int dist = meee.distanceSquaredTo(whereToGo); if (dist > 0 && rc.isActive()) { Direction dir = meee.directionTo(whereToGo); int[] directionOffsets = {0, 1, -1, 2, -2}; Direction lookingAtCurrently = null; for (int d : directionOffsets) { lookingAtCurrently = Direction.values()[(dir.ordinal() + d + 8) % 8]; if (rc.canMove(lookingAtCurrently)) { moveOrDefuse(lookingAtCurrently); break; } } } }
public void evalMove(MapLocation currentLocation, MapLocation whereToGo) throws GameActionException { // New pathing algorithm // SHOULD WE CONSIDER NOT MOVING?? if (rc.isActive()) { try { this.mapIntDistribution[currentLocation.x][currentLocation.y] += 1; } catch (Exception e) { this.mapIntDistribution[currentLocation.x][currentLocation.y] = 1; } int[] dirOffsets = {0, 1, 2, 3, 4, 5, 6, 7}; int bestScore = -1; Direction bestDir = null; for (int offset : dirOffsets) { Direction dir = Direction.values()[offset]; if (rc.canMove(dir)) { int score = this.evalDirection( currentLocation, dir, whereToGo, currentLocation.directionTo(whereToGo), this.movesAway(currentLocation, whereToGo)); if (bestDir == null) { bestScore = score; bestDir = dir; } else if (score < bestScore) { bestScore = score; bestDir = dir; } } } if (bestDir != null) { rc.setIndicatorString( 0, "Best score: " + bestScore + ", Direction to target: " + currentLocation.directionTo(whereToGo)); MapLocation moveSquare = currentLocation.add(bestDir); if (this.mineHazard(moveSquare)) { rc.defuseMine(moveSquare); } else { rc.move(bestDir); } } } }
private static void runSoldier() throws GameActionException { // follow orders from HQ // Direction towardEnemy = rc.getLocation().directionTo(rc.senseEnemyHQLocation()); // BasicPathing.tryToMove(towardEnemy, true, rc, directionalLooks, allDirections);//was // Direction.SOUTH_EAST Robot[] enemyRobots = rc.senseNearbyGameObjects(Robot.class, 10000, rc.getTeam().opponent()); if (enemyRobots.length > 0) { // if there are enemies rc.setIndicatorString(0, "There are enemies"); MapLocation[] robotLocations = new MapLocation[enemyRobots.length]; for (int i = 0; i < enemyRobots.length; i++) { Robot anEnemy = enemyRobots[i]; RobotInfo anEnemyInfo = rc.senseRobotInfo(anEnemy); robotLocations[i] = anEnemyInfo.location; } MapLocation closestEnemyLoc = VectorFunctions.findClosest(robotLocations, rc.getLocation()); if (closestEnemyLoc.distanceSquaredTo(rc.getLocation()) < rc.getType().attackRadiusMaxSquared) { rc.setIndicatorString(1, "trying to shoot"); if (rc.isActive()) { rc.attackSquare(closestEnemyLoc); } } else { rc.setIndicatorString(1, "trying to go closer"); Direction towardClosest = rc.getLocation().directionTo(closestEnemyLoc); simpleMove(towardClosest); } } else { if (path.size() == 0) { MapLocation goal = getRandomLocation(); path = BreadthFirst.pathTo( VectorFunctions.mldivide(rc.getLocation(), bigBoxSize), VectorFunctions.mldivide(rc.senseEnemyHQLocation(), bigBoxSize), 100000); } // follow breadthFirst path Direction bdir = BreadthFirst.getNextDirection(path, bigBoxSize); BasicPathing.tryToMove(bdir, true, rc, directionalLooks, allDirections); } // Direction towardEnemy = rc.getLocation().directionTo(rc.senseEnemyHQLocation()); // simpleMove(towardEnemy); }
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 pullInto(RobotController rc, int radius, MapLocation center) { for (int k = 0; k < directions.length; k++) { while (!rc.isActive()) {} MapLocation toFire = center.add(directions[k], radius); try { while (toFire.distanceSquaredTo(center) > 3) { if (toFire.x >= 0 && toFire.x < rc.getMapWidth() && toFire.y >= 0 && toFire.y < rc.getMapHeight()) { try { rc.attackSquare(toFire); rc.yield(); } catch (Exception e) { } } toFire = toFire.add(directions[k].opposite()); } } catch (Exception e) { } } }
// this method will advance one square towards a target and try to avoid enemies as much as // possible public static void avoidEnemiesMove(RobotController rc, MapLocation target) { try { // first we will find all enemy bots near us GameObject[] nearByBots = rc.senseNearbyGameObjects(Robot.class, 15, rc.getTeam().opponent()); Direction direction = rc.getLocation().directionTo(target); // if we don't see anything then lets head towards target if (nearByBots.length == 0) { // rc.setIndicatorString(2, "No enemies detected"); // rc.setIndicatorString(1, "x: "+target.x + " y: " + target.y); direction = rc.getLocation().directionTo(target); if (rc.canMove(direction)) // && // !rc.senseTerrainTile(rc.getLocation().add(direction).add(direction)).equals(TerrainTile.VOID)) { if (rc.isActive()) { rc.move(direction); } } else { MapLocation target2 = rc.getLocation().add(direction); if (rc.senseTerrainTile(target2).equals(TerrainTile.VOID)) { int j = 0; while (rc.senseTerrainTile(target2).equals(TerrainTile.VOID)) { rc.setIndicatorString(0, "" + j); j++; target2 = target2.add(direction); } Utilities.MoveMapLocation(rc, target2, false); } /* int distanceRight = 0; int distanceLeft = 0; direction = direction.rotateRight(); while (!rc.canMove(direction) && rc.senseTerrainTile(rc.getLocation().add(direction)).equals(TerrainTile.VOID)) { direction = direction.rotateRight(); } if (rc.isActive()) { if (rc.canMove(direction)) { rc.move(direction); } } */ } } // otherwise we need to avoid them else { rc.setIndicatorString(2, "Avoiding enemies"); rc.setIndicatorString(1, "Numb of Enemies: " + nearByBots.length); // now we will calculate the distance form all 5 spots towards are target and the distance // from that spot to all enemies we can see // we will pick the one with the greatest distance int[] distancesToLocations = new int[5]; for (int k = 0; k < distancesToLocations.length; k++) { distancesToLocations[k] = 0; } MapLocation spot; Direction newDir; // first we look 90 to our right newDir = direction.rotateRight().rotateRight(); for (int j = 0; j < 5; j++) { if (rc.canMove(newDir)) { spot = rc.getLocation().add(newDir); for (int i = 0; i < nearByBots.length; i++) { // System.out.println("entering for loop"); distancesToLocations[j] += spot.distanceSquaredTo(rc.senseLocationOf(nearByBots[i])); } } else { distancesToLocations[j] = -123; } // every time through the loop we look one further to the left newDir.rotateLeft(); } int indexOfLargest = 0; int largest = distancesToLocations[0]; for (int j = 1; j < distancesToLocations.length; j++) { if (largest < distancesToLocations[j]) { indexOfLargest = j; largest = distancesToLocations[j]; } } // now we orientate newDir to the right spot newDir = direction.rotateRight().rotateRight(); for (int i = 0; i <= indexOfLargest; i++) { newDir = newDir.rotateLeft(); } while (!rc.isActive()) { rc.yield(); } // now we can finally move if (rc.isActive()) { if (rc.canMove(newDir)) { rc.move(newDir); } } } } catch (Exception e) { e.printStackTrace(); } }
public static void MoveMapLocation(RobotController rc, MapLocation target, boolean sneak) { MapLocation[] pastLocations = new MapLocation[10]; int side = 45; Direction dir; Direction newDir; rand = new Random(); // we initialize pastLocations to hold our current location 5 times for (int i = 0; i < pastLocations.length; i++) { pastLocations[i] = rc.getLocation(); } // this method will run until we get to our target location while (!rc.getLocation().equals(target)) { // we put the try block inside of the while loop so an exception won't terminate the method try { dir = rc.getLocation().directionTo(target); newDir = Direction.NONE; // simple shoot at an enemy if we see one will need to be improved later Robot[] nearbyEnemies = rc.senseNearbyGameObjects(Robot.class, 10, rc.getTeam().opponent()); if (nearbyEnemies.length > 0 && rc.senseRobotInfo((Robot) nearbyEnemies[0]).health < 201) { fire(rc); } // if we can move towards target and we haven't been on the square recently then lets move else if (rc.canMove(dir) && !MapLocationInArray(rc, rc.getLocation().add(dir), pastLocations)) { newDir = dir; // if we found a direction to move then we go to it if (newDir != Direction.NONE) { // now we decide if we are going to sneak or run if (sneak) { // another check to make sure we don't throw any exceptions if (rc.isActive() && rc.canMove(newDir)) { // System.out.println(newDir); rc.sneak(newDir); } } else { // another check to make sure we don't throw any exceptions if (rc.isActive() && rc.canMove(newDir)) { rc.move(newDir); } } } side = 45; } else { // if their is a robot blocking our way then we just move in a random direction if (rc.senseObjectAtLocation(rc.getLocation().add(dir)) != null) { // newDir = directions[rand.nextInt(8)]; MoveDirection(rc, dir, sneak); } else { // rc.setIndicatorString(2, "Looking elswhere"); Direction dir2 = dir; MapLocation right; MapLocation left; dir2 = (dir.rotateRight()); while (!rc.canMove(dir2)) { dir2 = dir2.rotateRight(); } right = rc.getLocation().add(dir2); dir2 = dir.rotateLeft(); while (!rc.canMove(dir2)) { dir2 = dir2.rotateLeft(); } left = rc.getLocation().add(dir2); // left seems better so lets go that way if (left.distanceSquaredTo(target) < right.distanceSquaredTo(target)) { side = 1; } // right seems better so lets try that way else { side = 0; } // we will go hugging one side of obstacle until we get back on our original line while (!dir2.equals(dir) && !rc.getLocation().equals(target)) // && rc.canMove(dir2)) { try { if (rc.isActive()) { // rc.setIndicatorString(1, "Trying to Avoid"); // rc.setIndicatorString(2, ""+side); dir2 = rc.getLocation().directionTo(target); if (rc.canMove(dir2) && !MapLocationInArray(rc, rc.getLocation().add(dir2), pastLocations)) // && // !rc.senseTerrainTile(rc.getLocation().add(dir2).add(dir2)).equals(TerrainTile.VOID)) { // rc.setIndicatorString(0, "Going straight"); } else { for (int i = 0; i < 4; i++) { if (side == 1) { dir2 = dir2.rotateLeft(); } else { dir2 = dir2.rotateRight(); } if (rc.senseTerrainTile(rc.getLocation().add(dir2)) .equals(TerrainTile.OFF_MAP)) { dir2 = Direction.NONE; i = 48; } else if ((rc.canMove(dir2) || (rc.senseObjectAtLocation(rc.getLocation().add(dir2)) != null))) // && !MapLocationInArray(rc, rc.getLocation().add(dir2), // pastLocations))// && // !rc.senseTerrainTile(rc.getLocation().add(dir2).add(dir2)).equals(TerrainTile.VOID)) { i = 48; } else if (i == 3) { dir2 = Direction.NONE; // rc.setIndicatorString(1, "We failed to find a spot"); } } } // if we can move if (dir2 != Direction.NONE) { if (rc.isActive()) { if (rc.canMove(dir2)) { if (sneak) { rc.sneak(dir2); } else { rc.move(dir2); } } else { MoveDirection(rc, dir2, sneak); } } } else { if (side == 1) { side = 0; } else { side = 1; } } } // rc.setIndicatorString(0, "Dir: "+ dir +" Dir2: " + dir2); } catch (Exception e) { // tell the console we through an exception in utility object for debug purposes // System.out.println("Utility Exception"); // System.out.println(e.toString()); e.printStackTrace(); rc.yield(); } if (!rc.getLocation().equals(pastLocations[(pastLocations.length - 1)])) { for (int j = 0; j < (pastLocations.length - 1); j++) { pastLocations[j] = pastLocations[j + 1]; // System.out.println(pastLocations[j]); } // stick current local into array pastLocations[(pastLocations.length - 1)] = rc.getLocation(); } rc.yield(); } // rc.setIndicatorString(1, "Not trying to Avoid"); } } // now we shift everything up one in pastLocations if (rc.getLocation() != pastLocations[(pastLocations.length - 1)]) { for (int j = 0; j < (pastLocations.length - 1); j++) { pastLocations[j] = pastLocations[j + 1]; // System.out.println(pastLocations[j]); } // stick current local into array pastLocations[(pastLocations.length - 1)] = rc.getLocation(); } rc.yield(); } catch (Exception e) { // tell the console we through an exception in utility object for debug purposes System.out.println("Utility Exception"); e.printStackTrace(); // System.out.println(e.toString()); rc.yield(); } } }
public static void MoveDirection(RobotController rc, Direction dir, boolean sneak) { Direction newDir = Direction.NONE; int counter = 1; try { // here we do some checks to make sure that we don't throw any exceptions if (rc.isActive()) { if (dir != Direction.NONE && dir != Direction.OMNI) { if (!rc.canMove(dir)) { // now we loop through the other 7 directions to find one that works for (int i = 0; i < 7; i++) { newDir = dir; // first look right if (i % 2 == 0) { // now we rotate 45 right a certain numb of times for (int j = 0; j < counter; j++) { newDir = newDir.rotateRight(); } } // the look left else { // now we rotate 45 left a certain numb of times for (int j = 0; j < counter; j++) { newDir = newDir.rotateLeft(); } // now after we have looked both ways we update counter counter++; } // at end of for loop we check to see if we can move or if we need to keep looking if (rc.canMove(newDir)) { i = 48; } // if we have gone through all our options and can't move then we will wait else if (i == 5 && !rc.canMove(newDir)) { newDir = Direction.NONE; } } } // we are going to move in the direction of newDir and as we can move in direction dir we // assign newDir to it else { newDir = dir; } if (newDir != Direction.NONE) { // now we decide if we are going to sneak or run if (sneak) { // another check to make sure we don't throw any exceptions if (rc.isActive() && rc.canMove(newDir)) { rc.sneak(newDir); } } else { // another check to make sure we don't throw any exceptions if (rc.isActive() && rc.canMove(newDir)) { rc.move(newDir); } } } } } } catch (Exception e) { // tell the console we through an exception in utility object for debug purposes System.out.println("Utility Exception"); e.printStackTrace(); // System.out.println(newDir); } }
public void progressMove(MapLocation whereToGo) throws GameActionException { MapLocation currentLocation = rc.getLocation(); int dist = currentLocation.distanceSquaredTo(whereToGo); if (dist > 0 && rc.isActive()) { Direction toTarget = currentLocation.directionTo(whereToGo); int[] directionOffsets = {-2, 2, -1, 1, 0}; Direction potentialDirectionMovement; // direction of where we are going to move MapLocation newLocation; int offset; for (int i = 5; --i >= 0; ) { offset = directionOffsets[i]; potentialDirectionMovement = Direction.values()[(toTarget.ordinal() + offset + 8) % 8]; newLocation = rc.getLocation().add(potentialDirectionMovement); Team mineAtPotentialNewLocation = rc.senseMine(newLocation); if (rc.canMove(potentialDirectionMovement) && this.shouldMakeMoveRand(newLocation, currentLocation) && (mineAtPotentialNewLocation == myTeam || mineAtPotentialNewLocation == null)) { rc.move(potentialDirectionMovement); // this.previousFour[lastIndex] = currentLocation; // lastIndex = (lastIndex + 1)%4; try { try { this.mapIntDistribution[newLocation.x][newLocation.y]++; } catch (Exception e) { this.mapIntDistribution[newLocation.x][newLocation.y] = 1; } } catch (Exception e) { } // rc.setIndicatorString(0,Arrays.toString(this.previousFour)); // rc.setIndicatorString(1,"locationBeforeMove: "+currentLocation); // rc.setIndicatorString(2,"to Target Direction: "+toTarget.toString()); return; } } for (int i = 5; --i >= 0; ) { offset = directionOffsets[i]; potentialDirectionMovement = Direction.values()[(toTarget.ordinal() + offset + 8) % 8]; if (rc.canMove(potentialDirectionMovement)) { newLocation = currentLocation.add(toTarget); this.defuseFirstorThenMove(potentialDirectionMovement); // this.previousFour[lastIndex] = currentLocation; // lastIndex = (lastIndex + 1)%4; try { try { this.mapIntDistribution[newLocation.x][newLocation.y]++; } catch (Exception e) { this.mapIntDistribution[newLocation.x][newLocation.y] = 1; } } catch (Exception e) { } // rc.setIndicatorString(0,Arrays.toString(this.previousFour)); // rc.setIndicatorString(1,"locationBeforeMove: "+currentLocation); // rc.setIndicatorString(2,"to Target Direction: "+toTarget.toString()); return; } } } }
public static void hqCode(RobotController myRC) throws GameActionException { rc = myRC; Direction defaultSpawnDir = rc.getLocation().directionTo(rc.senseEnemyHQLocation()); evaluateMap(); while (true) { rc.broadcast(Constants.attackChannel, 0); enemyRobots = rc.senseNearbyGameObjects( Robot.class, new MapLocation(0, 0), 1000000, rc.getTeam().opponent()); if (expandOrRally()) { rc.broadcast(Constants.commandChannel, Constants.commandExpand); broadcastUpdatedBuildOrder(); MapLocation rally = findRallyPoint(); rc.broadcast(Constants.rallyXChannel, rally.x); rc.broadcast(Constants.rallyYChannel, rally.y); } else { MapLocation rally = findRallyPoint(); rc.broadcast(Constants.rallyXChannel, rally.x); rc.broadcast(Constants.rallyYChannel, rally.y); rc.broadcast(Constants.commandChannel, Constants.commandRally); } if (rc.isActive()) { int readIn = rc.readBroadcast(Constants.campChannel); if (!doWeNeedGenerator()) { rc.broadcast(Constants.campChannel, Constants.campSupplier); // Spawn a soldier Team defaultScan = rc.senseMine(rc.getLocation().add(defaultSpawnDir)); if (rc.canMove(defaultSpawnDir) && (defaultScan == null || defaultScan == rc.getTeam())) { rc.spawn(defaultSpawnDir); } else { for (Direction d : Direction.values()) // TODO: optimize secondary direction finding { if (d != Direction.OMNI && d != Direction.NONE) { Team scan = rc.senseMine(rc.getLocation().add(d)); if (rc.canMove(d) && (scan == null || scan == rc.getTeam())) { rc.spawn(d); break; } } } if (rc.isActive()) { // if there are no valid spawn directions rc.researchUpgrade(Upgrade.NUKE); } } } else // we do need a generator { if (readIn == Constants.campSupplier || (readIn != Constants.campGenInProduction && readIn != Constants.campGen)) { rc.broadcast(Constants.campChannel, Constants.campGen); } if (!rc.hasUpgrade(Upgrade.FUSION)) { rc.researchUpgrade(Upgrade.FUSION); } else if (!rc.hasUpgrade(Upgrade.DEFUSION)) { rc.researchUpgrade(Upgrade.DEFUSION); } else { rc.researchUpgrade(Upgrade.NUKE); } } } if (Clock.getRoundNum() > 200) { if (rc.senseEnemyNukeHalfDone()) { rc.broadcast(Constants.commandChannel, Constants.commandEnemyNukeHalfDone); while (!rc.hasUpgrade(Upgrade.DEFUSION)) { if (rc.isActive()) { rc.researchUpgrade(Upgrade.DEFUSION); } rc.yield(); } enemyRobots = rc.senseNearbyGameObjects( Robot.class, new MapLocation(0, 0), 1000000, rc.getTeam().opponent()); } } shallWeAllIn(); rc.yield(); } }