예제 #1
0
  // move in a given direction
  public static void moveInDirection(Direction d) throws GameActionException {
    MapLocation m = rc.getLocation().add(d);

    if (rc.senseRubble(m) < tooMuchRubble
        || Math.random() < probClearRubbleAnyways) // if it's less than 20, just move there
    {
      if (rc.isCoreReady() && rc.canMove(d)) {
        rc.move(d);
      }
    } else // clear it
    {
      if (rc.isCoreReady()) {
        rc.clearRubble(d);
      }
    }
  }
예제 #2
0
  // move to a maplocation
  public static void moveToLocation(MapLocation m) throws GameActionException {
    MapLocation currentLoc = rc.getLocation();
    Direction directionToM = currentLoc.directionTo(m);
    Direction actualDirectionToMove = directionToM;

    // deal with the slug trail - trim it to size
    if (past10Locations.size() > 10) {
      while (past10Locations.size() > 10) {
        past10Locations.remove(past10Locations.size() - 1);
      }
    }
    past10Locations.add(currentLoc);

    MapLocation locationToMoveTo = currentLoc.add(directionToM);

    if (canMoveThere(
        actualDirectionToMove,
        locationToMoveTo)) // make sure it's not part of the slug trail and it's not blocked by
                           // rubble and you can move there
    {
      moveInDirection(actualDirectionToMove);
    } else {
      // first, check if you should remove rubble. only if the surrounding squares are empty
      // boolean shouldRemoveRubble = false;
      int directionsWithRubble = 0;
      for (Direction d : Direction.values()) {
        MapLocation added = goal.add(d);
        boolean isFullOfRubble = rc.senseRubble(added) > 50;
        if (isFullOfRubble) {
          directionsWithRubble++;
        }
      }
      if (directionsWithRubble > 2) // if it's surrounded then dig
      {
        if (rc.isCoreReady()) {
          if (actualDirectionToMove.equals(Direction.OMNI) == false) {
            rc.clearRubble(actualDirectionToMove);
          }
        }
      } else // if not, path around it
      {
        Direction right = actualDirectionToMove.rotateRight();
        MapLocation rightLoc = currentLoc.add(right);

        while (right.equals(actualDirectionToMove) == false) {
          if (canMoveThere(right, rightLoc)) {
            moveInDirection(right);
            right = actualDirectionToMove;
          } else {
            right = right.rotateRight();
            rightLoc = currentLoc.add(right);
          }
        }
      }
    }
  }
예제 #3
0
 // build a robot of a given type
 public static void buildRobot(RobotType type) throws GameActionException {
   if (rc.isCoreReady() && rc.hasBuildRequirements(type)) {
     Direction[] values = Direction.values();
     for (Direction dir : values) {
       if (rc.canBuild(dir, type)) {
         rc.build(dir, type);
         return;
       }
     }
   }
 }