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); } }
/** * Moves to a square that is closer to the goal returns true if was able to move, false otherwise * * @param goalLoc * @return * @throws GameActionException */ public static boolean moveCloser() throws GameActionException { // first try to get closer double distance = rc.getLocation().distanceSquaredTo(destination); for (int i = 8; --i >= 0; ) { if (rc.canMove(DataCache.directionArray[i])) { MapLocation nextLoc = rc.getLocation().add(DataCache.directionArray[i]); if (nextLoc.distanceSquaredTo(destination) < distance) { NavSystem.moveOrDefuse(DataCache.directionArray[i]); return true; } } } return false; }
public static void tryBFSNextTurn() throws GameActionException { if (BFSIdle >= 50) { // if idle for 50 turns or more // we retry destination setupGetCloser(destination); } else { // System.out.println("BFS length: " + BFSTurns.length); // System.out.println("Direction: " + BFSTurns[BFSRound]); Direction dir = Direction.values()[BFSTurns[BFSRound]]; boolean hasMoved = NavSystem.moveOrDefuse(dir); if (hasMoved) { BFSRound++; } else { BFSIdle++; } } }