Search in sources :

Example 1 with Position

use of org.openbw.bwapi4j.Position in project BWAPI4J by OpenBW.

the class TestListenerBwem method onFrame.

@Override
public void onFrame() {
    try {
        // Send idle workers to mine at the closest mineral patch.
        for (final Worker worker : workers) {
            if (worker.isIdle()) {
                MineralPatch closestMineralPatch = null;
                for (final MineralPatch mineralPatch : bw.getMineralPatches()) {
                    if (closestMineralPatch == null) {
                        closestMineralPatch = mineralPatch;
                    } else {
                        if (mineralPatch.getPosition().getDistance(self.getStartLocation().toPosition()) < closestMineralPatch.getPosition().getDistance(self.getStartLocation().toPosition())) {
                            closestMineralPatch = mineralPatch;
                        }
                    }
                }
                worker.gather(closestMineralPatch);
            }
        }
        /* Train an SCV at every Command Center. */
        {
            if (self.getRace() == Race.Terran) {
                for (final PlayerUnit u : bw.getUnits(self)) {
                    if (u instanceof CommandCenter) {
                        final CommandCenter commandCenter = (CommandCenter) u;
                        if (!commandCenter.isTraining()) {
                            commandCenter.trainWorker();
                        }
                    }
                }
            }
        }
        /* Highlight starting locations and possible base locations. */
        {
            for (final Base base : bwem.getMap().getBases()) {
                final boolean isStartingLocation = base.isStartingLocation();
                final Color highlightColor = isStartingLocation ? Color.GREEN : Color.YELLOW;
                final Position baseLocation = base.getLocation().toPosition();
                final Position resourceDepotSize = UnitType.Terran_Command_Center.tileSize().toPosition();
                if (isOnScreen(baseLocation)) {
                    bw.getMapDrawer().drawBoxMap(baseLocation, baseLocation.add(resourceDepotSize), highlightColor);
                }
                /* Display minerals. */
                for (final Mineral mineral : base.getMinerals()) {
                    if (isOnScreen(mineral.getCenter())) {
                        bw.getMapDrawer().drawLineMap(mineral.getCenter(), base.getCenter(), Color.CYAN);
                    }
                }
                /* Display geysers. */
                for (final Geyser geyser : base.getGeysers()) {
                    if (isOnScreen(geyser.getCenter())) {
                        bw.getMapDrawer().drawLineMap(geyser.getCenter(), base.getCenter(), Color.GREEN);
                    }
                }
            }
        }
        /* Highlight choke points. */
        {
            final int chokePointRadius = 8;
            final Color chokePointColor = Color.RED;
            for (final ChokePoint chokePoint : bwem.getMap().getChokePoints()) {
                final Position center = chokePoint.getCenter().toPosition();
                if (isOnScreen(center)) {
                    bw.getMapDrawer().drawCircleMap(center, chokePointRadius, chokePointColor);
                    bw.getMapDrawer().drawLineMap(center.getX() - chokePointRadius, center.getY(), center.getX() + chokePointRadius, center.getY(), chokePointColor);
                    bw.getMapDrawer().drawLineMap(center.getX(), center.getY() - chokePointRadius, center.getX(), center.getY() + chokePointRadius, chokePointColor);
                }
            }
        }
        /* Highlight workers. */
        {
            for (final Worker worker : workers) {
                final Position tileSize = new TilePosition(worker.tileWidth(), worker.tileHeight()).toPosition();
                final Position topLeft = worker.getPosition().subtract(tileSize.divide(new Position(2, 2)));
                final Position bottomRight = topLeft.add(tileSize);
                if (isOnScreen(topLeft)) {
                    bw.getMapDrawer().drawBoxMap(topLeft, bottomRight, Color.BROWN);
                }
            }
        }
        /* Draw mouse position debug info. */
        {
            final Position screenPosition = bw.getInteractionHandler().getScreenPosition();
            final Position mousePosition = screenPosition.add(bw.getInteractionHandler().getMousePosition());
            final String mouseText = "T:" + mousePosition.toTilePosition().toString() + "\nW:" + mousePosition.toWalkPosition().toString() + "\nP:" + mousePosition.toString();
            bw.getMapDrawer().drawBoxMap(mousePosition.toTilePosition().toPosition(), mousePosition.toTilePosition().toPosition().add(new TilePosition(1, 1).toPosition()), Color.WHITE);
            bw.getMapDrawer().drawTextMap(mousePosition.add(new Position(20, -10)), mouseText);
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(0);
    }
}
Also used : Mineral(bwem.unit.Mineral) TilePosition(org.openbw.bwapi4j.TilePosition) Position(org.openbw.bwapi4j.Position) Color(org.openbw.bwapi4j.type.Color) CommandCenter(org.openbw.bwapi4j.unit.CommandCenter) MineralPatch(org.openbw.bwapi4j.unit.MineralPatch) Geyser(bwem.unit.Geyser) TilePosition(org.openbw.bwapi4j.TilePosition) Worker(org.openbw.bwapi4j.unit.Worker) PlayerUnit(org.openbw.bwapi4j.unit.PlayerUnit)

Example 2 with Position

use of org.openbw.bwapi4j.Position in project BWAPI4J by OpenBW.

the class BwemExt method centerOfBuilding.

public static Position centerOfBuilding(final TilePosition tilePosition, final TilePosition buildingSize) {
    final Position pixelSize = buildingSize.toPosition();
    final Position pixelOffset = pixelSize.divide(new Position(2, 2));
    return tilePosition.toPosition().add(pixelOffset);
}
Also used : WalkPosition(org.openbw.bwapi4j.WalkPosition) TilePosition(org.openbw.bwapi4j.TilePosition) Position(org.openbw.bwapi4j.Position)

Example 3 with Position

use of org.openbw.bwapi4j.Position in project BWAPI4J by OpenBW.

the class BwemExt method drawDiagonalCrossMap.

public static void drawDiagonalCrossMap(final MapDrawer mapDrawer, final Position topLeft, final Position bottomRight, final Color col) {
    mapDrawer.drawLineMap(topLeft, bottomRight, col);
    mapDrawer.drawLineMap(new Position(bottomRight.getX(), topLeft.getY()), new Position(topLeft.getX(), bottomRight.getY()), col);
}
Also used : WalkPosition(org.openbw.bwapi4j.WalkPosition) TilePosition(org.openbw.bwapi4j.TilePosition) Position(org.openbw.bwapi4j.Position)

Example 4 with Position

use of org.openbw.bwapi4j.Position in project BWAPI4J by OpenBW.

the class Building method getLasKnownDistance.

public double getLasKnownDistance(Unit target) {
    if (this == target) {
        return 0;
    }
    int xDist = (this.getLastKnownPosition().getX() - this.type.dimensionLeft()) - (target.getRight() + 1);
    if (xDist < 0) {
        xDist = target.getLeft() - ((this.getLastKnownPosition().getX() + this.type.dimensionRight()) + 1);
        if (xDist < 0) {
            xDist = 0;
        }
    }
    int yDist = (this.getLastKnownPosition().getY() - this.type.dimensionUp()) - (target.getBottom() + 1);
    if (yDist < 0) {
        yDist = target.getTop() - ((this.getLastKnownPosition().getY() + this.type.dimensionDown()) + 1);
        if (yDist < 0) {
            yDist = 0;
        }
    }
    logger.trace("dx, dy: {}, {}.", xDist, yDist);
    return new Position(0, 0).getDistance(new Position(xDist, yDist));
}
Also used : TilePosition(org.openbw.bwapi4j.TilePosition) Position(org.openbw.bwapi4j.Position)

Example 5 with Position

use of org.openbw.bwapi4j.Position in project Ecgberht by Jabbo16.

the class ChooseDefensePosition method chooseDefensePosition.

private Position chooseDefensePosition() {
    Position chosen = null;
    double maxScore = 0;
    for (Unit b : gameState.enemyInBase) {
        double influence = getScore(b);
        // double score = influence / (2 * getEuclideanDist(p, b.pos.toPosition()));
        double score = influence / (2.5 * Util.getGroundDistance(getDefensePosition(), b.getPosition()));
        if (score > maxScore) {
            chosen = b.getPosition();
            maxScore = score;
        }
    }
    return chosen;
}
Also used : Position(org.openbw.bwapi4j.Position)

Aggregations

Position (org.openbw.bwapi4j.Position)55 TilePosition (org.openbw.bwapi4j.TilePosition)19 UnitInfo (ecgberht.UnitInfo)10 Worker (org.openbw.bwapi4j.unit.Worker)10 UnitType (org.openbw.bwapi4j.type.UnitType)9 SimInfo (ecgberht.Simulation.SimInfo)8 Util (ecgberht.Util.Util)8 WalkPosition (org.openbw.bwapi4j.WalkPosition)8 Ecgberht.getGs (ecgberht.Ecgberht.getGs)7 UtilMicro (ecgberht.Util.UtilMicro)7 org.openbw.bwapi4j.unit (org.openbw.bwapi4j.unit)7 Area (bwem.Area)6 Base (bwem.Base)6 Collectors (java.util.stream.Collectors)6 Order (org.openbw.bwapi4j.type.Order)6 java.util (java.util)5 WeaponType (org.openbw.bwapi4j.type.WeaponType)5 ArrayList (java.util.ArrayList)4 MineralPatch (org.openbw.bwapi4j.unit.MineralPatch)4 Squad (ecgberht.Squad)3