Exemple #1
0
  protected static void init(RobotController theRC) throws GameActionException {
    Bot.init(theRC);
    //		Debug.init(theRC, "pages");

    // claim the assignment to build this pastr so others know not to build it
    int numPastrLocations = MessageBoard.NUM_PASTR_LOCATIONS.readInt();
    for (int i = 0; i < numPastrLocations; i++) {
      MapLocation pastrLoc = MessageBoard.BEST_PASTR_LOCATIONS.readFromMapLocationList(i);
      if (rc.getLocation().equals(pastrLoc)) {
        MessageBoard.PASTR_BUILDER_ROBOT_IDS.claimAssignment(i);
        break;
      }
    }
  }
  protected static void init(RobotController theRC) throws GameActionException {
    Bot.init(theRC);
    // Debug.init(theRC, "herd");

    here = rc.getLocation();

    // claim the assignment to build this tower so others know not to build it
    int numPastrLocations = MessageBoard.NUM_PASTR_LOCATIONS.readInt();
    amSuppressor = true;
    for (int i = 0; i < numPastrLocations; i++) {
      MapLocation pastrLoc = MessageBoard.BEST_PASTR_LOCATIONS.readFromMapLocationList(i);
      if (rc.getLocation().isAdjacentTo(pastrLoc)) {
        amSuppressor = false;
        MessageBoard.TOWER_BUILDER_ROBOT_IDS.claimAssignment(i);
        break;
      }
    }

    if (amSuppressor) {
      int bestDistSq = 999999;
      int numSuppressors = MessageBoard.NUM_SUPPRESSORS.readInt();
      int suppressorIndex = -1;
      for (int i = 0; i < numSuppressors; i++) {
        MapLocation target = MessageBoard.SUPPRESSOR_TARGET_LOCATIONS.readFromMapLocationList(i);
        int distSq = here.distanceSquaredTo(target);
        if (distSq < bestDistSq) {
          bestDistSq = distSq;
          suppressionTarget = target;
          suppressorIndex = i;
        }
      }
      if (suppressorIndex != -1) {
        MessageBoard.SUPPRESSOR_BUILDER_ROBOT_IDS.claimAssignment(suppressorIndex);
      }
    } else {
      // Figure out the best direction to start herding in
      double[] freeCows = new double[8];
      double[][] cowGrowth = rc.senseCowGrowth();
      Direction[] dirs = Direction.values();
      for (int i = 0; i < 8; i++) {
        Direction dir = dirs[i];
        MapLocation probe = here.add(dir);
        while (Util.passable(rc.senseTerrainTile(probe))
            && here.distanceSquaredTo(probe) <= RobotType.NOISETOWER.attackRadiusMaxSquared) {
          freeCows[i] += cowGrowth[probe.x][probe.y];
          probe = probe.add(dir);
        }
      }

      double bestScore = -1;
      int bestDir = -1;
      for (int i = 0; i < 8; i++) {
        double score = freeCows[i] + freeCows[(i + 1) % 8] + freeCows[(i + 2) % 8];
        if (score > bestScore) {
          bestScore = score;
          bestDir = i;
        }
      }
      attackDir = dirs[bestDir];
    }
  }