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; } } } }
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 void clear_rubble() throws GameActionException { if (!rc.isCoreReady()) return; if (Scanner.can_see_targets()) return; if (Scanner.there_is_hidden_enemy()) return; Direction direction_to_clear = current_location.directionTo(destination); if (direction_to_clear == Direction.NONE || direction_to_clear == Direction.OMNI) return; if (rc.senseRubble(current_location.add(direction_to_clear)) < 1) return; rc.clearRubble(direction_to_clear); rc.setIndicatorString(1, "Clearing: " + direction_to_clear.toString()); }
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; } } }