Beispiel #1
0
 private static Table getTable(Map<Block, Table> tables, MinedCounter.Entry entry) {
   Table table = tables.get(entry.getBlock());
   if (table == null) {
     table = new Table();
     tables.put(entry.getBlock(), table);
   }
   return table;
 }
Beispiel #2
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();
      }
    }
  }