コード例 #1
0
ファイル: App.java プロジェクト: pvginkel/AutoMiner
  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;
  }
コード例 #2
0
ファイル: App.java プロジェクト: pvginkel/AutoMiner
  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();
      }
    }
  }