Search in sources :

Example 6 with UnitType

use of org.openbw.bwapi4j.type.UnitType 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 7 with UnitType

use of org.openbw.bwapi4j.type.UnitType 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)

Aggregations

UnitType (org.openbw.bwapi4j.type.UnitType)7 TilePosition (org.openbw.bwapi4j.TilePosition)6 Position (org.openbw.bwapi4j.Position)3 Building (org.openbw.bwapi4j.unit.Building)3 Barracks (org.openbw.bwapi4j.unit.Barracks)2 Worker (org.openbw.bwapi4j.unit.Worker)2 Area (bwem.Area)1 Base (bwem.Base)1 GameState (ecgberht.GameState)1 Squad (ecgberht.Squad)1 Status (ecgberht.Squad.Status)1 UnitInfo (ecgberht.UnitInfo)1 Util (ecgberht.Util.Util)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 State (org.iaie.btree.BehavioralTree.State)1 Conditional (org.iaie.btree.task.leaf.Conditional)1 org.openbw.bwapi4j.unit (org.openbw.bwapi4j.unit)1 CommandCenter (org.openbw.bwapi4j.unit.CommandCenter)1 Factory (org.openbw.bwapi4j.unit.Factory)1