Search in sources :

Example 1 with SCV

use of org.openbw.bwapi4j.unit.SCV in project BWAPI4J by OpenBW.

the class MainTest method testMineralMining.

private void testMineralMining() throws AssertionError {
    boolean commandSuccessful = false;
    Player self = this.bw.getInteractionHandler().self();
    Collection<Unit> allUnits = this.bw.getAllUnits();
    MineralPatch patch = null;
    for (Unit unit : allUnits) {
        if (unit instanceof MineralPatch) {
            patch = (MineralPatch) unit;
        }
    }
    List<PlayerUnit> units = this.bw.getUnits(self);
    SCV scv = null;
    for (PlayerUnit unit : units) {
        if (unit instanceof SCV) {
            scv = (SCV) unit;
        }
    }
    if (patch != null && scv != null) {
        commandSuccessful = scv.gather(patch);
    } else {
        logger.error("no scv and patch found.");
    }
    assertTrue("gather command failed.", commandSuccessful);
}
Also used : MineralPatch(org.openbw.bwapi4j.unit.MineralPatch) SCV(org.openbw.bwapi4j.unit.SCV) PlayerUnit(org.openbw.bwapi4j.unit.PlayerUnit) Unit(org.openbw.bwapi4j.unit.Unit) PlayerUnit(org.openbw.bwapi4j.unit.PlayerUnit)

Example 2 with SCV

use of org.openbw.bwapi4j.unit.SCV in project Ecgberht by Jabbo16.

the class WorkerWalkBuild method execute.

@Override
public State execute() {
    try {
        for (Entry<SCV, MutablePair<UnitType, TilePosition>> u : gameState.workerBuild.entrySet()) {
            SCV chosen = u.getKey();
            if (u.getValue().first != UnitType.Terran_Command_Center || gameState.getGame().getBWMap().isVisible(u.getValue().second) || !gameState.fortressSpecialBLsTiles.contains(u.getValue().second))
                continue;
            Base myBase = Util.getClosestBaseLocation(u.getValue().second.toPosition());
            MutablePair<MineralPatch, MineralPatch> minerals = gameState.fortressSpecialBLs.get(myBase);
            Area scvArea = gameState.bwem.getMap().getArea(chosen.getTilePosition());
            if (!u.getValue().second.equals(new TilePosition(7, 118))) {
                if (scvArea != null && scvArea.equals(myBase.getArea())) {
                    if (chosen.getDistance(minerals.first) > 3 * 32) {
                        chosen.move(u.getValue().second.toPosition());
                        continue;
                    }
                    if (minerals.second.isVisible()) {
                        chosen.gather(minerals.second);
                        continue;
                    }
                }
                if (minerals.second.isVisible()) {
                    chosen.gather(minerals.second);
                    continue;
                }
                if (minerals.first.isVisible()) {
                    chosen.gather(minerals.first);
                }
            } else {
                // Weird logic :/
                if (scvArea != null && scvArea.equals(myBase.getArea())) {
                    if (chosen.getDistance(minerals.first) > 3 * 32) {
                        chosen.move(u.getValue().second.toPosition());
                        continue;
                    } else {
                        chosen.gather(minerals.second);
                        continue;
                    }
                }
                chosen.gather(minerals.first);
            }
        }
        return State.SUCCESS;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        e.printStackTrace();
        return State.ERROR;
    }
}
Also used : MutablePair(ecgberht.Util.MutablePair) Area(bwem.Area) MineralPatch(org.openbw.bwapi4j.unit.MineralPatch) SCV(org.openbw.bwapi4j.unit.SCV) TilePosition(org.openbw.bwapi4j.TilePosition) Base(bwem.Base)

Example 3 with SCV

use of org.openbw.bwapi4j.unit.SCV in project Ecgberht by Jabbo16.

the class Build method execute.

@Override
public State execute() {
    try {
        List<SCV> toRemove = new ArrayList<>();
        for (Entry<SCV, MutablePair<UnitType, TilePosition>> u : gameState.workerBuild.entrySet()) {
            if (u.getKey().getOrder() != Order.PlaceBuilding && gameState.getGame().getBWMap().isVisible(u.getValue().second) && gameState.canAfford(u.getValue().first)) {
                SCV chosen = u.getKey();
                if (u.getValue().first == UnitType.Terran_Bunker) {
                    if (!chosen.build(u.getValue().second, u.getValue().first)) {
                        gameState.deltaCash.first -= u.getValue().first.mineralPrice();
                        gameState.deltaCash.second -= u.getValue().first.gasPrice();
                        toRemove.add(chosen);
                        chosen.stop(false);
                        gameState.workerIdle.add(chosen);
                    }
                } else if (u.getKey().getOrder() == Order.PlayerGuard) {
                    if (Math.random() < 0.8)
                        chosen.build(u.getValue().second, u.getValue().first);
                    else
                        chosen.move(u.getKey().getPosition().add(new Position(32, 0)));
                } else
                    chosen.build(u.getValue().second, u.getValue().first);
            }
        }
        for (SCV s : toRemove) gameState.workerBuild.remove(s);
        return State.SUCCESS;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        e.printStackTrace();
        return State.ERROR;
    }
}
Also used : MutablePair(ecgberht.Util.MutablePair) TilePosition(org.openbw.bwapi4j.TilePosition) Position(org.openbw.bwapi4j.Position) SCV(org.openbw.bwapi4j.unit.SCV) ArrayList(java.util.ArrayList)

Example 4 with SCV

use of org.openbw.bwapi4j.unit.SCV in project Ecgberht by Jabbo16.

the class CheckMineralWalkGoldRush method getCloserMineral.

private MineralPatch getCloserMineral(Map.Entry<SCV, MutablePair<UnitType, TilePosition>> entry) {
    double bestDist = Double.MAX_VALUE;
    MineralPatch closerMineral = null;
    SCV scv = entry.getKey();
    Position buildTarget = entry.getValue().second.toPosition();
    for (MineralPatch mineralPatch : gameState.walkingMinerals) {
        if (!mineralPatch.isVisible() || scv.getDistance(mineralPatch) <= 32 * 4)
            continue;
        double dist = mineralPatch.getDistance(buildTarget) * 1.2;
        if (dist > scv.getDistance(buildTarget))
            continue;
        Area mineralArea = gameState.bwem.getMap().getArea(mineralPatch.getTilePosition());
        Area workerArea = gameState.bwem.getMap().getArea(scv.getTilePosition());
        if (mineralPatch.equals(scv.getTargetUnit()) && mineralArea != null && mineralArea.equals(workerArea))
            continue;
        if (dist < bestDist) {
            bestDist = dist;
            closerMineral = mineralPatch;
        }
    }
    return closerMineral;
}
Also used : Area(bwem.Area) MineralPatch(org.openbw.bwapi4j.unit.MineralPatch) TilePosition(org.openbw.bwapi4j.TilePosition) Position(org.openbw.bwapi4j.Position) SCV(org.openbw.bwapi4j.unit.SCV)

Example 5 with SCV

use of org.openbw.bwapi4j.unit.SCV in project Ecgberht by Jabbo16.

the class CheckMineralWalkGoldRush method execute.

@Override
public State execute() {
    try {
        if (gameState.walkingMinerals.isEmpty())
            return State.SUCCESS;
        for (Map.Entry<SCV, MutablePair<UnitType, TilePosition>> u : gameState.workerBuild.entrySet()) {
            if (u.getValue().first != UnitType.Terran_Command_Center)
                continue;
            SCV scv = u.getKey();
            Unit movingMineral = u.getKey().getTargetUnit();
            if (movingMineral == null) {
                MineralPatch target = getCloserMineral(u);
                if (target == null) {
                    if (scv.getOrderTarget() != null && scv.getOrder() != Order.Move) {
                        scv.move(u.getValue().second.toPosition());
                    }
                    continue;
                }
                if (!target.equals(scv.getTargetUnit()))
                    scv.rightClick(target, false);
            } else if (scv.getDistance(movingMineral) < 32) {
                scv.move(u.getValue().second.toPosition());
            }
        }
        return State.SUCCESS;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        e.printStackTrace();
        return State.ERROR;
    }
}
Also used : MutablePair(ecgberht.Util.MutablePair) MineralPatch(org.openbw.bwapi4j.unit.MineralPatch) SCV(org.openbw.bwapi4j.unit.SCV) Unit(org.openbw.bwapi4j.unit.Unit) Map(java.util.Map)

Aggregations

SCV (org.openbw.bwapi4j.unit.SCV)6 MineralPatch (org.openbw.bwapi4j.unit.MineralPatch)4 MutablePair (ecgberht.Util.MutablePair)3 Position (org.openbw.bwapi4j.Position)3 TilePosition (org.openbw.bwapi4j.TilePosition)3 Area (bwem.Area)2 Unit (org.openbw.bwapi4j.unit.Unit)2 Base (bwem.Base)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 PlayerUnit (org.openbw.bwapi4j.unit.PlayerUnit)1 Worker (org.openbw.bwapi4j.unit.Worker)1