Search in sources :

Example 1 with Timer

use of bwem.util.Timer in project BWAPI4J by OpenBW.

the class TestListenerYata method onStart.

@Override
public void onStart() {
    try {
        System.out.println("onStart");
        this.bw.getInteractionHandler().enableUserInput();
        System.out.println("YATA initialization started.");
        this.yata = new YATA(this.bw.getBWMap());
        System.out.println("YATA initialization complete.");
        final MapPrinter mapPrinter = new MapPrinter(new TilePosition(this.bw.getBWMap().mapWidth(), this.bw.getBWMap().mapHeight()));
        for (int y = 0; y < this.yata.getHeight(); ++y) {
            for (int x = 0; x < this.yata.getWidth(); ++x) {
                final Color color = this.yata.getNodes()[x][y].isWalkable() ? Color.GREEN : Color.BLACK;
                final TilePosition tilePosition = new TilePosition(x, y);
                mapPrinter.Point(tilePosition.toWalkPosition(), color);
            }
        }
        final TilePosition sourceTilePosition = this.bw.getBWMap().getStartPositions().get(0);
        final TilePosition targetTilePosition = this.bw.getBWMap().getStartPositions().get(1);
        // final TilePosition sourceTilePosition = new TilePosition(65, 104);
        // final TilePosition targetTilePosition = new TilePosition(89, 106);
        Timer timer = new Timer();
        final List<TilePosition> tilePath = this.yata.getPath(sourceTilePosition, targetTilePosition);
        System.out.println("getPath(): " + timer.elapsedMilliseconds() + " ms");
        timer.reset();
        for (final TilePosition tilePosition : tilePath) {
            mapPrinter.Point(tilePosition.toWalkPosition(), Color.WHITE);
        }
        mapPrinter.writeImageToFile(Paths.get("yata.png"));
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(0);
    }
}
Also used : Timer(bwem.util.Timer) TilePosition(org.openbw.bwapi4j.TilePosition)

Aggregations

Timer (bwem.util.Timer)1 TilePosition (org.openbw.bwapi4j.TilePosition)1