Search in sources :

Example 1 with State

use of org.iaie.btree.BehavioralTree.State in project Ecgberht by Jabbo16.

the class CheckEnemyBaseVisible method execute.

@Override
public State execute() {
    try {
        List<PlayerUnit> enemies = gameState.getGame().getUnits(gameState.getIH().enemy());
        if (!enemies.isEmpty()) {
            for (UnitInfo u : gameState.unitStorage.getEnemyUnits().values().stream().filter(u -> u.unitType.isBuilding()).collect(Collectors.toSet())) {
                if (Util.broodWarDistance(gameState.chosenScout.getPosition(), u.lastPosition) <= 500) {
                    gameState.enemyMainBase = Util.getClosestBaseLocation(u.lastPosition);
                    gameState.scoutSLs = new HashSet<>();
                    if (!gameState.getStrat().name.equals("PlasmaWraithHell")) {
                        gameState.chosenHarasser = (Worker) gameState.chosenScout;
                    }
                    gameState.chosenScout = null;
                    Util.sendText("!");
                    gameState.playSound("gearthere.mp3");
                    if (gameState.enemyStartBase == null) {
                        gameState.enemyBLs.clear();
                        gameState.enemyBLs.addAll(gameState.BLs);
                        gameState.enemyBLs.sort(new BaseLocationComparator(gameState.enemyMainBase));
                        if (gameState.firstScout) {
                            gameState.enemyStartBase = gameState.enemyMainBase;
                            gameState.enemyMainArea = gameState.enemyStartBase.getArea();
                            gameState.enemyNaturalBase = gameState.enemyBLs.get(1);
                            gameState.enemyNaturalArea = gameState.enemyNaturalBase.getArea();
                        }
                    }
                    return State.SUCCESS;
                }
            }
        }
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        e.printStackTrace();
        return State.ERROR;
    }
}
Also used : HashSet(java.util.HashSet) List(java.util.List) Util(ecgberht.Util.Util) PlayerUnit(org.openbw.bwapi4j.unit.PlayerUnit) UnitInfo(ecgberht.UnitInfo) GameState(ecgberht.GameState) State(org.iaie.btree.BehavioralTree.State) Worker(org.openbw.bwapi4j.unit.Worker) Action(org.iaie.btree.task.leaf.Action) BaseLocationComparator(ecgberht.Util.BaseLocationComparator) Collectors(java.util.stream.Collectors) UnitInfo(ecgberht.UnitInfo) BaseLocationComparator(ecgberht.Util.BaseLocationComparator) PlayerUnit(org.openbw.bwapi4j.unit.PlayerUnit)

Example 2 with State

use of org.iaie.btree.BehavioralTree.State in project Ecgberht by Jabbo16.

the class CheckPerimeter method execute.

@Override
public State execute() {
    try {
        gameState.enemyInBase.clear();
        gameState.defense = false;
        Set<Unit> enemyInvaders = new TreeSet<>(gameState.enemyCombatUnitMemory);
        for (UnitInfo u : gameState.unitStorage.getEnemyUnits().values().stream().filter(u -> u.unitType.isBuilding()).collect(Collectors.toSet())) {
            if (u.unitType.canAttack() || u.unitType == UnitType.Protoss_Pylon || u.unitType.canProduce() || u.unitType.isRefinery()) {
                enemyInvaders.add(u.unit);
            }
        }
        for (Unit u : enemyInvaders) {
            UnitType uType = u.getType();
            if (u instanceof Building || ((uType.canAttack() || uType.isSpellcaster() || u instanceof Loadable) && uType != UnitType.Zerg_Scourge && uType != UnitType.Terran_Valkyrie && uType != UnitType.Protoss_Corsair && !(u instanceof Overlord))) {
                Area enemyArea = gameState.bwem.getMap().getArea(u.getTilePosition());
                if (enemyArea != null) {
                    Area myMainArea = gameState.mainCC != null ? gameState.mainCC.first.getArea() : null;
                    Area myNatArea = gameState.naturalArea;
                    for (Base b : gameState.CCs.keySet()) {
                        if (!b.getArea().equals(enemyArea))
                            continue;
                        if ((myMainArea != null && !b.getArea().equals(myMainArea) && (myNatArea != null && !b.getArea().equals(myNatArea))))
                            continue;
                        gameState.enemyInBase.add(u);
                        break;
                    }
                }
                for (Map.Entry<SCV, Building> c : gameState.workerTask.entrySet()) {
                    int dist = c.getValue() instanceof CommandCenter ? 500 : 200;
                    if (Util.broodWarDistance(u.getPosition(), c.getValue().getPosition()) <= dist) {
                        gameState.enemyInBase.add(u);
                        break;
                    }
                }
                for (Unit c : gameState.CCs.values()) {
                    if (Util.broodWarDistance(u.getPosition(), c.getPosition()) <= 500) {
                        gameState.enemyInBase.add(u);
                        break;
                    }
                }
                for (Unit c : gameState.DBs.keySet()) {
                    if (Util.broodWarDistance(u.getPosition(), c.getPosition()) <= 200) {
                        gameState.enemyInBase.add(u);
                        break;
                    }
                }
                for (Unit c : gameState.SBs) {
                    if (Util.broodWarDistance(u.getPosition(), c.getPosition()) <= 200) {
                        gameState.enemyInBase.add(u);
                        break;
                    }
                }
                for (ResearchingFacility c : gameState.UBs) {
                    if (Util.broodWarDistance(u.getPosition(), c.getPosition()) <= 200) {
                        gameState.enemyInBase.add(u);
                        break;
                    }
                }
                if (!gameState.getStrat().name.equals("ProxyBBS") && !gameState.getStrat().name.equals("ProxyEightRax")) {
                    for (Unit c : gameState.MBs) {
                        if (Util.broodWarDistance(u.getPosition(), c.getPosition()) <= 200) {
                            gameState.enemyInBase.add(u);
                            break;
                        }
                    }
                }
            }
        }
        if (!gameState.enemyInBase.isEmpty()) {
            /*if ((((GameState) gameState).getArmySize() >= 50 && ((GameState) gameState).getArmySize() / ((GameState) gameState).enemyInBase.size() > 10)) {
                    return State.FAILURE;
                }*/
            gameState.defense = true;
            return State.SUCCESS;
        }
        int cFrame = gameState.frameCount;
        List<Worker> toDelete = new ArrayList<>();
        for (Worker u : gameState.workerDefenders.keySet()) {
            if (u.getLastCommandFrame() == cFrame)
                continue;
            Position closestDefense;
            if (gameState.learningManager.isNaughty()) {
                if (!gameState.DBs.isEmpty()) {
                    closestDefense = gameState.DBs.keySet().iterator().next().getPosition();
                    u.move(closestDefense);
                    toDelete.add(u);
                    continue;
                }
            }
            closestDefense = gameState.getNearestCC(u.getPosition(), false);
            if (closestDefense != null) {
                u.move(closestDefense);
                toDelete.add(u);
            }
        }
        for (Worker u : toDelete) {
            u.stop(false);
            gameState.workerDefenders.remove(u);
            gameState.workerIdle.add(u);
        }
        for (Squad u : gameState.sqManager.squads.values()) {
            if (u.status == Status.DEFENSE) {
                Position closestCC = gameState.getNearestCC(u.getSquadCenter(), false);
                if (closestCC != null) {
                    Area squad = gameState.bwem.getMap().getArea(u.getSquadCenter().toTilePosition());
                    Area regCC = gameState.bwem.getMap().getArea(closestCC.toTilePosition());
                    if (squad != null && regCC != null) {
                        if (!squad.equals(regCC)) {
                            if (!gameState.DBs.isEmpty() && gameState.CCs.size() == 1) {
                                u.giveMoveOrder(gameState.DBs.keySet().iterator().next().getPosition());
                            } else {
                                u.giveMoveOrder(Util.getClosestChokepoint(u.getSquadCenter()).getCenter().toPosition());
                            }
                            u.status = Status.IDLE;
                            u.attack = null;
                            continue;
                        }
                    }
                    u.status = Status.IDLE;
                    u.attack = null;
                    continue;
                }
                u.status = Status.IDLE;
                u.attack = null;
            }
        }
        gameState.defense = false;
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        e.printStackTrace();
        return State.ERROR;
    }
}
Also used : java.util(java.util) Util(ecgberht.Util.Util) Area(bwem.Area) UnitInfo(ecgberht.UnitInfo) Squad(ecgberht.Squad) Collectors(java.util.stream.Collectors) Status(ecgberht.Squad.Status) Conditional(org.iaie.btree.task.leaf.Conditional) UnitType(org.openbw.bwapi4j.type.UnitType) org.openbw.bwapi4j.unit(org.openbw.bwapi4j.unit) GameState(ecgberht.GameState) Base(bwem.Base) State(org.iaie.btree.BehavioralTree.State) Position(org.openbw.bwapi4j.Position) Position(org.openbw.bwapi4j.Position) Base(bwem.Base) UnitInfo(ecgberht.UnitInfo) Area(bwem.Area) UnitType(org.openbw.bwapi4j.type.UnitType) Squad(ecgberht.Squad)

Example 3 with State

use of org.iaie.btree.BehavioralTree.State 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 State

use of org.iaie.btree.BehavioralTree.State in project Ecgberht by Jabbo16.

the class ChooseBuildingToHarass method execute.

@Override
public State execute() {
    try {
        if (gameState.chosenUnitToHarass != null)
            return State.FAILURE;
        for (UnitInfo u : gameState.unitStorage.getEnemyUnits().values().stream().filter(u -> u.unitType.isBuilding()).collect(Collectors.toSet())) {
            if (gameState.enemyMainBase != null && gameState.bwem.getMap().getArea(u.tileposition).equals(gameState.bwem.getMap().getArea(gameState.enemyMainBase.getLocation()))) {
                gameState.chosenUnitToHarass = u.unit;
                return State.SUCCESS;
            }
        }
        if (gameState.chosenHarasser.isIdle()) {
            gameState.workerIdle.add(gameState.chosenHarasser);
            gameState.chosenHarasser.stop(false);
            gameState.chosenHarasser = null;
            gameState.chosenUnitToHarass = null;
        }
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        e.printStackTrace();
        return State.ERROR;
    }
}
Also used : UnitInfo(ecgberht.UnitInfo) GameState(ecgberht.GameState) State(org.iaie.btree.BehavioralTree.State) Action(org.iaie.btree.task.leaf.Action) Collectors(java.util.stream.Collectors) UnitInfo(ecgberht.UnitInfo)

Aggregations

GameState (ecgberht.GameState)4 State (org.iaie.btree.BehavioralTree.State)4 UnitInfo (ecgberht.UnitInfo)3 Collectors (java.util.stream.Collectors)3 Action (org.iaie.btree.task.leaf.Action)3 Util (ecgberht.Util.Util)2 UnitType (org.openbw.bwapi4j.type.UnitType)2 Area (bwem.Area)1 Base (bwem.Base)1 Squad (ecgberht.Squad)1 Status (ecgberht.Squad.Status)1 BaseLocationComparator (ecgberht.Util.BaseLocationComparator)1 java.util (java.util)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Conditional (org.iaie.btree.task.leaf.Conditional)1 Position (org.openbw.bwapi4j.Position)1 org.openbw.bwapi4j.unit (org.openbw.bwapi4j.unit)1 Factory (org.openbw.bwapi4j.unit.Factory)1 MachineShop (org.openbw.bwapi4j.unit.MachineShop)1