Search in sources :

Example 36 with Position

use of org.openbw.bwapi4j.Position in project Ecgberht by Jabbo16.

the class VultureAgent method retreat.

private void retreat() {
    Position CC = getGs().getNearestCC(myUnit.getPosition(), true);
    if (CC != null)
        UtilMicro.move(unit, CC);
    else
        UtilMicro.move(unit, getGs().getPlayer().getStartLocation().toPosition());
    attackPos = null;
    attackUnit = null;
}
Also used : Position(org.openbw.bwapi4j.Position)

Example 37 with Position

use of org.openbw.bwapi4j.Position in project Ecgberht by Jabbo16.

the class VultureAgent method runAgent.

@Override
public boolean runAgent() {
    try {
        if (!unit.exists() || unitInfo == null)
            return true;
        if (unit.getHitPoints() <= 20) {
            MutablePair<Base, Unit> cc = getGs().mainCC;
            if (cc != null && cc.second != null) {
                Position ccPos = cc.second.getPosition();
                if (getGs().getGame().getBWMap().isValidPosition(ccPos)) {
                    unit.move(ccPos);
                    getGs().myArmy.add(unitInfo);
                    return true;
                }
            }
            unit.move(getGs().getPlayer().getStartLocation().toPosition());
            getGs().myArmy.add(unitInfo);
            return true;
        }
        mySim = getGs().sim.getSimulation(unitInfo, SimInfo.SimType.GROUND);
        actualFrame = getGs().frameCount;
        frameLastOrder = unit.getLastCommandFrame();
        if (frameLastOrder == actualFrame)
            return false;
        // Status old = status;
        getNewStatus();
        // if (old == status && status != Status.COMBAT && status != Status.ATTACK) return false;
        if (status != Status.COMBAT && status != Status.PATROL)
            attackUnit = null;
        if ((status == Status.ATTACK || status == Status.IDLE) && (unit.isIdle() || unit.getOrder() == Order.PlayerGuard)) {
            Position pos = Util.chooseAttackPosition(unit.getPosition(), false);
            if (pos == null || !getGs().getGame().getBWMap().isValidPosition(pos))
                return false;
            UtilMicro.move(unit, pos);
            status = Status.ATTACK;
            return false;
        }
        switch(status) {
            case ATTACK:
                attack();
                break;
            case COMBAT:
                combat();
                break;
            case KITE:
                kite();
                break;
            case RETREAT:
                retreat();
                break;
            case PATROL:
                patrol();
                break;
        }
        return false;
    } catch (Exception e) {
        System.err.println("Exception VultureAgent");
        e.printStackTrace();
    }
    return false;
}
Also used : Position(org.openbw.bwapi4j.Position) Unit(org.openbw.bwapi4j.unit.Unit) Base(bwem.Base)

Example 38 with Position

use of org.openbw.bwapi4j.Position in project Ecgberht by Jabbo16.

the class VultureAgent method getNewStatus.

private void getNewStatus() {
    if (mySim.enemies.isEmpty()) {
        status = Status.ATTACK;
    } else {
        boolean meleeOnly = checkOnlyMelees();
        if (!meleeOnly && getGs().sim.getSimulation(unitInfo, SimInfo.SimType.GROUND).lose) {
            status = Util.isInOurBases(unitInfo) ? Status.KITE : Status.RETREAT;
            return;
        }
        if (status == Status.PATROL && actualFrame - lastPatrolFrame > 5) {
            status = Status.COMBAT;
            return;
        }
        int cd = unit.getGroundWeapon().cooldown();
        UnitInfo closestAttacker = Util.getClosestUnit(unitInfo, mySim.enemies, true);
        if (closestAttacker != null && (cd != 0 || unitInfo.getDistance(closestAttacker) < unitInfo.groundRange * 0.6)) {
            status = Status.KITE;
            return;
        }
        if (status == Status.COMBAT || status == Status.ATTACK) {
            /*if (attackUnit != null) {
                    int weaponRange = attackUnit instanceof GroundAttacker ? ((GroundAttacker) attackUnit).getGroundWeaponMaxRange() : 0;
                    if (weaponRange > type.groundWeapon().maxRange()) return;
                }*/
            if (cd > 0) {
                if (attackUnit != null) {
                    Position predictedPosition = UtilMicro.predictUnitPosition(attackUnit, 2);
                    if (predictedPosition != null && getGs().getGame().getBWMap().isValidPosition(predictedPosition)) {
                        double distPredicted = unit.getDistance(predictedPosition);
                        double distCurrent = unitInfo.getDistance(attackUnit);
                        if (distPredicted > distCurrent) {
                            status = Status.COMBAT;
                            return;
                        } else {
                            attackUnit = null;
                            attackPos = null;
                            status = Status.KITE;
                            return;
                        }
                    }
                }
                if (mySim.enemies.isEmpty()) {
                    status = Status.ATTACK;
                    return;
                }
                status = Status.COMBAT;
                return;
            }
        }
        if (status == Status.KITE) {
            UnitInfo closest = getUnitToAttack(mySim.enemies);
            if (closest != null) {
                double dist = unitInfo.getDistance(closest);
                double speed = type.topSpeed();
                double timeToEnter = 0.0;
                if (speed > .00001)
                    timeToEnter = Math.max(0.0, dist - type.groundWeapon().maxRange()) / speed;
                if (timeToEnter >= cd) {
                    // status = Status.COMBAT;
                    status = Status.PATROL;
                    attackUnit = closest;
                    return;
                }
            } else {
                status = Status.ATTACK;
                return;
            }
            if (cd == 0)
                status = Status.COMBAT;
        }
    }
}
Also used : UnitInfo(ecgberht.UnitInfo) Position(org.openbw.bwapi4j.Position)

Example 39 with Position

use of org.openbw.bwapi4j.Position in project Ecgberht by Jabbo16.

the class WraithAgent method runAgent.

@Override
public boolean runAgent() {
    // TODO improve
    try {
        if (!unit.exists() || unitInfo == null)
            return true;
        actualFrame = getGs().frameCount;
        frameLastOrder = unit.getLastCommandFrame();
        airAttackers.clear();
        if (frameLastOrder == actualFrame)
            return false;
        Position attack = getBestBaseToHarass();
        UnitInfo closestThreat = null;
        double bestDist = Double.MAX_VALUE;
        SimInfo airSim = getGs().sim.getSimulation(unitInfo, SimInfo.SimType.AIR);
        airAttackers = airSim.enemies;
        for (UnitInfo u : airAttackers) {
            double predictedDist = unitInfo.getPredictedDistance(u);
            if (predictedDist < bestDist) {
                closestThreat = u;
                bestDist = predictedDist;
            }
        }
        Set<UnitInfo> mainTargets = getGs().sim.getSimulation(unitInfo, SimInfo.SimType.MIX).enemies;
        UnitInfo harassed = chooseHarassTarget(mainTargets);
        if (closestThreat != null) {
            Weapon myWeapon = closestThreat.flying ? unit.getAirWeapon() : unit.getGroundWeapon();
            double hisAirWeaponRange = closestThreat.airRange;
            Position kitePos = UtilMicro.kiteAway(unit, new TreeSet<>(Collections.singleton(closestThreat)));
            if (myWeapon.maxRange() > hisAirWeaponRange && bestDist > hisAirWeaponRange) {
                if (myWeapon.cooldown() != 0) {
                    if (kitePos != null) {
                        UtilMicro.move(unit, kitePos);
                        return false;
                    }
                } else if (harassed != null && unitInfo.getDistance(harassed) <= myWeapon.maxRange()) {
                    UtilMicro.attack(unitInfo, harassed);
                } else
                    UtilMicro.attack(unitInfo, closestThreat);
                return false;
            }
            if (kitePos != null) {
                UtilMicro.move(unit, kitePos);
                return false;
            }
        }
        if (harassed != null) {
            UtilMicro.attack(unitInfo, harassed);
            return false;
        }
        UnitInfo target = Util.getRangedTarget(unitInfo, mainTargets);
        if (target != null) {
            UtilMicro.attack(unitInfo, target);
            return false;
        }
        if (attack != null) {
            if (attack.getDistance(myUnit.getPosition()) >= 32 * 5)
                UtilMicro.move(unit, attack);
            else
                UtilMicro.attack(unit, attack);
            return false;
        }
        return false;
    } catch (Exception e) {
        System.err.println("Exception WraithAgent");
        e.printStackTrace();
    }
    return false;
}
Also used : UnitInfo(ecgberht.UnitInfo) SimInfo(ecgberht.Simulation.SimInfo) Position(org.openbw.bwapi4j.Position) Weapon(org.openbw.bwapi4j.unit.Weapon)

Example 40 with Position

use of org.openbw.bwapi4j.Position in project Ecgberht by Jabbo16.

the class CheckResourcesBuilding method execute.

@Override
public State execute() {
    try {
        if (gameState.chosenPosition == null) {
            gameState.chosenWorker = null;
            // ((GameState) gameState).chosenToBuild = UnitType.None;
            return State.FAILURE;
        }
        MutablePair<Integer, Integer> cash = gameState.getCash();
        Worker chosen = gameState.chosenWorker;
        TilePosition start = chosen.getTilePosition();
        TilePosition end = gameState.chosenPosition;
        Position realEnd = Util.getUnitCenterPosition(end.toPosition(), gameState.chosenToBuild);
        if (gameState.getStrat().name.equals("ProxyBBS") && gameState.chosenToBuild == UnitType.Terran_Barracks) {
            if (Util.countBuildingAll(UnitType.Terran_Barracks) < 1) {
                if (cash.first + gameState.getMineralsWhenReaching(start, realEnd.toTilePosition()) >= (gameState.chosenToBuild.mineralPrice() * 2 + 40 + gameState.deltaCash.first) && cash.second >= (gameState.chosenToBuild.gasPrice() * 2) + gameState.deltaCash.second) {
                    return State.SUCCESS;
                }
            } else if (Util.countBuildingAll(UnitType.Terran_Barracks) == 1)
                return State.SUCCESS;
            return State.FAILURE;
        } else if (cash.first + gameState.getMineralsWhenReaching(start, realEnd.toTilePosition()) >= (gameState.chosenToBuild.mineralPrice() + gameState.deltaCash.first) && cash.second >= (gameState.chosenToBuild.gasPrice()) + gameState.deltaCash.second) {
            return State.SUCCESS;
        }
        gameState.chosenWorker = null;
        gameState.chosenPosition = null;
        // ((GameState) gameState).chosenToBuild = UnitType.None;
        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) TilePosition(org.openbw.bwapi4j.TilePosition) Worker(org.openbw.bwapi4j.unit.Worker)

Aggregations

Position (org.openbw.bwapi4j.Position)55 TilePosition (org.openbw.bwapi4j.TilePosition)19 UnitInfo (ecgberht.UnitInfo)10 Worker (org.openbw.bwapi4j.unit.Worker)10 UnitType (org.openbw.bwapi4j.type.UnitType)9 SimInfo (ecgberht.Simulation.SimInfo)8 Util (ecgberht.Util.Util)8 WalkPosition (org.openbw.bwapi4j.WalkPosition)8 Ecgberht.getGs (ecgberht.Ecgberht.getGs)7 UtilMicro (ecgberht.Util.UtilMicro)7 org.openbw.bwapi4j.unit (org.openbw.bwapi4j.unit)7 Area (bwem.Area)6 Base (bwem.Base)6 Collectors (java.util.stream.Collectors)6 Order (org.openbw.bwapi4j.type.Order)6 java.util (java.util)5 WeaponType (org.openbw.bwapi4j.type.WeaponType)5 ArrayList (java.util.ArrayList)4 MineralPatch (org.openbw.bwapi4j.unit.MineralPatch)4 Squad (ecgberht.Squad)3