Пример #1
0
  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());
      }
    }
  }
Пример #2
0
 private static void moveOrDefuse(Direction dir) throws GameActionException {
   MapLocation ahead = rc.getLocation().add(dir);
   if (rc.senseMine(ahead) != null) {
     rc.defuseMine(ahead);
   } else {
     rc.move(dir);
   }
 }
 private void moveOrDefuse(Direction dir) throws GameActionException {
   MapLocation ahead = rc.getLocation().add(dir);
   if (rc.canMove(dir) && rc.senseMine(ahead) != null && rc.senseMine(ahead) != rc.getTeam()) {
     rc.defuseMine(ahead);
   } else {
     if (rc.canMove(dir)) {
       rc.move(dir);
     }
   }
 }
 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);
       }
     }
   }
 }
Пример #5
0
 private static void goDirectionAndDefuse(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.defuseMine(rc.getLocation().add(lookingAtCurrently));
       } else {
         rc.move(lookingAtCurrently);
         rc.setIndicatorString(0, "Last direction moved: " + lookingAtCurrently.toString());
       }
       break lookAround;
     }
   }
 }