/** * @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); } } }
// try to move in the direction of the target // if we can't, see what other spaces are open // if our path is blocked entirely by mines, defuse the one that lies on the direct path to the // target private void goToLocation(MapLocation place) throws GameActionException { int dist = rc.getLocation().distanceSquaredTo(place); if (dist > 0) { int[] directionOffsets = { 0, 1, -1, 2, -2 }; // lower magnitude offsets don't change our direction much Direction dir = rc.getLocation().directionTo(place); // get direction straight to target Direction firstMine = null; boolean hasMoved = false; for (int d : directionOffsets) { // apply the offset to get direction (start with direction straight to target, and change if // necessary) Direction lookingAtCurrently = Direction.values()[(dir.ordinal() + d + 8) % 8]; if (rc.canMove(lookingAtCurrently)) { // if the path is open, take it if (rc.senseMine(rc.getLocation().add(lookingAtCurrently)) == null) { rc.move(lookingAtCurrently); hasMoved = true; break; } else if (firstMine == null) { // detect the first mine firstMine = Direction.values()[lookingAtCurrently.ordinal()]; } } } if (!hasMoved) { // if we haven't moved at all, defuse the mine on the most direct path to the // target if (firstMine != null) { rc.defuseMine(rc.getLocation().add(firstMine)); } } } }
public int evalDirection( MapLocation currentLocation, Direction dir, MapLocation goal, Direction dirToGoal, int currentMovesToGoal) { boolean hasDefusion = rc.hasUpgrade(Upgrade.DEFUSION); MapLocation square = currentLocation.add(dir); int directionPenalty; int dirDiff = Math.abs(dir.ordinal() - dirToGoal.ordinal()); if (dirDiff <= 2) { directionPenalty = this.movesAway(square, goal) - currentMovesToGoal; } else { directionPenalty = hasDefusion ? 5 : 12; } int minePenalty; if (hasDefusion) { minePenalty = this.mineHazard(square) ? 5 : 0; } else { minePenalty = this.mineHazard(square) ? 12 : 0; } int visitPenalty = 2 * this.mapIntDistribution[square.x][square.y] * (hasDefusion ? 5 : 12); return directionPenalty + minePenalty + visitPenalty; }
private void cautiouslyApproachVisibleEnemySoldier(MapLocation enemySoldier, int maxEnemyExposure) throws GameActionException { int[] numEnemiesAttackingDirs = countNumEnemiesAttackingMoveDirs(); Direction toEnemy = here.directionTo(enemySoldier); Direction[] tryDirs = new Direction[] {toEnemy, toEnemy.rotateLeft(), toEnemy.rotateRight()}; for (int i = 0; i < tryDirs.length; i++) { Direction tryDir = tryDirs[i]; if (!rc.canMove(tryDir)) continue; if (numEnemiesAttackingDirs[tryDir.ordinal()] > maxEnemyExposure) continue; if (Util.inHQAttackRange(here.add(tryDir), theirHQ)) continue; Debug.indicate( "micro", 1, String.format( "cautiously approaching enemy soldier; direction %d; attackers = %d %d %d %d %d %d %d %d", tryDir.ordinal(), numEnemiesAttackingDirs[0], numEnemiesAttackingDirs[1], numEnemiesAttackingDirs[2], numEnemiesAttackingDirs[3], numEnemiesAttackingDirs[4], numEnemiesAttackingDirs[5], numEnemiesAttackingDirs[6], numEnemiesAttackingDirs[7])); rc.move(tryDir); return; } Debug.indicate("micro", 1, "can't safely approach enemy soldier"); }
private void goToLocation(MapLocation place) throws GameActionException { int dist = rc.getLocation().distanceSquaredTo(place); if (dist > 0) { int[] directionOffsets = {0, 1, -1, 2, -2}; Direction dir = rc.getLocation().directionTo(place); Direction firstMine = null; boolean hasMoved = false; for (int d : directionOffsets) { Team teamOfMine = null; Direction lookingAtCurrently = Direction.values()[(dir.ordinal() + d + 8) % 8]; if (rc.canMove(lookingAtCurrently)) { if ((teamOfMine = (rc.senseMine(rc.getLocation().add(lookingAtCurrently)))) == null) { if (this.movedFrom != lookingAtCurrently.opposite()) { this.movedFrom = lookingAtCurrently; rc.move(lookingAtCurrently); hasMoved = true; break; } else { continue; } } else if (firstMine == null && teamOfMine != rc.getTeam()) { firstMine = Direction.values()[lookingAtCurrently.ordinal()]; } } } if (!hasMoved) { if (firstMine != null) { rc.defuseMine(rc.getLocation().add(firstMine)); } } } }
public void progressMove(MapLocation whereToGo, Boolean inBattle) 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 { this.mapIntDistribution[newLocation.x][newLocation.y]++; } catch (Exception e) { this.mapIntDistribution[newLocation.x][newLocation.y] = 1; } 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) && !inBattle) { newLocation = currentLocation.add(toTarget); this.defuseFirstorThenMove(potentialDirectionMovement); // this.previousFour[lastIndex] = currentLocation; // lastIndex = (lastIndex + 1)%4; try { this.mapIntDistribution[newLocation.x][newLocation.y]++; } catch (Exception e) { this.mapIntDistribution[newLocation.x][newLocation.y] = 1; } rc.setIndicatorString(0, Arrays.toString(this.previousFour)); rc.setIndicatorString(1, "locationBeforeMove: " + currentLocation); rc.setIndicatorString(2, "to Target Direction: " + toTarget.toString()); return; } } } }
public static void HqCommand() throws GameActionException { if (rc.getType() == RobotType.HQ) { // if (rc.isActive()) { // Spawn a soldier int[] directionOffSets = {0, 1, -1, 2, -2}; // Team mineSpawn = rc.senseMine(rc.getLocation().add(spawnDir)); Direction dir = rc.getLocation().directionTo(rc.senseEnemyHQLocation()); // this does not work! Direction spawnDir = dir; // spawn robots in the direction of the enemy if (rc.senseMine(rc.getLocation().add(dir)) != null) { lookForDir: for (int d : directionOffSets) { spawnDir = Direction.values()[(dir.ordinal() + d + 8) % 8]; if (rc.canMove(spawnDir) && rc.senseMine(rc.getLocation().add(spawnDir)) != null) { rc.spawn(Direction.SOUTH); rc.spawn(spawnDir); break lookForDir; } } } if (rc.canMove(dir)) { rc.spawn(dir); } // } } }
private static void goToLocation(MapLocation whereToGo) throws GameActionException { // if (rc.isActive()) { // if(encampmentLocationArray == null){ // find encampments // encampmentLocationArray = rc.senseAllEncampmentSquares(); // } // if (counter < 10 && rc.senseMine(rc.getLocation()) == null) { // lay mines behind robots // if(rc.senseMine(rc.getLocation())==null) // rc.layMine(); // Send all robots to the passed in argument. int dist = rc.getLocation().distanceSquaredTo(whereToGo); if (dist > 0) { // dist > 0 && rc.isActive() Direction dir = rc.getLocation().directionTo(whereToGo); Direction curDir = dir; int[] directionOffSets = {0, 1, -1, 2, -2}; lookForDir: for (int d : directionOffSets) { curDir = Direction.values()[(dir.ordinal() + d + 8) % 8]; if (rc.canMove(curDir)) { break lookForDir; } } Team mine = rc.senseMine(rc.getLocation().add(curDir)); if (mine != null && mine != rc.getTeam()) { rc.defuseMine(rc.getLocation().add(curDir)); } else { rc.move(curDir); rc.setIndicatorString(0, "Last direction moved: " + dir.toString()); } } }
public static boolean goToLocation(MapLocation whereToGo, boolean defuseMines) throws GameActionException { int dist = mRC.getLocation().distanceSquaredTo(whereToGo); // TODO if its an hq and stuff is in the way you gotta kill it if (mRC.isActive() && dist > 0) { Direction dir = mRC.getLocation().directionTo(whereToGo); for (int d : Constants.testDirOrderFrontSide) { Direction lookingAtCurrently = Direction.values()[(dir.ordinal() + d + NUM_DIR) % NUM_DIR]; MapLocation newLoc = mRC.getLocation().add(lookingAtCurrently); Team mineOwner = mRC.senseMine(newLoc); boolean shouldDefuseEnemyMine = Math.random() < CHANCE_OF_DEFUSING_ENEMY_MINE; if (mRC.canMove(lookingAtCurrently) && (defuseMines || !isMineDir(mRC.getLocation(), lookingAtCurrently, true))) { if (mineOwner != null && mineOwner != mRC.getTeam()) { mRC.defuseMine(newLoc); } else { mRC.move(lookingAtCurrently); } return true; } else if (mRC.canMove(lookingAtCurrently) && isMineDir(mRC.getLocation(), lookingAtCurrently, true) && mineOwner == mRC.getTeam().opponent() && shouldDefuseEnemyMine) { mRC.defuseMine(newLoc); return true; } } } return false; }
public static void moveCloserFavorNoMines() throws GameActionException { Direction dir = rc.getLocation().directionTo(destination); double distance = rc.getLocation().distanceSquaredTo(destination); double currDist; if (rc.canMove(dir) && !hasBadMine(rc.getLocation().add(dir))) { rc.move(dir); } else { Direction bestDir = dir; Direction currentDir = dir; for (int directionOffset : directionOffsets) { if (directionOffset != 0) { currentDir = Direction.values()[(dir.ordinal() + directionOffset + 8) % 8]; if (rc.canMove(currentDir) && !hasBadMine(rc.getLocation().add(currentDir))) { currDist = rc.getLocation().add(currentDir).distanceSquaredTo(destination); if (currDist < distance) { distance = currDist; bestDir = currentDir; } } } } NavSystem.moveOrDefuse(bestDir); } }
public static void go_towards_destination() throws GameActionException { if (!rc.isCoreReady()) return; if (destination == null || destination.equals(current_location)) { dig(destination); return; } combat_mode = false; if (life_insurance_policy == Safety.KITE) combat_mode = true; // TODO alter try directions so we use non-diagonal if possible. Direction direction_to_head = current_location.directionTo(destination); for (int offset : (combat_mode ? combat_directions : try_directions)) { Direction try_to_walk = Direction.values()[(direction_to_head.ordinal() + offset + 8) % 8]; if (rc.canMove(try_to_walk)) { if (life_insurance_policy.says_this_move_will_shorten_your_life( current_location.add(try_to_walk))) continue; previous_location = current_location; if (rc.canMove(try_to_walk)) { rc.move(try_to_walk); } else { System.out.println("Running over byte limit"); } return; } } dig(destination); }
private static void simpleMove(Direction chosenDirection) throws GameActionException { for (int directionalOffset : directionalLooks) { int forwardInt = chosenDirection.ordinal(); Direction trialDir = allDirections[(forwardInt + directionalOffset + 8) % 8]; if (rc.canMove(trialDir)) { rc.move(trialDir); break; } } }
public static void spawnRobot() throws GameActionException { Direction tempDir = null; for (int i = 0; i < NUM_DIR; ++i) { tempDir = Direction.values()[(enHQDir.ordinal() + i + NUM_DIR) % NUM_DIR]; if (mRC.canMove(tempDir)) { mRC.spawn(tempDir); break; } } }
protected void forwardish(Direction ahead) throws GameActionException { // System.out.println(ahead); for (int i : RobotConstants.posDirs) { Direction candidateDir = Direction.values()[(ahead.ordinal() + i + 8) % 8]; if (rc.canMove(candidateDir)) { rc.move(candidateDir); break; } } }
public static Direction getBestMoveableDirection(Direction dir, RobotController rc, int fan) { int ordinal = dir.ordinal(); for (int i = 0; i < 2 * fan + 1; i++) { int disp = ((i % 2) * 2 - 1) * (i + 1) / 2; Direction testDir = Direction.values()[mod8(ordinal + disp)]; if (rc.canMove(testDir)) { return testDir; } } return Direction.NONE; }
private Direction getSpawnDir() { Direction directDir = this.getDirectSpawnDir(); int[] spawningOffsets = {0, 1, -1, 2, -2, 3, -3, 4}; for (int offset : spawningOffsets) { Direction potentialSpawnDir = Direction.values()[(directDir.ordinal() + offset + 8) % 8]; MapLocation potentialSpawnLocation = this.currentLocation.add(potentialSpawnDir); if (rc.canMove(potentialSpawnDir) && !this.mineHazard(potentialSpawnLocation)) { return potentialSpawnDir; } } return null; }
private Direction chooseRetreatDirection() throws GameActionException { int[] numEnemiesAttackingDir = countNumEnemiesAttackingMoveDirs(); int repelX = 0; int repelY = 0; for (int i = visibleEnemies.length; i-- > 0; ) { Direction repelDir = visibleEnemies[i].location.directionTo(here); repelX += repelDir.dx; repelY += repelDir.dy; } int absRepelX = Math.abs(repelX); int absRepelY = Math.abs(repelY); Direction retreatDir; if (absRepelX >= 1.5 * absRepelY) { retreatDir = repelX > 0 ? Direction.EAST : Direction.WEST; } else if (absRepelY >= 1.5 * absRepelX) { retreatDir = repelY > 0 ? Direction.SOUTH : Direction.NORTH; } else if (repelX > 0) { retreatDir = repelY > 0 ? Direction.SOUTH_EAST : Direction.NORTH_EAST; } else { retreatDir = repelY > 0 ? Direction.SOUTH_WEST : Direction.NORTH_WEST; } // Test to see if retreatDir, or either of the adjacent directions, actually work // To work, three conditions have to be satisfied: // (a) we have to be able to move in that direction // (b) moving in that direction has to take us out of range of enemy attacks // (c) moving in that direction can't take us within range of the enemy HQ int[] tryDirs = new int[] {0, 1, -1, 2, -2, 3, -3, 4}; for (int i = 0; i < tryDirs.length; i++) { Direction tryDir = Direction.values()[(retreatDir.ordinal() + tryDirs[i] + 8) % 8]; if (!rc.canMove(tryDir)) continue; MapLocation tryLoc = here.add(tryDir); if (numEnemiesAttackingDir[tryDir.ordinal()] > 0) continue; if (Util.inHQAttackRange(tryLoc, theirHQ)) continue; return tryDir; } return null; }
public static void goDirectionAndDontDefuseOrAvoidMines(Direction dir) throws GameActionException { if (rc.isActive()) { Direction lookingAtCurrently = dir; lookAround: for (int d : directionOffsets) { lookingAtCurrently = Direction.values()[(dir.ordinal() + d + 8) % 8]; if (rc.isActive() && rc.canMove(lookingAtCurrently)) { rc.move(lookingAtCurrently); break lookAround; } } } }
private static void goDirectionAvoidMines(Direction dir) throws GameActionException { int[] directionOffsets = {0, 1, -1, 2, -2}; Direction lookingAtCurrently = dir; lookAround: for (int d : directionOffsets) { lookingAtCurrently = Direction.values()[(dir.ordinal() + d + 8) % 8]; if (rc.canMove(lookingAtCurrently)) { if (!badBomb(rc.getLocation().add(lookingAtCurrently))) { rc.move(lookingAtCurrently); rc.setIndicatorString(0, "Last direction moved: " + lookingAtCurrently.toString()); } break lookAround; } } }
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 static void goDirectionAndDefuse(Direction dir) throws GameActionException { if (rc.isActive()) { Direction lookingAtCurrently = dir; lookAround: for (int d : directionOffsets) { lookingAtCurrently = Direction.values()[(dir.ordinal() + d + 8) % 8]; if (rc.isActive() && rc.canMove(lookingAtCurrently)) { if (hasBadMine(rc.getLocation().add(lookingAtCurrently))) { rc.defuseMine(rc.getLocation().add(lookingAtCurrently)); } else { rc.move(lookingAtCurrently); } break lookAround; } } } }
/** * Records a tracking direction at the given location. Returns true if the direction had * previously been recorded there. * * @param here * @param dir * @param CW * @return */ public boolean addTrackingDirection(MapLocation here, Direction dir, boolean CW) { int directionNum = dir.ordinal(); boolean prevEntry; if (directionNum >= 8) { return false; } if (!CW) { directionNum += 8; } int xIndex = here.x % HASH_WIDTH; int yIndex = here.y % HASH_HEIGHT; prevEntry = directionsHash[xIndex][yIndex][directionNum]; directionsHash[xIndex][yIndex][directionNum] = true; return prevEntry; }
private static void herdTowardPastrDumb() throws GameActionException { MapLocation target = null; do { int dx = radius * attackDir.dx; int dy = radius * attackDir.dy; target = new MapLocation(pastr.x + dx, pastr.y + dy); radius--; if (radius <= (attackDir.isDiagonal() ? 3 : 5)) { attackDir = Direction.values()[nextDumbHerdDir[attackDir.ordinal()]]; radius = attackDir.isDiagonal() ? maxDiagonalRadius : maxOrthogonalRadius; } } while (tooFarOffMap(target) || !rc.canAttackSquare(target)); rc.attackSquare(target); }
// We store the data in this format: // 1000ddddaaaaaaaaxxxxxxxxyyyyyyyy // 1 = validation to prevent mistaking the initial 0 value for a valid pathing instruction // d = direction to move (enum ordinal) // a = actions (turns) to move here // x = x coordinate of destination // y = y coordinate of destination private void publishResult( int page, MapLocation here, MapLocation dest, Direction dir, int actions) { int data = 0x80; data |= dir.ordinal(); data <<= 8; data |= actions; data <<= 8; data |= cropX(dest.x); data <<= 8; data |= cropY(dest.y); int channel = locChannel(page, here); try { rc.broadcast(channel, data); } catch (GameActionException e) { e.printStackTrace(); } }
private void retreat(MapLocation closestEnemy, MapLocation closestEncampment) throws GameActionException { Direction direnemy = rc.getLocation().directionTo(closestEnemy); int[] directionOffsets = {4, -3, 3, -2, 2}; boolean hasmoved = false; for (int d : directionOffsets) { Direction lookingAtCurrently = Direction.values()[(direnemy.ordinal() + d + 8) % 8]; if (rc.canMove(lookingAtCurrently)) { if (((rc.senseMine(rc.getLocation().add(lookingAtCurrently)))) == null) { rc.move(lookingAtCurrently); hasmoved = true; } else continue; } else continue; } if (!hasmoved) { goToLocation(closestEncampment); } }
/** * helper fcn to see what direction to actually go given a desired direction * * @param rc * @param dir * @return */ private static Direction getSpawnDirection(RobotController rc, Direction dir) { Direction canMoveDirection = null; int desiredDirOffset = dir.ordinal(); int[] dirOffsets = new int[] {0, 1, -1, 2, -2, 3, -3, 4}; for (int dirOffset : dirOffsets) { Direction currentDirection = Direction.values()[(desiredDirOffset + dirOffset + 8) % 8]; if (rc.canMove(currentDirection)) { if (canMoveDirection == null) { canMoveDirection = currentDirection; } Team mineTeam = rc.senseMine(rc.getLocation().add(currentDirection)); if (mineTeam == null || mineTeam == rc.getTeam()) { // If there's no mine here or the mine is an allied mine, we can spawn here return currentDirection; } } } // Otherwise, let's just spawn in the desired direction, and make sure to clear out a path later return canMoveDirection; }
private void markSpawnSquare() throws GameActionException { if (this.canBeTrappedByOnlyEncampments()) { // Don't commission encampment on spawn square rc.setIndicatorString(1, "Trapped by just encampments"); this.spawnSquare = currentLocation.add(this.getDirectSpawnDir()); } else { // Commission a mine defusion on spawn square rc.setIndicatorString(1, "Trapped by mines/encampments"); Direction directDir = this.getDirectSpawnDir(); int[] spawningOffsets = {0, 1, -1, 2, -2, 3, -3, 4}; SpawnSquareSearch: for (int offset : spawningOffsets) { Direction potentialSpawnDir = Direction.values()[(directDir.ordinal() + offset + 8) % 8]; MapLocation potentialSpawnSquare = this.currentLocation.add(potentialSpawnDir); if (this.mineHazard(potentialSpawnSquare)) { this.spawnSquare = potentialSpawnSquare; rc.broadcast(DefuseSpawnSquareChannel, intFromMapLocation(this.spawnSquare)); break SpawnSquareSearch; } } } rc.setIndicatorString(2, "Spawn Square: " + this.spawnSquare.toString()); }
private boolean spawnSoldier() throws GameActionException { if (rc.senseRobotCount() >= GameConstants.MAX_ROBOTS) return false; // if (rc.senseRobotCount() >= 2) return false; int spawnCount = MessageBoard.SPAWN_COUNT.readInt(); Direction startDir = here.directionTo(theirHQ); if (startDir.isDiagonal()) startDir = startDir.rotateRight(); int[] offsets = new int[] {0, 2, 4, 6, 1, 3, 5, 7}; for (int i = 0; i < offsets.length; i++) { Direction dir = Direction.values()[(startDir.ordinal() + offsets[i]) % 8]; if (rc.canMove(dir)) { rc.spawn(dir); MessageBoard.SPAWN_COUNT.writeInt(spawnCount + 1); return true; } } return false; }
public static boolean goToLocation(MapLocation whereToGo, boolean defuseMines) throws GameActionException { int dist = mRC.getLocation().distanceSquaredTo(whereToGo); if (mRC.isActive() && dist > 0) { Direction dir = mRC.getLocation().directionTo(whereToGo); for (int d : Constants.testDirOrderFrontSide) { Direction lookingAtCurrently = Direction.values()[(dir.ordinal() + d + NUM_DIR) % NUM_DIR]; if (mRC.canMove(lookingAtCurrently) && (defuseMines || !isMineDir(mRC.getLocation(), lookingAtCurrently, true))) { MapLocation newLoc = mRC.getLocation().add(lookingAtCurrently); Team mineOwner = mRC.senseMine(newLoc); if (mineOwner != null && mineOwner != mRC.getTeam()) { mRC.defuseMine(newLoc); } else { mRC.move(lookingAtCurrently); } return true; } } } return false; }
/** * Calculates the next smart waypoint to take and writes it to currentWaypoint. * * @throws GameActionException */ public static void getSmartWaypoint() throws GameActionException { MapLocation currentLocation = rc.getLocation(); if (currentLocation.distanceSquaredTo(destination) <= Constants.PATH_GO_ALL_IN_SQ_RADIUS) { // If we're already really close to the destination, just go straight in currentWaypoint = destination; return; } // Otherwise, try to pick a good direction to move in based on mines and direction to // destination int bestScore = Integer.MAX_VALUE; MapLocation bestLocation = null; Direction dirLookingAt = currentLocation.directionTo(destination); for (int i = -2; i <= 2; i++) { Direction dir = Direction.values()[(dirLookingAt.ordinal() + i + 8) % 8]; MapLocation iterLocation = currentLocation.add(dir, Constants.PATH_OFFSET_RADIUS); int currentScore = smartScore(iterLocation, Constants.PATH_CHECK_RADIUS, destination); if (currentScore < bestScore) { bestScore = currentScore; bestLocation = iterLocation; } } currentWaypoint = bestLocation; }