Search in sources :

Example 1 with Building

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

the class ChooseExpand method execute.

@Override
public State execute() {
    try {
        String strat = gameState.getStrat().name;
        if (strat.equals("ProxyBBS") || strat.equals("ProxyEightRax") || ((strat.equals("JoyORush") || strat.equals("TheNitekat")) && gameState.getCash().first <= 550))
            return State.FAILURE;
        if (strat.equals("FullMech") && (gameState.myArmy.stream().noneMatch(u -> u.unit instanceof SiegeTank) || !gameState.getPlayer().hasResearched(TechType.Tank_Siege_Mode)) && gameState.firstExpand)
            return State.FAILURE;
        for (MutablePair<UnitType, TilePosition> w : gameState.workerBuild.values()) {
            if (w.first == UnitType.Terran_Command_Center)
                return State.FAILURE;
        }
        for (Building w : gameState.workerTask.values()) {
            if (w instanceof CommandCenter)
                return State.FAILURE;
        }
        if (strat.equals("PlasmaWraithHell") && Util.countUnitTypeSelf(UnitType.Terran_Command_Center) > 2) {
            return State.FAILURE;
        }
        if (gameState.iReallyWantToExpand || (gameState.getCash().first >= 550 && gameState.getArmySize() >= gameState.getStrat().armyForExpand) || (strat.equals("14CC") && gameState.supplyMan.getSupplyUsed() == 28)) {
            gameState.chosenToBuild = UnitType.Terran_Command_Center;
            return State.SUCCESS;
        }
        if ((strat.equals("BioGreedyFE") || strat.equals("MechGreedyFE") || strat.equals("BioMechGreedyFE") || strat.equals("PlasmaWraithHell")) && !gameState.MBs.isEmpty() && gameState.CCs.size() == 1) {
            gameState.chosenToBuild = UnitType.Terran_Command_Center;
            return State.SUCCESS;
        }
        int workers = gameState.workerIdle.size();
        for (Integer wt : gameState.mineralsAssigned.values()) workers += wt;
        if (gameState.mineralsAssigned.size() * 2 <= workers - 1 && gameState.getArmySize() >= gameState.getStrat().armyForExpand) {
            gameState.chosenToBuild = UnitType.Terran_Command_Center;
            return State.SUCCESS;
        }
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        e.printStackTrace();
        return State.ERROR;
    }
}
Also used : Building(org.openbw.bwapi4j.unit.Building) UnitType(org.openbw.bwapi4j.type.UnitType) TilePosition(org.openbw.bwapi4j.TilePosition) CommandCenter(org.openbw.bwapi4j.unit.CommandCenter) SiegeTank(org.openbw.bwapi4j.unit.SiegeTank)

Example 2 with Building

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

the class ChooseBarracks method execute.

@Override
public State execute() {
    try {
        String strat = gameState.getStrat().name;
        if ((strat.equals("BioGreedyFE") || strat.equals("MechGreedyFE") || strat.equals("BioMechGreedyFE")) && Util.countBuildingAll(UnitType.Terran_Command_Center) == 1 && Util.countBuildingAll(UnitType.Terran_Barracks) > 1 && gameState.frameCount <= 24 * 240) {
            return State.FAILURE;
        }
        if (strat.equals("14CC") && Util.countBuildingAll(UnitType.Terran_Command_Center) < 2)
            return State.FAILURE;
        if (!gameState.getStrat().techToResearch.contains(TechType.Stim_Packs) && gameState.getStrat().raxPerCC == 1 && gameState.MBs.size() > 0) {
            return State.FAILURE;
        }
        if (gameState.learningManager.isNaughty() && gameState.enemyRace == Race.Zerg && Util.countBuildingAll(UnitType.Terran_Barracks) == 1 && Util.countBuildingAll(UnitType.Terran_Bunker) < 1) {
            return State.FAILURE;
        }
        if (!strat.equals("ProxyBBS") && !strat.equals("ProxyEightRax")) {
            if (!gameState.MBs.isEmpty() && Util.countBuildingAll(UnitType.Terran_Barracks) == gameState.getStrat().numRaxForAca && Util.countBuildingAll(UnitType.Terran_Academy) == 0) {
                return State.FAILURE;
            }
            if (Util.countBuildingAll(UnitType.Terran_Barracks) == gameState.getStrat().numRaxForAca && Util.countBuildingAll(UnitType.Terran_Refinery) == 0) {
                return State.FAILURE;
            }
        } else if (gameState.getPlayer().supplyUsed() < 16)
            return State.FAILURE;
        if (gameState.getStrat().buildUnits.contains(UnitType.Terran_Factory)) {
            int count = 0;
            boolean found = false;
            for (MutablePair<UnitType, TilePosition> w : gameState.workerBuild.values()) {
                if (w.first == UnitType.Terran_Barracks)
                    count++;
                if (w.first == UnitType.Terran_Factory)
                    found = true;
            }
            for (Building w : gameState.workerTask.values()) {
                if (w instanceof Barracks)
                    count++;
                if (w instanceof Factory)
                    found = true;
            }
            if (!gameState.Fs.isEmpty())
                found = true;
            if (count + gameState.MBs.size() > gameState.getStrat().numRaxForFac && !found)
                return State.FAILURE;
        }
        if (Util.countBuildingAll(UnitType.Terran_Academy) == 0 && Util.countBuildingAll(UnitType.Terran_Barracks) >= 2) {
            return State.FAILURE;
        }
        if (Util.countBuildingAll(UnitType.Terran_Barracks) == gameState.MBs.size() && gameState.getPlayer().minerals() >= 600) {
            gameState.chosenToBuild = UnitType.Terran_Barracks;
            return State.SUCCESS;
        }
        if (Util.countBuildingAll(UnitType.Terran_Barracks) < gameState.getStrat().raxPerCC * Util.getNumberCCs()) {
            gameState.chosenToBuild = UnitType.Terran_Barracks;
            return State.SUCCESS;
        }
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        e.printStackTrace();
        return State.ERROR;
    }
}
Also used : Building(org.openbw.bwapi4j.unit.Building) UnitType(org.openbw.bwapi4j.type.UnitType) TilePosition(org.openbw.bwapi4j.TilePosition) Factory(org.openbw.bwapi4j.unit.Factory) Barracks(org.openbw.bwapi4j.unit.Barracks)

Example 3 with Building

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

the class ChooseRefinery method execute.

@Override
public State execute() {
    try {
        String strat = gameState.getStrat().name;
        if (gameState.getPlayer().supplyUsed() < gameState.getStrat().supplyForFirstRefinery || gameState.getCash().second >= 300) {
            return State.FAILURE;
        }
        if ((strat.equals("BioGreedyFE") || strat.equals("FullBio") || strat.equals("FullBioFE")) && gameState.getCash().second >= 150) {
            return State.FAILURE;
        }
        if (gameState.getStrat().techToResearch.contains(TechType.Tank_Siege_Mode) && gameState.getCash().second >= 250) {
            return State.FAILURE;
        }
        if (gameState.refineriesAssigned.size() == 1) {
            boolean found = false;
            for (MutablePair<UnitType, TilePosition> w : gameState.workerBuild.values()) {
                if (w.first == UnitType.Terran_Barracks) {
                    found = true;
                    break;
                }
            }
            for (Building w : gameState.workerTask.values()) {
                if (w instanceof Barracks) {
                    found = true;
                    break;
                }
            }
            if (gameState.MBs.isEmpty() && !found)
                return State.FAILURE;
        }
        int count = 0;
        VespeneGeyser geyser = null;
        for (Entry<VespeneGeyser, Boolean> r : gameState.vespeneGeysers.entrySet()) {
            if (r.getValue()) {
                count++;
            } else
                geyser = r.getKey();
        }
        if (count == gameState.vespeneGeysers.size())
            return State.FAILURE;
        for (MutablePair<UnitType, TilePosition> w : gameState.workerBuild.values()) {
            if (w.first == UnitType.Terran_Refinery)
                return State.FAILURE;
        }
        for (Building w : gameState.workerTask.values()) {
            if (w instanceof Refinery && geyser != null && w.getTilePosition().equals(geyser.getTilePosition()))
                return State.FAILURE;
        }
        if ((strat.equals("BioGreedyFE") || strat.equals("MechGreedyFE") || strat.equals("BioMechGreedyFE")) && !gameState.refineriesAssigned.isEmpty() && Util.getNumberCCs() <= 2 && Util.countUnitTypeSelf(UnitType.Terran_SCV) < 30) {
            return State.FAILURE;
        }
        gameState.chosenToBuild = UnitType.Terran_Refinery;
        return State.SUCCESS;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        e.printStackTrace();
        return State.ERROR;
    }
}
Also used : Building(org.openbw.bwapi4j.unit.Building) VespeneGeyser(org.openbw.bwapi4j.unit.VespeneGeyser) Refinery(org.openbw.bwapi4j.unit.Refinery) Barracks(org.openbw.bwapi4j.unit.Barracks) UnitType(org.openbw.bwapi4j.type.UnitType) TilePosition(org.openbw.bwapi4j.TilePosition)

Example 4 with Building

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

the class CheckHarasserAttacked method execute.

@Override
public State execute() {
    try {
        if (gameState.enemyMainBase == null) {
            gameState.chosenUnitToHarass = null;
            gameState.chosenHarasser = null;
            return State.FAILURE;
        }
        if (gameState.chosenUnitToHarass != null) {
            if (!gameState.bw.getBWMap().isValidPosition(gameState.chosenUnitToHarass.getPosition())) {
                gameState.chosenUnitToHarass = null;
            }
        }
        UnitInfo attacker = null;
        int workers = 0;
        Set<UnitInfo> attackers = new TreeSet<>();
        // Thanks to @N00byEdge for cleaner code
        for (UnitInfo u : gameState.unitStorage.getAllyUnits().get(gameState.chosenHarasser).attackers) {
            if (!(u.unit instanceof Building) && u.unit instanceof Attacker && u.unit.exists()) {
                if (u.unit instanceof Worker) {
                    workers++;
                    attacker = u;
                }
                attackers.add(u);
            }
        }
        if (workers > 1) {
            gameState.learningManager.setHarass(true);
            gameState.chosenUnitToHarass = null;
            return State.FAILURE;
        }
        if (attackers.isEmpty()) {
            if (!gameState.getGame().getBWMap().isVisible(gameState.enemyMainBase.getLocation()) && gameState.chosenUnitToHarass == null) {
                gameState.chosenHarasser.move(gameState.enemyMainBase.getLocation().toPosition());
            }
            return State.SUCCESS;
        } else {
            boolean winHarass = gameState.sim.simulateHarass(gameState.chosenHarasser, attackers, 70);
            if (winHarass) {
                if (workers == 1 && !attacker.unit.equals(gameState.chosenUnitToHarass)) {
                    UtilMicro.attack(gameState.chosenHarasser, attacker);
                    gameState.chosenUnitToHarass = attacker.unit;
                    return State.SUCCESS;
                }
            } else {
                if (IntelligenceAgency.getEnemyStrat() == IntelligenceAgency.EnemyStrats.Unknown) {
                    gameState.explore = true;
                    gameState.chosenUnitToHarass = null;
                    gameState.chosenHarasser.stop(false);
                    return State.FAILURE;
                } else if (gameState.chosenHarasser.getHitPoints() <= 15) {
                    gameState.workerIdle.add(gameState.chosenHarasser);
                    gameState.chosenHarasser.stop(false);
                    gameState.chosenHarasser = null;
                    gameState.chosenUnitToHarass = null;
                } else {
                    // Position kite = UtilMicro.kiteAway(gameState.chosenHarasser, attackers);
                    Optional<UnitInfo> closestUnit = attackers.stream().min(Comparator.comparing(u -> u.getDistance(gameState.chosenHarasser)));
                    Position kite = closestUnit.map(unit1 -> UtilMicro.kiteAwayAlt(gameState.chosenHarasser.getPosition(), unit1.position)).orElse(null);
                    if (kite != null && gameState.bw.getBWMap().isValidPosition(kite)) {
                        UtilMicro.move(gameState.chosenHarasser, kite);
                        gameState.chosenUnitToHarass = null;
                    } else {
                        kite = UtilMicro.kiteAway(gameState.chosenHarasser, attackers);
                        if (kite != null && gameState.bw.getBWMap().isValidPosition(kite)) {
                            UtilMicro.move(gameState.chosenHarasser, kite);
                            gameState.chosenUnitToHarass = null;
                        }
                    }
                }
                return State.FAILURE;
            }
        }
        return State.SUCCESS;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        e.printStackTrace();
        return State.ERROR;
    }
}
Also used : Building(org.openbw.bwapi4j.unit.Building) UnitInfo(ecgberht.UnitInfo) Attacker(org.openbw.bwapi4j.unit.Attacker) Optional(java.util.Optional) Position(org.openbw.bwapi4j.Position) TreeSet(java.util.TreeSet) Worker(org.openbw.bwapi4j.unit.Worker)

Aggregations

Building (org.openbw.bwapi4j.unit.Building)4 TilePosition (org.openbw.bwapi4j.TilePosition)3 UnitType (org.openbw.bwapi4j.type.UnitType)3 Barracks (org.openbw.bwapi4j.unit.Barracks)2 UnitInfo (ecgberht.UnitInfo)1 Optional (java.util.Optional)1 TreeSet (java.util.TreeSet)1 Position (org.openbw.bwapi4j.Position)1 Attacker (org.openbw.bwapi4j.unit.Attacker)1 CommandCenter (org.openbw.bwapi4j.unit.CommandCenter)1 Factory (org.openbw.bwapi4j.unit.Factory)1 Refinery (org.openbw.bwapi4j.unit.Refinery)1 SiegeTank (org.openbw.bwapi4j.unit.SiegeTank)1 VespeneGeyser (org.openbw.bwapi4j.unit.VespeneGeyser)1 Worker (org.openbw.bwapi4j.unit.Worker)1