Search in sources :

Example 1 with Squad

use of ecgberht.Squad in project Ecgberht by Jabbo16.

the class CheckPerimeter method execute.

@Override
public State execute() {
    try {
        ((GameState) this.handler).enemyInBase.clear();
        ((GameState) this.handler).defense = false;
        List<Unit> enemyInvaders = new ArrayList<>();
        enemyInvaders.addAll(((GameState) this.handler).enemyCombatUnitMemory);
        for (EnemyBuilding u : ((GameState) this.handler).enemyBuildingMemory.values()) {
            if (u.type.canAttack() || u.type == UnitType.Protoss_Pylon || u.type.canProduce() || u.type.isRefinery()) {
                enemyInvaders.add(u.unit);
            }
        }
        for (Unit u : enemyInvaders) {
            if ((u.getType().canAttack() || u.getType() == UnitType.Protoss_Pylon) && u.getType() != UnitType.Zerg_Scourge && u.getType() != UnitType.Protoss_Corsair) {
                for (Unit c : ((GameState) this.handler).CCs.values()) {
                    if (((GameState) this.handler).broodWarDistance(u.getPosition(), c.getPosition()) < 500) {
                        ((GameState) this.handler).enemyInBase.add(u);
                        continue;
                    }
                }
                for (Unit c : ((GameState) this.handler).DBs.keySet()) {
                    if (((GameState) this.handler).broodWarDistance(u.getPosition(), c.getPosition()) < 200) {
                        ((GameState) this.handler).enemyInBase.add(u);
                        continue;
                    }
                }
                for (Unit c : ((GameState) this.handler).SBs) {
                    if (((GameState) this.handler).broodWarDistance(u.getPosition(), c.getPosition()) < 200) {
                        ((GameState) this.handler).enemyInBase.add(u);
                        continue;
                    }
                }
                for (Unit c : ((GameState) this.handler).MBs) {
                    if (((GameState) this.handler).broodWarDistance(u.getPosition(), c.getPosition()) < 200) {
                        ((GameState) this.handler).enemyInBase.add(u);
                        continue;
                    }
                }
            }
        }
        boolean overlordCheck = true;
        for (Unit u : ((GameState) this.handler).enemyInBase) {
            if (u.getType().canAttack() || u.getType() == UnitType.Protoss_Shuttle || u.getType() == UnitType.Terran_Dropship) {
                overlordCheck = false;
                break;
            }
        }
        if (!((GameState) this.handler).enemyInBase.isEmpty() && !overlordCheck) {
            if ((((GameState) this.handler).getArmySize() >= 50 && ((GameState) this.handler).getArmySize() / ((GameState) this.handler).enemyInBase.size() > 10)) {
                return State.FAILURE;
            }
            ((GameState) this.handler).defense = true;
            return State.SUCCESS;
        }
        int cFrame = ((GameState) this.handler).frameCount;
        for (Unit u : ((GameState) this.handler).workerDefenders) {
            if (u.getLastCommandFrame() == cFrame) {
                continue;
            }
            Position closestCC = ((GameState) this.handler).getNearestCC(u.getPosition());
            if (closestCC != null) {
                if (!BWTA.getRegion(u.getPosition()).getCenter().equals(BWTA.getRegion(closestCC).getCenter())) {
                    u.move(closestCC);
                }
            }
        }
        for (Squad u : ((GameState) this.handler).squads.values()) {
            if (u.status == Status.DEFENSE) {
                Position closestCC = ((GameState) this.handler).getNearestCC(((GameState) this.handler).getSquadCenter(u));
                if (closestCC != null) {
                    Region squad = BWTA.getRegion(((GameState) this.handler).getSquadCenter(u));
                    Region regCC = BWTA.getRegion(closestCC);
                    if (squad != null && regCC != null) {
                        if (!squad.getCenter().equals(regCC.getCenter())) {
                            if (!((GameState) this.handler).DBs.isEmpty() && ((GameState) this.handler).CCs.size() == 1) {
                                u.giveMoveOrder(((GameState) this.handler).DBs.keySet().iterator().next().getPosition());
                            } else {
                                u.giveMoveOrder(BWTA.getNearestChokepoint(((GameState) this.handler).getSquadCenter(u)).getCenter());
                            }
                            u.status = Status.IDLE;
                            u.attack = Position.None;
                            continue;
                        }
                    }
                    u.status = Status.IDLE;
                    u.attack = Position.None;
                    continue;
                }
                u.status = Status.IDLE;
                u.attack = Position.None;
                continue;
            }
        }
        ((GameState) this.handler).defense = false;
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        System.err.println(e);
        return State.ERROR;
    }
}
Also used : Position(bwapi.Position) ArrayList(java.util.ArrayList) Region(bwta.Region) GameState(ecgberht.GameState) Unit(bwapi.Unit) Squad(ecgberht.Squad) EnemyBuilding(ecgberht.EnemyBuilding)

Example 2 with Squad

use of ecgberht.Squad in project Ecgberht by Jabbo16.

the class ChooseScout method execute.

@Override
public State execute() {
    try {
        if (gameState.getStrat().name.equals("PlasmaWraithHell")) {
            for (Squad s : gameState.sqManager.squads.values()) {
                for (UnitInfo u : s.members) {
                    if (u.unit instanceof Wraith) {
                        gameState.chosenScout = (MobileUnit) u.unit;
                        s.members.remove(u);
                        return State.SUCCESS;
                    }
                }
            }
        }
        if (!gameState.workerIdle.isEmpty()) {
            Worker chosen = gameState.workerIdle.iterator().next();
            gameState.chosenScout = chosen;
            gameState.workerIdle.remove(chosen);
        }
        if (gameState.chosenScout == null) {
            for (Worker u : gameState.workerMining.keySet()) {
                if (!u.isCarryingMinerals()) {
                    gameState.chosenScout = u;
                    MineralPatch mineral = gameState.workerMining.get(u);
                    if (gameState.mineralsAssigned.containsKey(mineral)) {
                        gameState.mining--;
                        gameState.mineralsAssigned.put(mineral, gameState.mineralsAssigned.get(mineral) - 1);
                    }
                    gameState.workerMining.remove(u);
                    break;
                }
            }
        }
        if (gameState.chosenScout != null)
            return State.SUCCESS;
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        e.printStackTrace();
        return State.ERROR;
    }
}
Also used : UnitInfo(ecgberht.UnitInfo) MineralPatch(org.openbw.bwapi4j.unit.MineralPatch) Worker(org.openbw.bwapi4j.unit.Worker) Squad(ecgberht.Squad) Wraith(org.openbw.bwapi4j.unit.Wraith)

Example 3 with Squad

use of ecgberht.Squad in project Ecgberht by Jabbo16.

the class CheckBuildingFlames method execute.

@Override
public State execute() {
    try {
        List<SCV> toRemove = new ArrayList<>();
        for (Entry<SCV, Mechanical> u : gameState.repairerTask.entrySet()) {
            if (u.getValue().maxHitPoints() != u.getValue().getHitPoints()) {
                if (u.getKey().getOrder() != Order.Follow && u.getKey().getOrder() != Order.Repair) {
                    u.getKey().rightClick(u.getValue(), false);
                }
            } else if (Util.countBuildingAll(UnitType.Terran_Command_Center) < 2 && u.getValue() instanceof Bunker && IntelligenceAgency.getEnemyStrat() == IntelligenceAgency.EnemyStrats.ZealotRush && gameState.frameCount >= 24 * 60 * 2.2) {
                if (u.getKey().getDistance(u.getValue()) > 3 * 32)
                    u.getKey().move(u.getValue().getPosition());
            } else if (Util.countBuildingAll(UnitType.Terran_Command_Center) == 2 && gameState.CCs.size() < 2 && u.getValue() instanceof Bunker) {
                if (u.getKey().getDistance(u.getValue()) > 3 * 32)
                    u.getKey().move(u.getValue().getPosition());
            } else {
                u.getKey().stop(false);
                gameState.workerIdle.add(u.getKey());
                toRemove.add(u.getKey());
            }
        }
        for (SCV s : toRemove) gameState.repairerTask.remove(s);
        boolean isBeingRepaired;
        boolean cheesed = IntelligenceAgency.getEnemyStrat() == IntelligenceAgency.EnemyStrats.ZealotRush && gameState.frameCount >= 24 * 60 * 2.2;
        boolean fastExpanding = gameState.getStrat().name.contains("GreedyFE") && Util.countBuildingAll(UnitType.Terran_Command_Center) == 2 && gameState.CCs.size() < 2 && gameState.firstExpand;
        for (Bunker w : gameState.DBs.keySet()) {
            int count = 0;
            if (UnitType.Terran_Bunker.maxHitPoints() != w.getHitPoints() || (cheesed && Util.countBuildingAll(UnitType.Terran_Command_Center) < 2) || fastExpanding) {
                for (Mechanical r : gameState.repairerTask.values()) {
                    if (w.equals(r))
                        count++;
                }
                if (count < 2 && (gameState.defense || cheesed || fastExpanding)) {
                    gameState.chosenUnitRepair = w;
                    return State.SUCCESS;
                }
                if (count == 0) {
                    gameState.chosenUnitRepair = w;
                    return State.SUCCESS;
                }
            }
        }
        isBeingRepaired = false;
        for (MissileTurret b : gameState.Ts) {
            if (UnitType.Terran_Missile_Turret.maxHitPoints() != b.getHitPoints()) {
                for (Mechanical r : gameState.repairerTask.values()) {
                    if (b.equals(r)) {
                        // TODO check to add break?
                        isBeingRepaired = true;
                    }
                }
                if (!isBeingRepaired) {
                    gameState.chosenUnitRepair = b;
                    return State.SUCCESS;
                }
            }
        }
        isBeingRepaired = false;
        for (Squad s : gameState.sqManager.squads.values()) {
            if (s.status != Squad.Status.IDLE)
                continue;
            for (UnitInfo u : s.members) {
                if (u.unit instanceof Mechanical && u.health != u.unitType.maxHitPoints()) {
                    Area unitArea = gameState.bwem.getMap().getArea(u.tileposition);
                    for (Base b : gameState.CCs.keySet()) {
                        if (unitArea != null && b.getArea().equals(unitArea)) {
                            for (Mechanical r : gameState.repairerTask.values()) {
                                if (u.unit.equals(r)) {
                                    isBeingRepaired = true;
                                }
                            }
                            if (!isBeingRepaired) {
                                gameState.chosenUnitRepair = (Mechanical) u.unit;
                                return State.SUCCESS;
                            }
                        }
                    }
                }
            }
        }
        if (!gameState.getStrat().proxy) {
            isBeingRepaired = false;
            for (Barracks b : gameState.MBs) {
                if (UnitType.Terran_Barracks.maxHitPoints() != b.getHitPoints()) {
                    for (Mechanical r : gameState.repairerTask.values()) {
                        if (b.equals(r)) {
                            isBeingRepaired = true;
                        }
                    }
                    if (!isBeingRepaired) {
                        gameState.chosenUnitRepair = b;
                        return State.SUCCESS;
                    }
                }
            }
        }
        isBeingRepaired = false;
        for (Factory b : gameState.Fs) {
            if (b.equals(gameState.proxyBuilding))
                continue;
            if (UnitType.Terran_Factory.maxHitPoints() != b.getHitPoints()) {
                for (Mechanical r : gameState.repairerTask.values()) {
                    if (b.equals(r)) {
                        isBeingRepaired = true;
                    }
                }
                if (!isBeingRepaired) {
                    gameState.chosenUnitRepair = b;
                    return State.SUCCESS;
                }
            }
        }
        isBeingRepaired = false;
        for (ResearchingFacility b : gameState.UBs) {
            if (b.getType().maxHitPoints() != b.getHitPoints()) {
                for (Mechanical r : gameState.repairerTask.values()) {
                    if (b.equals(r)) {
                        isBeingRepaired = true;
                    }
                }
                if (!isBeingRepaired) {
                    gameState.chosenUnitRepair = (Mechanical) b;
                    return State.SUCCESS;
                }
            }
        }
        isBeingRepaired = false;
        for (SupplyDepot b : gameState.SBs) {
            if (UnitType.Terran_Supply_Depot.maxHitPoints() != b.getHitPoints()) {
                for (Mechanical r : gameState.repairerTask.values()) {
                    if (b.equals(r)) {
                        isBeingRepaired = true;
                    }
                }
                if (!isBeingRepaired) {
                    gameState.chosenUnitRepair = b;
                    return State.SUCCESS;
                }
            }
        }
        isBeingRepaired = false;
        for (CommandCenter b : gameState.CCs.values()) {
            if (UnitType.Terran_Command_Center.maxHitPoints() != b.getHitPoints()) {
                for (Mechanical r : gameState.repairerTask.values()) {
                    if (b.equals(r)) {
                        isBeingRepaired = true;
                    }
                }
                if (!isBeingRepaired) {
                    gameState.chosenUnitRepair = b;
                    return State.SUCCESS;
                }
            }
        }
        isBeingRepaired = false;
        for (ComsatStation b : gameState.CSs) {
            if (UnitType.Terran_Comsat_Station.maxHitPoints() != b.getHitPoints()) {
                for (Mechanical r : gameState.repairerTask.values()) {
                    if (b.equals(r)) {
                        isBeingRepaired = true;
                    }
                }
                if (!isBeingRepaired) {
                    gameState.chosenUnitRepair = b;
                    return State.SUCCESS;
                }
            }
        }
        isBeingRepaired = false;
        for (Starport b : gameState.Ps) {
            if (UnitType.Terran_Starport.maxHitPoints() != b.getHitPoints()) {
                for (Mechanical r : gameState.repairerTask.values()) {
                    if (b.equals(r)) {
                        isBeingRepaired = true;
                    }
                }
                if (!isBeingRepaired) {
                    gameState.chosenUnitRepair = b;
                    return State.SUCCESS;
                }
            }
        }
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        e.printStackTrace();
        return State.ERROR;
    }
}
Also used : ArrayList(java.util.ArrayList) Base(bwem.Base) UnitInfo(ecgberht.UnitInfo) Area(bwem.Area) Squad(ecgberht.Squad)

Example 4 with Squad

use of ecgberht.Squad in project Ecgberht by Jabbo16.

the class SendDefenders method execute.

@Override
public State execute() {
    try {
        boolean air_only = true;
        boolean cannon_rush = false;
        for (Unit u : ((GameState) this.handler).enemyInBase) {
            if (u.isFlying() || u.isCloaked()) {
                continue;
            }
            if (!cannon_rush) {
                if (u.getType() == UnitType.Protoss_Pylon || u.getType() == UnitType.Protoss_Photon_Cannon) {
                    cannon_rush = true;
                }
            }
            air_only = false;
        }
        Set<Unit> friends = new HashSet<Unit>();
        for (Squad s : ((GameState) this.handler).squads.values()) {
            for (Unit u : s.members) {
                friends.add(u);
            }
        }
        boolean bunker = false;
        if (!((GameState) this.handler).DBs.isEmpty()) {
            for (Unit u : ((GameState) this.handler).DBs.keySet()) {
                friends.add(u);
            }
            bunker = true;
        }
        int defenders = 6;
        Iterator<Unit> it = ((GameState) this.handler).enemyInBase.iterator();
        if (((GameState) this.handler).enemyInBase.size() == 1 && it.next().getType().isWorker()) {
            defenders = 1;
        }
        Pair<Boolean, Boolean> battleWin = new Pair<>(true, false);
        if (defenders != 1) {
            if (((GameState) this.handler).enemyInBase.size() + friends.size() < 25) {
                battleWin = ((GameState) this.handler).simulateDefenseBattle(friends, ((GameState) this.handler).enemyInBase, 150, bunker);
            }
            if (((GameState) this.handler).enemyInBase.size() >= 2 * friends.size()) {
                battleWin.first = false;
            }
        }
        if (cannon_rush) {
            battleWin.first = false;
        }
        int frame = ((GameState) this.handler).frameCount;
        if (!air_only && ((!battleWin.first || battleWin.second) || defenders == 1)) {
            while (((GameState) this.handler).workerDefenders.size() < defenders && !((GameState) this.handler).workerIdle.isEmpty()) {
                Unit closestWorker = null;
                Position chosen = ((GameState) this.handler).attackPosition;
                for (Unit u : ((GameState) this.handler).workerIdle) {
                    if (u.getLastCommandFrame() == frame) {
                        continue;
                    }
                    if ((closestWorker == null || ((GameState) this.handler).broodWarDistance(u.getPosition(), chosen) < ((GameState) this.handler).broodWarDistance(closestWorker.getPosition(), chosen))) {
                        closestWorker = u;
                    }
                }
                if (closestWorker != null) {
                    ((GameState) this.handler).workerDefenders.add(closestWorker);
                    ((GameState) this.handler).workerIdle.remove(closestWorker);
                }
            }
            while (((GameState) this.handler).workerDefenders.size() < defenders && !((GameState) this.handler).workerMining.isEmpty()) {
                Unit closestWorker = null;
                Position chosen = ((GameState) this.handler).attackPosition;
                for (Unit u : ((GameState) this.handler).workerMining.keySet()) {
                    if (u.getLastCommandFrame() == frame) {
                        continue;
                    }
                    if ((closestWorker == null || u.getDistance(chosen) < closestWorker.getDistance(chosen))) {
                        closestWorker = u;
                    }
                }
                if (closestWorker != null) {
                    if (((GameState) this.handler).workerMining.containsKey(closestWorker)) {
                        Unit mineral = ((GameState) this.handler).workerMining.get(closestWorker);
                        ((GameState) this.handler).workerDefenders.add(closestWorker);
                        if (((GameState) this.handler).mineralsAssigned.containsKey(mineral)) {
                            ((GameState) this.handler).mining--;
                            ((GameState) this.handler).mineralsAssigned.put(mineral, ((GameState) this.handler).mineralsAssigned.get(mineral) - 1);
                        }
                        ((GameState) this.handler).workerMining.remove(closestWorker);
                    }
                }
            }
            for (Unit u : ((GameState) this.handler).workerDefenders) {
                if (frame == u.getLastCommandFrame()) {
                    continue;
                }
                if (((GameState) this.handler).attackPosition != null) {
                    if (u.isIdle()) {
                        if (((GameState) this.handler).enemyInBase.size() == 1) {
                            u.attack(((GameState) this.handler).enemyInBase.iterator().next());
                        } else {
                            Unit toAttack = ((GameState) this.handler).getUnitToAttack(u, ((GameState) this.handler).enemyInBase);
                            if (toAttack != null) {
                                Unit lastTarget = u.getOrderTarget();
                                if (lastTarget != null && lastTarget.exists()) {
                                    if (lastTarget.equals(toAttack)) {
                                        continue;
                                    }
                                }
                                UnitCommand lastUnitCommand = u.getLastCommand();
                                if (lastUnitCommand != null) {
                                    if (lastUnitCommand.getTarget() != null && lastUnitCommand.getTarget().exists())
                                        if (lastUnitCommand.getTarget().equals(toAttack)) {
                                            continue;
                                        }
                                }
                                u.attack(toAttack);
                            } else {
                                u.attack(((GameState) this.handler).attackPosition);
                            }
                            continue;
                        }
                    }
                }
            }
        } else {
            if (((GameState) this.handler).strat.name != "ProxyBBS") {
                for (Entry<String, Squad> u : ((GameState) this.handler).squads.entrySet()) {
                    if (((GameState) this.handler).attackPosition != null) {
                        // if(u.getValue().estado == Status.IDLE || !((GameState)this.handler).attackPosition.equals(u.getValue().attack)) {
                        u.getValue().giveAttackOrder(((GameState) this.handler).attackPosition);
                        u.getValue().status = Status.DEFENSE;
                        continue;
                    // }
                    } else {
                        u.getValue().status = Status.IDLE;
                        u.getValue().attack = Position.None;
                        continue;
                    }
                }
            }
        }
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        System.err.println(e);
        return State.ERROR;
    }
}
Also used : Position(bwapi.Position) GameState(ecgberht.GameState) Unit(bwapi.Unit) UnitCommand(bwapi.UnitCommand) Squad(ecgberht.Squad) HashSet(java.util.HashSet) Pair(bwapi.Pair)

Example 5 with Squad

use of ecgberht.Squad in project Ecgberht by Jabbo16.

the class ChooseAttackPosition method execute.

@Override
public State execute() {
    try {
        if (((GameState) this.handler).squads.isEmpty()) {
            return State.FAILURE;
        }
        for (Squad u : ((GameState) this.handler).squads.values()) {
            Pair<Integer, Integer> p = ((GameState) this.handler).inMap.getPosition(((GameState) this.handler).getSquadCenter(u).toTilePosition(), true);
            if (p.first != null && p.second != null) {
                if (!((GameState) this.handler).firstProxyBBS && ((GameState) this.handler).strat.name == "ProxyBBS") {
                    ((GameState) this.handler).firstProxyBBS = true;
                    ((GameState) this.handler).getGame().sendText("Get ready for a party in your house!");
                }
                u.giveAttackOrder(new TilePosition(p.second, p.first).toPosition());
                u.status = Status.ATTACK;
                continue;
            } else if (((GameState) this.handler).enemyBase != null) {
                ((GameState) this.handler).attackPosition = ((GameState) this.handler).enemyBase.getPosition();
                continue;
            } else {
                u.status = Status.IDLE;
                continue;
            }
        }
        return State.SUCCESS;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        System.err.println(e);
        return State.ERROR;
    }
}
Also used : TilePosition(bwapi.TilePosition) GameState(ecgberht.GameState) Squad(ecgberht.Squad)

Aggregations

Squad (ecgberht.Squad)8 GameState (ecgberht.GameState)4 UnitInfo (ecgberht.UnitInfo)4 Position (bwapi.Position)2 Unit (bwapi.Unit)2 Area (bwem.Area)2 Base (bwem.Base)2 ArrayList (java.util.ArrayList)2 Position (org.openbw.bwapi4j.Position)2 Pair (bwapi.Pair)1 TilePosition (bwapi.TilePosition)1 UnitCommand (bwapi.UnitCommand)1 Region (bwta.Region)1 EnemyBuilding (ecgberht.EnemyBuilding)1 Status (ecgberht.Squad.Status)1 MutablePair (ecgberht.Util.MutablePair)1 Util (ecgberht.Util.Util)1 java.util (java.util)1 HashSet (java.util.HashSet)1 Entry (java.util.Map.Entry)1