Search in sources :

Example 51 with Unit

use of bwapi.Unit in project Ecgberht by Jabbo16.

the class Move method execute.

@Override
public State execute() {
    try {
        Unit chosen = ((GameState) this.handler).chosenWorker;
        if (!chosen.canMove()) {
            return State.FAILURE;
        }
        boolean success = false;
        if (((GameState) this.handler).chosenToBuild == UnitType.Terran_Refinery) {
            success = chosen.build(((GameState) this.handler).chosenToBuild, ((GameState) this.handler).chosenPosition);
        } else {
            Position realEnd = ((GameState) this.handler).getCenterFromBuilding(((GameState) this.handler).chosenPosition.toPosition(), ((GameState) this.handler).chosenToBuild);
            success = chosen.move(realEnd);
        }
        if (success) {
            if (((GameState) this.handler).workerIdle.contains(chosen)) {
                ((GameState) this.handler).workerIdle.remove(chosen);
            } else {
                if (((GameState) this.handler).workerMining.containsKey(chosen)) {
                    Unit mineral = ((GameState) this.handler).workerMining.get(chosen);
                    ((GameState) this.handler).workerMining.remove(chosen);
                    if (((GameState) this.handler).mineralsAssigned.containsKey(mineral)) {
                        ((GameState) this.handler).mining--;
                        ((GameState) this.handler).mineralsAssigned.put(mineral, ((GameState) this.handler).mineralsAssigned.get(mineral) - 1);
                    }
                }
            }
            ((GameState) this.handler).workerBuild.add(new Pair<Unit, Pair<UnitType, TilePosition>>(chosen, new Pair<UnitType, TilePosition>(((GameState) this.handler).chosenToBuild, ((GameState) this.handler).chosenPosition)));
            ((GameState) this.handler).deltaCash.first += ((GameState) this.handler).chosenToBuild.mineralPrice();
            ((GameState) this.handler).deltaCash.second += ((GameState) this.handler).chosenToBuild.gasPrice();
            ((GameState) this.handler).chosenWorker = null;
            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) GameState(ecgberht.GameState) Unit(bwapi.Unit) Pair(bwapi.Pair)

Example 52 with Unit

use of bwapi.Unit in project Ecgberht by Jabbo16.

the class CollectGas method execute.

@Override
public State execute() {
    try {
        if (((GameState) this.handler).getPlayer().gas() >= 400) {
            return State.FAILURE;
        }
        Unit chosen = ((GameState) this.handler).chosenWorker;
        if (!((GameState) this.handler).refineriesAssigned.isEmpty()) {
            Unit closestGeyser = null;
            int index = 0;
            int count = 0;
            for (Pair<Pair<Unit, Integer>, Boolean> g : ((GameState) this.handler).refineriesAssigned) {
                if ((closestGeyser == null || chosen.getDistance(g.first.first) < chosen.getDistance(closestGeyser)) && g.first.second < 3 && ((GameState) this.handler).mining > 3 && g.second) {
                    closestGeyser = g.first.first;
                    index = count;
                }
                count++;
            }
            if (closestGeyser != null) {
                ((GameState) this.handler).refineriesAssigned.get(index).first.second++;
                ((GameState) this.handler).workerIdle.remove(chosen);
                ((GameState) this.handler).workerTask.add(new Pair<Unit, Unit>(chosen, closestGeyser));
                chosen.gather(closestGeyser, false);
                ((GameState) this.handler).chosenWorker = null;
                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) Pair(bwapi.Pair)

Example 53 with Unit

use of bwapi.Unit in project Ecgberht by Jabbo16.

the class CameraModule method moveCameraArmy.

@Override
public void moveCameraArmy() {
    int prio = 1;
    if (!shouldMoveCamera(prio)) {
        return;
    }
    // Double loop, check if army units are close to each other
    int radius = 50;
    Unit bestPosUnit = null;
    int mostUnitsNearby = 0;
    for (Unit unit1 : game.getAllUnits()) {
        if (!isArmyUnit(unit1)) {
            continue;
        }
        Position uPos = unit1.getPosition();
        int nrUnitsNearby = 0;
        for (Unit unit2 : game.getUnitsInRadius(uPos, radius)) {
            if (!isArmyUnit(unit2)) {
                continue;
            }
            nrUnitsNearby++;
        }
        if (nrUnitsNearby > mostUnitsNearby) {
            mostUnitsNearby = nrUnitsNearby;
            bestPosUnit = unit1;
        }
    }
    if (mostUnitsNearby > 1) {
        moveCamera(bestPosUnit, prio);
    }
}
Also used : TilePosition(bwapi.TilePosition) Position(bwapi.Position) Unit(bwapi.Unit)

Example 54 with Unit

use of bwapi.Unit in project Ecgberht by Jabbo16.

the class CameraModule method moveCameraScoutWorker.

@Override
public void moveCameraScoutWorker() {
    int highPrio = 2;
    int lowPrio = 0;
    if (!shouldMoveCamera(lowPrio)) {
        return;
    }
    for (Unit unit : game.self().getUnits()) {
        if (!unit.getType().isWorker()) {
            continue;
        }
        if (isNearStartLocation(unit.getPosition())) {
            moveCamera(unit, highPrio);
        } else if (!isNearOwnStartLocation(unit.getPosition())) {
            moveCamera(unit, lowPrio);
        }
    }
}
Also used : Unit(bwapi.Unit)

Example 55 with Unit

use of bwapi.Unit in project Ecgberht by Jabbo16.

the class ChooseComsatStation method execute.

@Override
public State execute() {
    try {
        if (!((GameState) this.handler).CCs.isEmpty()) {
            for (Unit c : ((GameState) this.handler).CCs.values()) {
                if (!c.isTraining() && c.getAddon() == null) {
                    for (Unit u : ((GameState) this.handler).UBs) {
                        if (u.getType() == UnitType.Terran_Academy) {
                            ((GameState) this.handler).chosenBuildingAddon = c;
                            ((GameState) this.handler).chosenAddon = UnitType.Terran_Comsat_Station;
                            return State.SUCCESS;
                        }
                    }
                }
            }
        }
        ((GameState) this.handler).chosenBuildingAddon = null;
        ((GameState) this.handler).chosenAddon = null;
        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