Search in sources :

Example 1 with Position

use of bwapi.Position in project Ecgberht by Jabbo16.

the class ChooseBuilderBL method execute.

@Override
public State execute() {
    try {
        if (((GameState) this.handler).chosenBuilderBL != null) {
            return State.SUCCESS;
        }
        Unit closestWorker = null;
        Position chosen = ((GameState) this.handler).chosenBaseLocation.toPosition();
        if (!((GameState) this.handler).workerIdle.isEmpty()) {
            for (Unit u : ((GameState) this.handler).workerIdle) {
                double unitChosen = ((GameState) this.handler).broodWarDistance(u.getPosition(), chosen);
                if (closestWorker == null) {
                    closestWorker = u;
                } else {
                    double closestChosen = ((GameState) this.handler).broodWarDistance(closestWorker.getPosition(), chosen);
                    if (unitChosen < closestChosen) {
                        closestWorker = u;
                    }
                }
            }
        }
        if (!((GameState) this.handler).workerMining.isEmpty()) {
            for (Unit u : ((GameState) this.handler).workerMining.keySet()) {
                double unitChosen = ((GameState) this.handler).broodWarDistance(u.getPosition(), chosen);
                if (closestWorker == null) {
                    closestWorker = u;
                } else {
                    double closestChosen = ((GameState) this.handler).broodWarDistance(closestWorker.getPosition(), chosen);
                    if (unitChosen < closestChosen) {
                        closestWorker = u;
                    }
                }
            }
        }
        if (closestWorker != null) {
            if (!((GameState) this.handler).workerTask.isEmpty() && ((GameState) this.handler).workerIdle.contains(closestWorker)) {
                ((GameState) this.handler).workerIdle.remove(closestWorker);
            } else if (!((GameState) this.handler).workerMining.isEmpty()) {
                if (((GameState) this.handler).workerMining.containsKey(closestWorker)) {
                    Unit mineral = ((GameState) this.handler).workerMining.get(closestWorker);
                    ((GameState) this.handler).workerMining.remove(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);
                    }
                }
            }
            if (((GameState) this.handler).chosenWorker != null && ((GameState) this.handler).chosenWorker.equals(closestWorker)) {
                ((GameState) this.handler).chosenWorker = null;
            }
            ((GameState) this.handler).chosenBuilderBL = closestWorker;
            return State.SUCCESS;
        }
        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)

Example 2 with Position

use of bwapi.Position in project Ecgberht by Jabbo16.

the class Vulture method runAgent.

public boolean runAgent() {
    try {
        boolean remove = false;
        if (unit.getHitPoints() <= 15) {
            Position cc = getGs().MainCC.getPosition();
            if (cc != null) {
                unit.move(cc);
            } else {
                unit.move(getGs().getPlayer().getStartLocation().toPosition());
            }
            getGs().addToSquad(unit);
            return true;
        }
        actualFrame = getGs().getGame().getFrameCount();
        closeEnemies.clear();
        closeWorkers.clear();
        if (frameLastOrder == actualFrame) {
            return remove;
        }
        if (actualFrame % getGs().getGame().getLatencyFrames() == 0) {
            return remove;
        }
        Status old = status;
        getNewStatus();
        if (old == status && status != Status.COMBAT && status != Status.ATTACK) {
            return remove;
        }
        if (status != Status.COMBAT) {
            attackUnit = null;
        }
        if (status == Status.ATTACK && unit.isIdle()) {
            Pair<Integer, Integer> pos = getGs().inMap.getPosition(unit.getTilePosition(), true);
            if (pos != null) {
                if (pos.first != null && pos.second != null) {
                    unit.attack(new Position(pos.first, pos.second));
                    return remove;
                }
            }
        }
        switch(status) {
            case ATTACK:
                attack();
                break;
            case COMBAT:
                combat();
                break;
            case KITE:
                kite();
                break;
            case RETREAT:
                retreat();
                break;
            default:
                break;
        }
        return remove;
    } catch (Exception e) {
        System.err.println("Exception Vulture");
        System.err.println(e);
    }
    return false;
}
Also used : Position(bwapi.Position)

Example 3 with Position

use of bwapi.Position in project Ecgberht by Jabbo16.

the class Vulture method kite.

private void kite() {
    Position kite = getGs().kiteAway(unit, closeEnemies);
    unit.move(kite);
    attackPos = Position.None;
}
Also used : Position(bwapi.Position)

Example 4 with Position

use of bwapi.Position in project Ecgberht by Jabbo16.

the class CheckHarasserAttacked method execute.

@Override
public State execute() {
    try {
        Unit attacker = null;
        int workers = 0;
        Set<Unit> attackers = new HashSet<>();
        // Thanks to @N00byEdge to the cleaner code
        for (Unit u : ((GameState) this.handler).getGame().enemy().getUnits()) {
            if (!u.getType().isBuilding() && u.getType().canAttack()) {
                Unit target = (u.getTarget() == null ? u.getOrderTarget() : u.getTarget());
                if (target != null && target.equals(((GameState) this.handler).chosenHarasser)) {
                    if (u.getType().isWorker()) {
                        workers++;
                        attacker = u;
                    }
                    attackers.add(u);
                    continue;
                }
            }
        }
        if (workers > 1) {
            ((GameState) this.handler).EI.defendHarass = true;
        }
        if (attackers.isEmpty()) {
            if (!((GameState) this.handler).getGame().isVisible(((GameState) this.handler).enemyBase.getTilePosition()) && ((GameState) this.handler).chosenUnitToHarass == null) {
                ((GameState) this.handler).chosenHarasser.move(((GameState) this.handler).enemyBase.getPosition());
            }
            return State.SUCCESS;
        } else {
            boolean winHarass = ((GameState) this.handler).simulateHarass(((GameState) this.handler).chosenHarasser, attackers, 70);
            if (winHarass) {
                if (workers == 1 && !attacker.equals(((GameState) this.handler).chosenUnitToHarass)) {
                    ((GameState) this.handler).chosenHarasser.attack(attacker);
                    ((GameState) this.handler).chosenUnitToHarass = attacker;
                    return State.SUCCESS;
                }
            } else {
                if (((GameState) this.handler).chosenHarasser.getHitPoints() <= 15) {
                    ((GameState) this.handler).workerIdle.add(((GameState) this.handler).chosenHarasser);
                    ((GameState) this.handler).chosenHarasser.stop();
                    ((GameState) this.handler).chosenHarasser = null;
                    ((GameState) this.handler).chosenUnitToHarass = null;
                } else {
                    Position kite = getGs().kiteAway(((GameState) this.handler).chosenHarasser, attackers);
                    ((GameState) this.handler).chosenHarasser.move(kite);
                    ((GameState) this.handler).chosenUnitToHarass = null;
                }
                return State.FAILURE;
            }
        }
        return State.SUCCESS;
    } 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) HashSet(java.util.HashSet)

Example 5 with Position

use of bwapi.Position in project Ecgberht by Jabbo16.

the class CheckResourcesBuilding method execute.

@Override
public State execute() {
    try {
        Pair<Integer, Integer> cash = ((GameState) this.handler).getCash();
        Unit chosen = ((GameState) this.handler).chosenWorker;
        TilePosition start = chosen.getTilePosition();
        TilePosition end = ((GameState) this.handler).chosenPosition;
        Position realEnd = ((GameState) this.handler).getCenterFromBuilding(end.toPosition(), ((GameState) this.handler).chosenToBuild);
        if (cash.first + ((GameState) this.handler).getMineralsWhenReaching(chosen, start, realEnd.toTilePosition()) >= (((GameState) this.handler).chosenToBuild.mineralPrice() + ((GameState) this.handler).deltaCash.first) && cash.second >= (((GameState) this.handler).chosenToBuild.gasPrice()) + ((GameState) this.handler).deltaCash.second) {
            return State.SUCCESS;
        }
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        System.err.println(e);
        return State.ERROR;
    }
}
Also used : TilePosition(bwapi.TilePosition) Position(bwapi.Position) TilePosition(bwapi.TilePosition) GameState(ecgberht.GameState) Unit(bwapi.Unit)

Aggregations

Position (bwapi.Position)18 Unit (bwapi.Unit)14 GameState (ecgberht.GameState)9 TilePosition (bwapi.TilePosition)4 HashSet (java.util.HashSet)3 Pair (bwapi.Pair)2 EnemyBuilding (ecgberht.EnemyBuilding)2 Squad (ecgberht.Squad)2 UnitCommand (bwapi.UnitCommand)1 BaseLocation (bwta.BaseLocation)1 Region (bwta.Region)1 ArrayList (java.util.ArrayList)1