Search in sources :

Example 1 with Factory

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

the class ChooseGoliath method execute.

@Override
public State execute() {
    try {
        if (gameState.UBs.stream().filter(unit -> unit instanceof Armory).count() < 1)
            return State.FAILURE;
        int count = 0;
        for (Unit u : gameState.getGame().getUnits(gameState.getPlayer())) {
            if (!u.exists())
                continue;
            if (u.getType() == UnitType.Terran_Goliath)
                count++;
            if (count >= gameState.maxGoliaths)
                return State.FAILURE;
        }
        if (!gameState.Fs.isEmpty()) {
            for (Factory b : gameState.Fs) {
                if (!b.isTraining() && b.canTrain(UnitType.Terran_Goliath)) {
                    gameState.chosenUnit = UnitType.Terran_Goliath;
                    gameState.chosenTrainingFacility = b;
                    return State.SUCCESS;
                }
            }
        }
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        e.printStackTrace();
        return State.ERROR;
    }
}
Also used : Factory(org.openbw.bwapi4j.unit.Factory) Unit(org.openbw.bwapi4j.unit.Unit) Armory(org.openbw.bwapi4j.unit.Armory)

Example 2 with Factory

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

the class ChooseTank method execute.

@Override
public State execute() {
    try {
        if (!gameState.Fs.isEmpty()) {
            if (gameState.getStrat().trainUnits.contains(UnitType.Terran_Wraith) && gameState.maxWraiths - Util.countUnitTypeSelf(UnitType.Terran_Wraith) > 0 && Math.random() * 10 <= 1) {
                return State.FAILURE;
            }
            int multiplier = 2;
            String strat = gameState.getStrat().name;
            if (strat.equals("JoyORush") && gameState.tanksTrained == 3 && Util.countUnitTypeSelf(UnitType.Terran_Siege_Tank_Tank_Mode) == 3)
                return State.FAILURE;
            if (strat.equals("FullMech") || strat.equals("MechGreedyFE"))
                multiplier = 15;
            if (Util.countUnitTypeSelf(UnitType.Terran_Siege_Tank_Siege_Mode) + Util.countUnitTypeSelf(UnitType.Terran_Siege_Tank_Tank_Mode) < Util.countUnitTypeSelf(UnitType.Terran_Marine) * multiplier) {
                MutablePair<Integer, Integer> cash = gameState.getCash();
                if (cash.second < (UnitType.Terran_Siege_Tank_Tank_Mode.gasPrice()))
                    return State.FAILURE;
                for (Factory b : gameState.Fs) {
                    if (!b.isTraining() && b.canTrain(UnitType.Terran_Siege_Tank_Tank_Mode)) {
                        gameState.chosenUnit = UnitType.Terran_Siege_Tank_Tank_Mode;
                        gameState.chosenTrainingFacility = b;
                        return State.SUCCESS;
                    }
                }
            }
        }
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        e.printStackTrace();
        return State.ERROR;
    }
}
Also used : Factory(org.openbw.bwapi4j.unit.Factory)

Example 3 with Factory

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

the class ChooseMachineShop method execute.

@Override
public State execute() {
    try {
        if (gameState.getStrat().name.equals("VultureRush") && (gameState.Fs.size() < 2 || gameState.UBs.stream().anyMatch(u -> u instanceof MachineShop)))
            return State.FAILURE;
        if (gameState.getStrat().name.equals("TheNitekat") && (gameState.Fs.size() > 1 || gameState.UBs.stream().anyMatch(u -> u instanceof MachineShop)))
            return State.FAILURE;
        if (!gameState.Fs.isEmpty()) {
            for (Factory c : gameState.Fs) {
                if (!c.isTraining() && c.getAddon() == null) {
                    gameState.chosenBuildingAddon = c;
                    gameState.chosenAddon = UnitType.Terran_Machine_Shop;
                    return State.SUCCESS;
                }
            }
        }
        gameState.chosenBuildingAddon = null;
        gameState.chosenAddon = null;
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        e.printStackTrace();
        return State.ERROR;
    }
}
Also used : MachineShop(org.openbw.bwapi4j.unit.MachineShop) UnitType(org.openbw.bwapi4j.type.UnitType) GameState(ecgberht.GameState) State(org.iaie.btree.BehavioralTree.State) Action(org.iaie.btree.task.leaf.Action) Factory(org.openbw.bwapi4j.unit.Factory) MachineShop(org.openbw.bwapi4j.unit.MachineShop) Factory(org.openbw.bwapi4j.unit.Factory)

Example 4 with Factory

use of org.openbw.bwapi4j.unit.Factory 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 5 with Factory

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

the class ChooseVulture method execute.

@Override
public State execute() {
    try {
        if (!gameState.Fs.isEmpty()) {
            if (gameState.getStrat().name.equals("VultureRush") || Util.countUnitTypeSelf(UnitType.Terran_Vulture) * 2 <= Util.countUnitTypeSelf(UnitType.Terran_Siege_Tank_Siege_Mode) + Util.countUnitTypeSelf(UnitType.Terran_Siege_Tank_Tank_Mode) + 2) {
                for (Factory b : gameState.Fs) {
                    if (!b.isTraining() && b.canTrain(UnitType.Terran_Vulture)) {
                        gameState.chosenUnit = UnitType.Terran_Vulture;
                        gameState.chosenTrainingFacility = b;
                        return State.SUCCESS;
                    }
                }
            }
        }
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        e.printStackTrace();
        return State.ERROR;
    }
}
Also used : Factory(org.openbw.bwapi4j.unit.Factory)

Aggregations

Factory (org.openbw.bwapi4j.unit.Factory)5 UnitType (org.openbw.bwapi4j.type.UnitType)2 GameState (ecgberht.GameState)1 State (org.iaie.btree.BehavioralTree.State)1 Action (org.iaie.btree.task.leaf.Action)1 TilePosition (org.openbw.bwapi4j.TilePosition)1 Armory (org.openbw.bwapi4j.unit.Armory)1 Barracks (org.openbw.bwapi4j.unit.Barracks)1 Building (org.openbw.bwapi4j.unit.Building)1 MachineShop (org.openbw.bwapi4j.unit.MachineShop)1 Unit (org.openbw.bwapi4j.unit.Unit)1