/**
   * Attempts to build a robot of the given type in a random direction (attempts all directions).
   * Only attempts building if rc has no core delay and has more parts than the threshold.
   *
   * @param rc RobotController from which to build
   * @param buildType type of robot to build
   * @return true if buildType is built else false
   * @throws GameActionException
   */
  private static boolean tryToBuild(RobotController rc, RobotType buildType)
      throws GameActionException {
    if (rc.isCoreReady()) {
      Direction buildDir = getRandomDirection();
      for (int i = 0; i < 8; i++) {
        if (rc.canBuild(buildDir, buildType)) {
          rc.build(buildDir, buildType);
          rc.broadcastMessageSignal(SENDING_MODE, currentMode, ONE_SQUARE_RADIUS);

          if (!turtleCorner.equals(LOCATION_NONE)) {
            rc.broadcastMessageSignal(SENDING_TURTLE_X, turtleCorner.x, ONE_SQUARE_RADIUS);
            rc.broadcastMessageSignal(SENDING_TURTLE_Y, turtleCorner.y, ONE_SQUARE_RADIUS);
          }

          if (buildType.equals(RobotType.SCOUT)) {
            for (MapLocation scoutKitingLoc : SCOUT_KITING_LOCATIONS) {
              rc.broadcastMessageSignal(
                  SENDING_SCOUT_KITING_LOCATION_X, scoutKitingLoc.x, ONE_SQUARE_RADIUS);
              rc.broadcastMessageSignal(
                  SENDING_SCOUT_KITING_LOCATION_Y, scoutKitingLoc.y, ONE_SQUARE_RADIUS);
            }
          }
          return true;
        }
        buildDir = buildDir.rotateRight(); // try all directions clockwise
      }
    }
    return false;
  }
Exemple #2
0
  protected boolean tryBuild(RobotType robotType, Direction initialDirection)
      throws GameActionException {
    if (!rc.isCoreReady()) {
      return false;
    }

    if (rc.getTeamParts() < robotType.partCost) {
      return false;
    }

    int startingPosition = getDirectionNumber(initialDirection);
    if (startingPosition < 0) {
      startingPosition = 0;
    }

    int[] d = {0, 1, 7, 2, 6, 3, 5, 4};
    for (int i = 0; i < 8; i++) {
      Direction direction = directions[(startingPosition + d[i]) % 8];
      if (rc.canBuild(direction, robotType)) {
        rc.build(direction, robotType);
        return true;
      }
    }

    return false;
  }
Exemple #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;
       }
     }
   }
 }
 /**
  * If robotType is null, compute where to move. Else compute where to build.
  *
  * @param rc
  * @param dir
  * @param robotType
  * @return Direction to move/build in
  */
 static Direction findPathDirection(RobotController rc, Direction dir, RobotType robotType) {
   final int maxRotations = 8;
   int diff = rand.nextInt(2);
   for (int i = 0; i <= maxRotations; ++i) {
     if (i == maxRotations) return Direction.NONE;
     if ((i + diff) % 2 == 0) {
       for (int j = 0; j < i; ++j) dir = dir.rotateLeft();
     } else {
       for (int j = 0; j < i; ++j) dir = dir.rotateRight();
     }
     if (robotType == null) {
       if (rc.canMove(dir)) break;
     } else {
       if (rc.canBuild(dir, robotType)) break;
     }
   }
   return dir;
 }
Exemple #5
0
  protected boolean tryBuild(RobotType robotType) throws GameActionException {
    if (!rc.isCoreReady()) {
      return false;
    }

    if (rc.getTeamParts() < robotType.partCost) {
      return false;
    }

    // --Build robot in some random direction
    for (int i = 0; i < 8; i++) {
      if (rc.canBuild(directions[i], robotType)) {
        rc.build(directions[i], robotType);
        return true;
      }
    }

    return false;
  }
  // This method will attempt to build in the given direction (or as close to it as possible)
  static boolean tryBuild(Direction d, RobotType type) {
    int offsetIndex = 0;
    int[] offsets = {0, 1, -1, 2, -2, 3, -3, 4};
    int dirint = directionToInt(d);
    while (offsetIndex < 8) {
      int i = (dirint + offsets[offsetIndex] + 8) % 8;
      Direction build = directions[i];
      MapLocation m = myLoc.add(build);

      if (rc.canBuild(build, type) && !wouldBlock(build) && !threats.isThreatened(m)) {
        try {
          rc.build(directions[i], type);
          strategy.addUnit(type);
        } catch (GameActionException e) {
          System.out.println("Build exception");
          // e.printStackTrace();
        }
        return true;
      }
      offsetIndex++;
    }

    return false;
  }