Search in sources :

Example 51 with Position

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

the class CheckResourcesIsland method execute.

@Override
public State execute() {
    try {
        MutablePair<Integer, Integer> cash = gameState.getCash();
        Worker chosen = gameState.chosenWorkerDrop;
        UnitType chosenType = UnitType.Terran_Command_Center;
        TilePosition start = chosen.getTilePosition();
        TilePosition end = gameState.chosenIsland.getLocation();
        Position realEnd = Util.getUnitCenterPosition(end.toPosition(), chosenType);
        if (cash.first + gameState.getMineralsWhenReaching(start, realEnd.toTilePosition()) >= chosenType.mineralPrice() + gameState.deltaCash.first) {
            return State.SUCCESS;
        }
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        e.printStackTrace();
        return State.ERROR;
    }
}
Also used : TilePosition(org.openbw.bwapi4j.TilePosition) Position(org.openbw.bwapi4j.Position) UnitType(org.openbw.bwapi4j.type.UnitType) TilePosition(org.openbw.bwapi4j.TilePosition) Worker(org.openbw.bwapi4j.unit.Worker)

Example 52 with Position

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

the class ChooseIsland method execute.

@Override
public State execute() {
    try {
        Base chosen = null;
        double distMax = Double.MAX_VALUE;
        Position drop = gameState.chosenDropShip.unit.getPosition();
        for (Base b : gameState.islandBases) {
            if (gameState.islandCCs.containsKey(b))
                continue;
            double dist = Util.broodWarDistance(b.getLocation().toPosition(), drop);
            if (dist < distMax) {
                distMax = dist;
                chosen = b;
            }
        }
        if (chosen != null) {
            gameState.chosenIsland = chosen;
            return State.SUCCESS;
        }
        gameState.chosenDropShip = null;
        gameState.chosenWorker = null;
        gameState.chosenIsland = null;
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        e.printStackTrace();
        return State.ERROR;
    }
}
Also used : Position(org.openbw.bwapi4j.Position) Base(bwem.Base)

Example 53 with Position

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

the class ChooseRepairer method execute.

@Override
public State execute() {
    try {
        SCV closestWorker = null;
        Position chosen = gameState.chosenUnitRepair.getPosition();
        int frame = gameState.frameCount;
        for (Worker u : gameState.workerIdle) {
            if (u.getLastCommandFrame() == frame)
                continue;
            if ((closestWorker == null || u.getDistance(chosen) < closestWorker.getDistance(chosen))) {
                closestWorker = (SCV) u;
            }
        }
        for (Worker u : gameState.workerMining.keySet()) {
            if (u.getLastCommandFrame() == frame)
                continue;
            if ((closestWorker == null || u.getDistance(chosen) < closestWorker.getDistance(chosen)) && !u.isCarryingMinerals()) {
                closestWorker = (SCV) u;
            }
        }
        if (closestWorker != null) {
            gameState.chosenRepairer = closestWorker;
            return State.SUCCESS;
        }
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        e.printStackTrace();
        return State.ERROR;
    }
}
Also used : Position(org.openbw.bwapi4j.Position) SCV(org.openbw.bwapi4j.unit.SCV) Worker(org.openbw.bwapi4j.unit.Worker)

Example 54 with Position

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

the class ChooseWorkerDrop method execute.

@Override
public State execute() {
    try {
        Worker closestWorker = null;
        int frame = gameState.frameCount;
        Position chosen = gameState.chosenDropShip.unit.getPosition();
        if (!gameState.workerIdle.isEmpty()) {
            for (Worker u : gameState.workerIdle) {
                if (u.isCarryingMinerals())
                    continue;
                if (u.getLastCommandFrame() == frame)
                    continue;
                if ((closestWorker == null || u.getDistance(chosen) < closestWorker.getDistance(chosen))) {
                    closestWorker = u;
                }
            }
        }
        if (!gameState.workerMining.isEmpty()) {
            for (Worker u : gameState.workerMining.keySet()) {
                if (u.isCarryingMinerals())
                    continue;
                if (u.getLastCommandFrame() == frame)
                    continue;
                if ((closestWorker == null || u.getDistance(chosen) < closestWorker.getDistance(chosen)) && !u.isCarryingMinerals()) {
                    closestWorker = u;
                }
            }
        }
        if (closestWorker != null) {
            gameState.chosenWorker = closestWorker;
            return State.SUCCESS;
        }
        gameState.chosenDropShip = null;
        gameState.chosenWorker = null;
        gameState.chosenIsland = null;
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        e.printStackTrace();
        return State.ERROR;
    }
}
Also used : Position(org.openbw.bwapi4j.Position) Worker(org.openbw.bwapi4j.unit.Worker)

Example 55 with Position

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

the class SimulationTheory method drawCluster.

/**
 * Draws a cluster on the screen
 *
 * @param c    The cluster to be drawn
 * @param ally If true draws the cluster using green lines otherwise red lines
 * @param id   Cluster identifier
 */
private void drawCluster(Cluster c, boolean ally, int id) {
    Color color = Color.RED;
    if (ally)
        color = Color.GREEN;
    Position centroid = new Position((int) c.modeX, (int) c.modeY);
    getGs().getGame().getMapDrawer().drawCircleMap(centroid, 4, color, true);
    // getGs().getGame().getMapDrawer().drawTextMap(centroid.add(new Position(0, 5)), ColorUtil.formatText(Integer.toString(id), ColorUtil.White));
    for (UnitInfo u : c.units) getGs().getGame().getMapDrawer().drawLineMap(u.lastPosition, centroid, color);
}
Also used : UnitInfo(ecgberht.UnitInfo) 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