Search in sources :

Example 11 with Area

use of bwem.Area in project Ecgberht by Jabbo16.

the class CheckMineralWalk method getCloserMineral.

private MineralPatch getCloserMineral() {
    double bestDist = Double.MAX_VALUE;
    MineralPatch closerMineral = null;
    for (MineralPatch mineralPatch : gameState.walkingMinerals) {
        if (!mineralPatch.isVisible() || gameState.chosenScout.getDistance(mineralPatch) <= 32 * 4)
            continue;
        double dist = mineralPatch.getDistance(gameState.scoutSLs.iterator().next().getLocation().toPosition());
        if (dist > gameState.chosenScout.getDistance(gameState.scoutSLs.iterator().next().getLocation().toPosition()))
            continue;
        Area mineralArea = gameState.bwem.getMap().getArea(mineralPatch.getTilePosition());
        Area workerArea = gameState.bwem.getMap().getArea(gameState.chosenScout.getTilePosition());
        if (mineralPatch.equals(movingMineral) && mineralArea != null && mineralArea.equals(workerArea))
            continue;
        if (dist < bestDist) {
            bestDist = dist;
            closerMineral = mineralPatch;
        }
    }
    return closerMineral;
}
Also used : Area(bwem.Area) MineralPatch(org.openbw.bwapi4j.unit.MineralPatch)

Example 12 with Area

use of bwem.Area 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 13 with Area

use of bwem.Area in project Ecgberht by Jabbo16.

the class ChooseWorker method execute.

@Override
public State execute() {
    try {
        Worker closestWorker = null;
        int frame = gameState.frameCount;
        Position chosen = gameState.chosenPosition.toPosition();
        Area posArea = gameState.bwem.getMap().getArea(gameState.chosenPosition);
        if (!gameState.workerIdle.isEmpty()) {
            for (Worker u : gameState.workerIdle) {
                if (u.getLastCommandFrame() == frame)
                    continue;
                Area workerArea = gameState.bwem.getMap().getArea(u.getTilePosition());
                if (workerArea == null)
                    continue;
                if (posArea != null && !posArea.equals(workerArea) && !posArea.isAccessibleFrom(workerArea)) {
                    continue;
                }
                if ((closestWorker == null || u.getDistance(chosen) < closestWorker.getDistance(chosen)))
                    closestWorker = u;
            }
        }
        if (!gameState.workerMining.isEmpty()) {
            for (Worker u : gameState.workerMining.keySet()) {
                if (u.getLastCommandFrame() == frame)
                    continue;
                Area workerArea = gameState.bwem.getMap().getArea(u.getTilePosition());
                if (workerArea == null)
                    continue;
                if (posArea != null && !posArea.equals(workerArea) && !posArea.isAccessibleFrom(workerArea)) {
                    continue;
                }
                if ((closestWorker == null || u.getDistance(chosen) < closestWorker.getDistance(chosen)) && !u.isCarryingMinerals()) {
                    closestWorker = u;
                }
            }
        }
        if (closestWorker != null) {
            gameState.chosenWorker = closestWorker;
            return State.SUCCESS;
        }
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        e.printStackTrace();
        return State.ERROR;
    }
}
Also used : Area(bwem.Area) Position(org.openbw.bwapi4j.Position) Worker(org.openbw.bwapi4j.unit.Worker)

Example 14 with Area

use of bwem.Area in project Ecgberht by Jabbo16.

the class CheckMineralWalkGoldRush method getCloserMineral.

private MineralPatch getCloserMineral(Map.Entry<SCV, MutablePair<UnitType, TilePosition>> entry) {
    double bestDist = Double.MAX_VALUE;
    MineralPatch closerMineral = null;
    SCV scv = entry.getKey();
    Position buildTarget = entry.getValue().second.toPosition();
    for (MineralPatch mineralPatch : gameState.walkingMinerals) {
        if (!mineralPatch.isVisible() || scv.getDistance(mineralPatch) <= 32 * 4)
            continue;
        double dist = mineralPatch.getDistance(buildTarget) * 1.2;
        if (dist > scv.getDistance(buildTarget))
            continue;
        Area mineralArea = gameState.bwem.getMap().getArea(mineralPatch.getTilePosition());
        Area workerArea = gameState.bwem.getMap().getArea(scv.getTilePosition());
        if (mineralPatch.equals(scv.getTargetUnit()) && mineralArea != null && mineralArea.equals(workerArea))
            continue;
        if (dist < bestDist) {
            bestDist = dist;
            closerMineral = mineralPatch;
        }
    }
    return closerMineral;
}
Also used : Area(bwem.Area) MineralPatch(org.openbw.bwapi4j.unit.MineralPatch) TilePosition(org.openbw.bwapi4j.TilePosition) Position(org.openbw.bwapi4j.Position) SCV(org.openbw.bwapi4j.unit.SCV)

Aggregations

Area (bwem.Area)14 TilePosition (org.openbw.bwapi4j.TilePosition)9 Base (bwem.Base)6 Position (org.openbw.bwapi4j.Position)5 ChokePoint (bwem.ChokePoint)4 UnitInfo (ecgberht.UnitInfo)3 MineralPatch (org.openbw.bwapi4j.unit.MineralPatch)3 Squad (ecgberht.Squad)2 ArrayList (java.util.ArrayList)2 WalkPosition (org.openbw.bwapi4j.WalkPosition)2 SCV (org.openbw.bwapi4j.unit.SCV)2 GameState (ecgberht.GameState)1 Status (ecgberht.Squad.Status)1 MutablePair (ecgberht.Util.MutablePair)1 Util (ecgberht.Util.Util)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 Result (org.bk.ass.path.Result)1 State (org.iaie.btree.BehavioralTree.State)1 Conditional (org.iaie.btree.task.leaf.Conditional)1