Search in sources :

Example 11 with Unit

use of bwapi.Unit in project Ecgberht by Jabbo16.

the class Squad method microUpdateOrder.

public void microUpdateOrder() {
    try {
        if (members.isEmpty()) {
            return;
        }
        Set<Unit> enemy = getGs().enemyCombatUnitMemory;
        int frameCount = getGs().frameCount;
        Position start = getGame().self().getStartLocation().toPosition();
        Set<Unit> marinesToHeal = new HashSet<>();
        Position sCenter = getGs().getSquadCenter(this);
        for (Unit u : members) {
            if (u.getType() == UnitType.Terran_Siege_Tank_Siege_Mode) {
                continue;
            }
            if (u.getType() == UnitType.Terran_Siege_Tank_Tank_Mode && u.getOrder() == Order.Sieging) {
                continue;
            }
            Position lastTarget = (u.getTargetPosition() == null ? u.getOrderTargetPosition() : u.getTargetPosition());
            if (lastTarget != null) {
                if (lastTarget.equals(attack)) {
                    continue;
                }
            }
            if (!getGs().DBs.isEmpty()) {
                Unit bunker = getGs().DBs.keySet().iterator().next();
                if (status == Status.IDLE && getGs().broodWarDistance(bunker.getPosition(), sCenter) >= 130 && getGs().getArmySize() < getGs().strat.armyForAttack && !getGs().expanding) {
                    if (u.getOrder() != Order.Move) {
                        u.move(bunker.getPosition());
                    }
                    continue;
                }
            } else if (getGs().closestChoke != null && !getGs().EI.naughty) {
                if (status == Status.IDLE && getGs().broodWarDistance(getGs().closestChoke.getCenter(), sCenter) >= 130 && getGs().getArmySize() < getGs().strat.armyForAttack && !getGs().expanding) {
                    if (u.getOrder() != Order.Move) {
                        u.move(getGs().closestChoke.getCenter());
                    }
                    continue;
                }
            }
            if (status == Status.IDLE && getGs().broodWarDistance(u.getPosition(), sCenter) >= 100 && u.getOrder() != Order.Move) {
                if (getGame().isWalkable(sCenter.toWalkPosition())) {
                    u.move(sCenter);
                    continue;
                }
            }
            if (u.getType() == UnitType.Terran_Medic && u.getOrder() != Order.MedicHeal) {
                Unit chosen = getHealTarget(u, marinesToHeal);
                if (chosen != null) {
                    u.useTech(TechType.Healing, chosen);
                    marinesToHeal.add(chosen);
                    continue;
                }
            }
            if (u.isIdle() && attack != Position.None && frameCount != u.getLastCommandFrame() && getGs().broodWarDistance(attack, u.getPosition()) > 500) {
                u.attack(attack);
                continue;
            }
            if (u.isAttacking() && attack == Position.None && frameCount != u.getLastCommandFrame() && getGs().broodWarDistance(sCenter, u.getPosition()) > 500) {
                u.move(sCenter);
                continue;
            }
            int framesToOrder = 18;
            if (u.getType() == UnitType.Terran_Vulture) {
                framesToOrder = 12;
            }
            if (frameCount - u.getLastCommandFrame() >= framesToOrder) {
                if (u.isIdle() && attack != Position.None && status != Status.IDLE) {
                    u.attack(attack);
                    continue;
                }
                // Experimental storm dodging?
                if (u.isUnderStorm()) {
                    u.move(start);
                    continue;
                }
                Set<Unit> enemyToKite = new HashSet<>();
                if (u.getGroundWeaponCooldown() > 0) {
                    for (Unit e : enemy) {
                        if (!e.getType().isFlyer() && e.getType().groundWeapon().maxRange() <= 32 && e.getType() != UnitType.Terran_Medic) {
                            if (e.isAttacking()) {
                                if (u.getUnitsInRadius(u.getType().groundWeapon().maxRange()).contains(e)) {
                                    // u.move(start);
                                    enemyToKite.add(e);
                                }
                            }
                        }
                    }
                    if (!enemyToKite.isEmpty()) {
                        Position run = getGs().kiteAway(u, enemyToKite);
                        if (run.isValid()) {
                            u.move(run);
                            continue;
                        } else {
                            u.move(getGs().getPlayer().getStartLocation().toPosition());
                            continue;
                        }
                    // Position run = getGs().getPlayer().getStartLocation().toPosition();
                    }
                } else if (attack != Position.None && !u.isStartingAttack() && !u.isAttacking() && u.getOrder() == Order.Move) {
                    u.attack(attack);
                    continue;
                }
            }
        }
    } catch (Exception e) {
        System.err.println("microUpdateOrder Error");
        System.err.println(e);
    }
}
Also used : Position(bwapi.Position) Unit(bwapi.Unit) HashSet(java.util.HashSet)

Example 12 with Unit

use of bwapi.Unit in project Ecgberht by Jabbo16.

the class Squad method getHealTarget.

private Unit getHealTarget(final Unit u, final Set<Unit> marinesToHeal) {
    Set<Unit> marines = getMarines();
    Unit chosen = null;
    double dist = Double.MAX_VALUE;
    for (Unit m : marines) {
        if (m.getHitPoints() == m.getType().maxHitPoints() || marinesToHeal.contains(m)) {
            continue;
        }
        double distA = getGs().broodWarDistance(m.getPosition(), u.getPosition());
        if (chosen == null || distA < dist) {
            chosen = m;
            dist = distA;
        }
    }
    return chosen;
}
Also used : Unit(bwapi.Unit)

Example 13 with Unit

use of bwapi.Unit in project Ecgberht by Jabbo16.

the class ChoosePosition method execute.

@Override
public State execute() {
    try {
        Game juego = ((GameState) this.handler).getGame();
        Player jugador = ((GameState) this.handler).getPlayer();
        TilePosition origin = null;
        if (((GameState) this.handler).chosenToBuild.isRefinery()) {
            if (!((GameState) this.handler).refineriesAssigned.isEmpty()) {
                for (Pair<Pair<Unit, Integer>, Boolean> g : ((GameState) this.handler).refineriesAssigned) {
                    if (!g.second) {
                        ((GameState) this.handler).chosenPosition = g.first.first.getTilePosition();
                        return State.SUCCESS;
                    }
                }
            }
        } else {
            if (!((GameState) this.handler).workerBuild.isEmpty()) {
                for (Pair<Unit, Pair<UnitType, TilePosition>> w : ((GameState) this.handler).workerBuild) {
                    ((GameState) this.handler).testMap.updateMap(w.second.second, w.second.first, false);
                }
            }
            if (!((GameState) this.handler).chosenToBuild.equals(UnitType.Terran_Bunker) && !((GameState) this.handler).chosenToBuild.equals(UnitType.Terran_Missile_Turret)) {
                if (((GameState) this.handler).strat.proxy && ((GameState) this.handler).chosenToBuild == UnitType.Terran_Barracks) {
                    origin = new TilePosition(((GameState) this.handler).getGame().mapWidth() / 2, ((GameState) this.handler).getGame().mapHeight() / 2);
                } else {
                    // origin = BWTA.getRegion(jugador.getStartLocation()).getCenter().toTilePosition();
                    origin = jugador.getStartLocation();
                }
            } else {
                if (((GameState) this.handler).chosenToBuild.equals(UnitType.Terran_Missile_Turret)) {
                    if (((GameState) this.handler).DBs.isEmpty()) {
                        origin = BWTA.getNearestChokepoint(jugador.getStartLocation()).getCenter().toTilePosition();
                    } else {
                        for (Unit b : ((GameState) this.handler).DBs.keySet()) {
                            origin = b.getTilePosition();
                            break;
                        }
                    }
                } else {
                    if (((GameState) this.handler).EI.naughty && ((GameState) this.handler).enemyRace == Race.Zerg) {
                        TilePosition raxTile = ((GameState) this.handler).MBs.iterator().next().getTilePosition();
                        origin = ((GameState) this.handler).testMap.findBunkerPositionAntiPool(raxTile.toPosition(), ((GameState) this.handler).closestChoke);
                        if (origin != null) {
                            ((GameState) this.handler).testMap = ((GameState) this.handler).map.clone();
                            ((GameState) this.handler).chosenPosition = origin;
                            return State.SUCCESS;
                        } else {
                            origin = ((GameState) this.handler).getBunkerPositionAntiPool();
                            if (origin != null) {
                                ((GameState) this.handler).testMap = ((GameState) this.handler).map.clone();
                                ((GameState) this.handler).chosenPosition = origin;
                                return State.SUCCESS;
                            } else {
                                origin = raxTile;
                            }
                        }
                    } else {
                        if (((GameState) this.handler).Ts.isEmpty()) {
                            if (((GameState) this.handler).closestChoke != null) {
                                origin = ((GameState) this.handler).testMap.findBunkerPosition(((GameState) this.handler).closestChoke);
                                if (origin != null) {
                                    ((GameState) this.handler).testMap = ((GameState) this.handler).map.clone();
                                    ((GameState) this.handler).chosenPosition = origin;
                                    return State.SUCCESS;
                                } else {
                                    origin = ((GameState) this.handler).closestChoke.getCenter().toTilePosition();
                                }
                            }
                        // else {
                        // origin = BWTA.getNearestChokepoint(jugador.getStartLocation()).getCenter().toTilePosition();
                        // }
                        } else {
                            for (Unit b : ((GameState) this.handler).Ts) {
                                origin = b.getTilePosition();
                                break;
                            }
                        }
                    }
                }
            }
            TilePosition posicion = ((GameState) this.handler).testMap.findPosition(((GameState) this.handler).chosenToBuild, origin);
            ((GameState) this.handler).testMap = ((GameState) this.handler).map.clone();
            if (posicion != null) {
                ((GameState) this.handler).chosenPosition = posicion;
                return State.SUCCESS;
            }
        }
        TilePosition posicion = juego.getBuildLocation(((GameState) this.handler).chosenToBuild, BWTA.getRegion(jugador.getStartLocation()).getCenter().toTilePosition(), 500);
        if (posicion != null) {
            if (juego.canBuildHere(posicion, ((GameState) this.handler).chosenToBuild)) {
                ((GameState) this.handler).chosenPosition = posicion;
                return State.SUCCESS;
            }
        }
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        System.err.println(e);
        return State.ERROR;
    }
}
Also used : Player(bwapi.Player) Game(bwapi.Game) TilePosition(bwapi.TilePosition) GameState(ecgberht.GameState) Unit(bwapi.Unit) Pair(bwapi.Pair)

Example 14 with Unit

use of bwapi.Unit in project Ecgberht by Jabbo16.

the class ChooseRefinery method execute.

@Override
public State execute() {
    try {
        if (((GameState) this.handler).getPlayer().supplyUsed() < ((GameState) this.handler).strat.supplyForFirstRefinery || ((GameState) this.handler).getCash().second >= 300) {
            return State.FAILURE;
        }
        if (((GameState) this.handler).refineriesAssigned.size() == 1) {
            boolean found = false;
            for (Pair<Unit, Pair<UnitType, TilePosition>> w : ((GameState) this.handler).workerBuild) {
                if (w.second.first == UnitType.Terran_Barracks) {
                    found = true;
                    break;
                }
            }
            for (Pair<Unit, Unit> w : ((GameState) this.handler).workerTask) {
                if (w.second.getType() == UnitType.Terran_Barracks) {
                    found = true;
                    break;
                }
            }
            if (((GameState) this.handler).MBs.isEmpty() && found == false) {
                return State.FAILURE;
            }
        }
        int count = 0;
        Unit geyser = null;
        for (Pair<Pair<Unit, Integer>, Boolean> r : ((GameState) this.handler).refineriesAssigned) {
            if (r.second) {
                count++;
            } else {
                geyser = r.first.first;
            }
        }
        if (count == ((GameState) this.handler).refineriesAssigned.size()) {
            return State.FAILURE;
        }
        for (Pair<Unit, Pair<UnitType, TilePosition>> w : ((GameState) this.handler).workerBuild) {
            if (w.second.first == UnitType.Terran_Refinery) {
                return State.FAILURE;
            }
        }
        for (Pair<Unit, Unit> w : ((GameState) this.handler).workerTask) {
            if (w.second.getType() == UnitType.Terran_Refinery && w.second.getPosition().equals(geyser.getPosition())) {
                return State.FAILURE;
            }
        }
        ((GameState) this.handler).chosenToBuild = UnitType.Terran_Refinery;
        return State.SUCCESS;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        System.err.println(e);
        return State.ERROR;
    }
}
Also used : GameState(ecgberht.GameState) Unit(bwapi.Unit) Pair(bwapi.Pair)

Example 15 with Unit

use of bwapi.Unit in project Ecgberht by Jabbo16.

the class CheckBuildingFlames method execute.

@Override
public State execute() {
    try {
        boolean isBeingRepaired = false;
        for (Unit w : ((GameState) this.handler).DBs.keySet()) {
            if (w.getType().maxHitPoints() != w.getHitPoints()) {
                for (Pair<Unit, Unit> r : ((GameState) this.handler).repairerTask) {
                    if (w.equals(r.second)) {
                        isBeingRepaired = true;
                    }
                }
                if (!isBeingRepaired) {
                    ((GameState) this.handler).chosenBuildingRepair = w;
                    return State.SUCCESS;
                }
            }
        }
        isBeingRepaired = false;
        for (Unit b : ((GameState) this.handler).Ts) {
            if (b.getType().maxHitPoints() != b.getHitPoints()) {
                for (Pair<Unit, Unit> r : ((GameState) this.handler).repairerTask) {
                    if (b.equals(r.second)) {
                        isBeingRepaired = true;
                    }
                }
                if (!isBeingRepaired) {
                    ((GameState) this.handler).chosenBuildingRepair = b;
                    return State.SUCCESS;
                }
            }
        }
        isBeingRepaired = false;
        for (Unit b : ((GameState) this.handler).MBs) {
            if (b.getType().maxHitPoints() != b.getHitPoints()) {
                for (Pair<Unit, Unit> r : ((GameState) this.handler).repairerTask) {
                    if (b.equals(r.second)) {
                        isBeingRepaired = true;
                    }
                }
                if (!isBeingRepaired) {
                    ((GameState) this.handler).chosenBuildingRepair = b;
                    return State.SUCCESS;
                }
            }
        }
        isBeingRepaired = false;
        for (Unit b : ((GameState) this.handler).Fs) {
            if (b.getType().maxHitPoints() != b.getHitPoints()) {
                for (Pair<Unit, Unit> r : ((GameState) this.handler).repairerTask) {
                    if (b.equals(r.second)) {
                        isBeingRepaired = true;
                    }
                }
                if (!isBeingRepaired) {
                    ((GameState) this.handler).chosenBuildingRepair = b;
                    return State.SUCCESS;
                }
            }
        }
        isBeingRepaired = false;
        for (Unit b : ((GameState) this.handler).UBs) {
            if (b.getType().maxHitPoints() != b.getHitPoints()) {
                for (Pair<Unit, Unit> r : ((GameState) this.handler).repairerTask) {
                    if (b.equals(r.second)) {
                        isBeingRepaired = true;
                    }
                }
                if (!isBeingRepaired) {
                    ((GameState) this.handler).chosenBuildingRepair = b;
                    return State.SUCCESS;
                }
            }
        }
        isBeingRepaired = false;
        for (Unit b : ((GameState) this.handler).SBs) {
            if (b.getType().maxHitPoints() != b.getHitPoints()) {
                for (Pair<Unit, Unit> r : ((GameState) this.handler).repairerTask) {
                    if (b.equals(r.second)) {
                        isBeingRepaired = true;
                    }
                }
                if (!isBeingRepaired) {
                    ((GameState) this.handler).chosenBuildingRepair = b;
                    return State.SUCCESS;
                }
            }
        }
        isBeingRepaired = false;
        for (Unit b : ((GameState) this.handler).CCs.values()) {
            if (b.getType().maxHitPoints() != b.getHitPoints()) {
                for (Pair<Unit, Unit> r : ((GameState) this.handler).repairerTask) {
                    if (b.equals(r.second)) {
                        isBeingRepaired = true;
                    }
                }
                if (!isBeingRepaired) {
                    ((GameState) this.handler).chosenBuildingRepair = b;
                    return State.SUCCESS;
                }
            }
        }
        isBeingRepaired = false;
        for (Unit b : ((GameState) this.handler).CSs) {
            if (b.getType().maxHitPoints() != b.getHitPoints()) {
                for (Pair<Unit, Unit> r : ((GameState) this.handler).repairerTask) {
                    if (b.equals(r.second)) {
                        isBeingRepaired = true;
                    }
                }
                if (!isBeingRepaired) {
                    ((GameState) this.handler).chosenBuildingRepair = b;
                    return State.SUCCESS;
                }
            }
        }
        isBeingRepaired = false;
        for (Unit b : ((GameState) this.handler).Ps) {
            if (b.getType().maxHitPoints() != b.getHitPoints()) {
                for (Pair<Unit, Unit> r : ((GameState) this.handler).repairerTask) {
                    if (b.equals(r.second)) {
                        isBeingRepaired = true;
                    }
                }
                if (!isBeingRepaired) {
                    ((GameState) this.handler).chosenBuildingRepair = b;
                    return State.SUCCESS;
                }
            }
        }
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        System.err.println(e);
        return State.ERROR;
    }
}
Also used : GameState(ecgberht.GameState) Unit(bwapi.Unit)

Aggregations

Unit (bwapi.Unit)73 GameState (ecgberht.GameState)36 Test (org.junit.Test)21 Position (bwapi.Position)14 TilePosition (bwapi.TilePosition)10 BaseLocation (bwta.BaseLocation)7 Pair (bwapi.Pair)6 UnitType (bwapi.UnitType)6 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 Player (bwapi.Player)3 EnemyBuilding (ecgberht.EnemyBuilding)3 RaceUtils.createMockRace (BWJSAL.utils.RaceUtils.createMockRace)2 UnitTypeUtils.mockResourceDepotUnitType (BWJSAL.utils.UnitTypeUtils.mockResourceDepotUnitType)2 Race (bwapi.Race)2 Squad (ecgberht.Squad)2 Game (bwapi.Game)1 UnitCommand (bwapi.UnitCommand)1 Region (bwta.Region)1 Random (java.util.Random)1