Exemple #1
0
  private static Rectangle findBoundingBox(List<Chunk> chunks) {
    Set<Point> points =
        chunks
            .stream()
            .map(p -> new Point(p.getPosition().getX(), p.getPosition().getZ()))
            .collect(Collectors.toSet());

    // Find the bounding box of the chunks.

    int minX = Integer.MAX_VALUE;
    int minZ = Integer.MAX_VALUE;
    int maxX = Integer.MIN_VALUE;
    int maxZ = Integer.MIN_VALUE;

    for (Point point : points) {
      minX = Math.min(minX, point.getX());
      minZ = Math.min(minZ, point.getY());
      maxX = Math.max(maxX, point.getX());
      maxZ = Math.max(maxZ, point.getY());
    }

    // See whether we're missing any Z's on any of the X chunks.

    int validMinX = minX;
    int validMaxX = maxX;

    // Remove a little bit from the top and bottom to find a larger bounding block.

    minZ += 5;
    maxZ -= 5;

    for (int z = minZ; z <= maxZ; z++) {
      for (int x = minX; x <= maxX; x++) {
        if (!points.contains(new Point(x, z))) {
          if (x > (minX + maxX) / 2) {
            validMaxX = Math.min(validMaxX, x - 1);
          } else {
            validMinX = Math.max(validMinX, x + 1);
          }
        }
      }
    }

    minX = validMinX;
    maxX = validMaxX;

    return new Rectangle(minX, minZ, maxX, maxZ);
  }
Exemple #2
0
  private static MinedCounter runStrategy(
      BlockMap blockMap, int mineLength, List<Vector> starts, int branchOffset, int branches) {
    MinedCounter mined = new MinedCounter();

    for (Vector start : starts) {
      Miner miner = new Miner(blockMap.clone());

      for (int x = 0; x < branches; x++) {
        Vector currentStart =
            new Vector(start.getX() + x * branchOffset, start.getY(), start.getZ());

        miner.run(currentStart, new Point(0, 1), mineLength);
      }

      //            System.out.println(String.format("Iteration %d", i + 1));
      //            System.out.println(miner.getMined());

      mined.addAll(miner.getMined());
    }

    mined.average(starts.size());

    return mined;
  }
Exemple #3
0
  public static void main(String[] args) throws Exception {
    File cacheFile = new File(CACHE_FILE);
    if (!cacheFile.exists()) {
      System.out.println("Building cache file");
      buildCache(args[0]);
    }

    System.out.println("Loading cache file...");

    BlockMap blockMap = BlockMap.load(cacheFile);

    final int iterations = 10;
    final int mineLength = 1000;

    List<Vector> starts = new ArrayList<>();
    Map<Block, Table> tables = new HashMap<>();

    for (int y = 9; y <= 13; y++) {
      System.out.println();
      System.out.println("Depth: " + y);
      System.out.println();

      for (int i = 0; i < iterations; i++) {
        starts.add(
            new Vector(
                blockMap.getOffset().getX() + 50 + RANDOM.nextInt(blockMap.getCx() - 100),
                y,
                blockMap.getOffset().getZ()
                    + 50
                    + RANDOM.nextInt(blockMap.getCz() - 100 - mineLength)));
      }

      MinedCounter mined = runStrategy(blockMap, mineLength, starts, 0, 1);

      //            System.out.println(mined);

      System.out.println(
          String.format(
              "Single branch: %s: %.1f, %s: %.1f",
              Blocks.DIAMOND_ORE.getName(),
              mined.get(Blocks.DIAMOND_ORE),
              Blocks.LAVA.getName(),
              mined.get(Blocks.LAVA)));

      for (MinedCounter.Entry entry : mined.entrySet()) {
        getTable(tables, entry).set(Integer.toString(y), "Single branch", entry.getValue());
      }

      final int branches = 4;

      for (int branchDistance = 2; branchDistance <= 7; branchDistance++) {
        //                System.out.println("Running strategy x+" + branchDistance + "+" +
        // branchDistance + " at " + y);

        mined = runStrategy(blockMap, mineLength, starts, branchDistance, branches);
        mined.average(branches);

        //            System.out.println(mined);

        System.out.println(
            String.format(
                "Strategy x+%d: %s: %.1f, %s: %.1f",
                branchDistance,
                Blocks.DIAMOND_ORE.getName(),
                mined.get(Blocks.DIAMOND_ORE),
                Blocks.LAVA.getName(),
                mined.get(Blocks.LAVA)));

        for (MinedCounter.Entry entry : mined.entrySet()) {
          getTable(tables, entry)
              .set(
                  Integer.toString(y),
                  String.format("Strategy x+%d", branchDistance),
                  entry.getValue());
        }
      }
    }

    try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream("out.txt"))) {
      OutputWriter ow = new OutputWriter(writer);

      for (Map.Entry<Block, Table> entry : tables.entrySet()) {
        ow.write(entry.getKey().getName());
        ow.nl();
        entry.getValue().write(ow);
        ow.nl();
      }
    }
  }