Search in sources :

Example 1 with Unit

use of bwapi.Unit 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 Unit

use of bwapi.Unit in project Ecgberht by Jabbo16.

the class Expand method execute.

@Override
public State execute() {
    try {
        Unit chosen = ((GameState) this.handler).chosenBuilderBL;
        if (!chosen.build(UnitType.Terran_Command_Center, ((GameState) this.handler).chosenBaseLocation)) {
            ((GameState) this.handler).movingToExpand = false;
            ((GameState) this.handler).expanding = false;
            ((GameState) this.handler).checkUnitsBL(((GameState) this.handler).chosenBaseLocation, chosen);
            ((GameState) this.handler).chosenBaseLocation = null;
            ((GameState) this.handler).workerIdle.add(((GameState) this.handler).chosenBuilderBL);
            ((GameState) this.handler).chosenBuilderBL.stop();
            ((GameState) this.handler).chosenBuilderBL = null;
            ((GameState) this.handler).deltaCash.first -= UnitType.Terran_Command_Center.mineralPrice();
            ((GameState) this.handler).deltaCash.second -= UnitType.Terran_Command_Center.gasPrice();
            return State.FAILURE;
        }
        ((GameState) this.handler).movingToExpand = false;
        ((GameState) this.handler).workerBuild.add(new Pair<Unit, Pair<UnitType, TilePosition>>(chosen, new Pair<UnitType, TilePosition>(UnitType.Terran_Command_Center, ((GameState) this.handler).chosenBaseLocation)));
        ((GameState) this.handler).expanding = false;
        ((GameState) this.handler).chosenBaseLocation = null;
        ((GameState) this.handler).chosenBuilderBL = null;
        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 3 with Unit

use of bwapi.Unit in project Ecgberht by Jabbo16.

the class Vulture method getUnitToAttack.

private Unit getUnitToAttack(Unit myUnit, Set<Unit> enemies) {
    Unit chosen = null;
    double distB = Double.MAX_VALUE;
    for (Unit u : enemies) {
        if (u.getType().isFlyer() || u.isCloaked()) {
            continue;
        }
        double distA = getGs().broodWarDistance(myUnit.getPosition(), u.getPosition());
        if (chosen == null || distA < distB) {
            chosen = u;
            distB = distA;
        }
    }
    if (chosen != null) {
        return chosen;
    }
    return null;
}
Also used : Unit(bwapi.Unit)

Example 4 with Unit

use of bwapi.Unit in project Ecgberht by Jabbo16.

the class Vulture method retreat.

private void retreat() {
    Unit CC = getGs().MainCC;
    if (CC != null) {
        unit.move(CC.getPosition());
    } else {
        unit.move(getGs().getPlayer().getStartLocation().toPosition());
    }
    attackPos = Position.None;
    attackUnit = null;
}
Also used : Unit(bwapi.Unit)

Example 5 with Unit

use of bwapi.Unit in project Ecgberht by Jabbo16.

the class Vulture method combat.

private void combat() {
    Unit toAttack = getUnitToAttack(unit, closeEnemies);
    if (toAttack != null) {
        if (attackUnit != null) {
            if (attackUnit.equals(toAttack)) {
                return;
            }
        }
        unit.attack(toAttack);
        attackUnit = toAttack;
    } else {
        if (!closeWorkers.isEmpty()) {
            toAttack = getUnitToAttack(unit, closeWorkers);
            if (toAttack != null) {
                if (attackUnit != null) {
                    if (attackUnit.equals(toAttack)) {
                        return;
                    }
                }
            }
        }
        unit.attack(toAttack);
        attackUnit = toAttack;
    }
    attackPos = Position.None;
}
Also used : 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