Search in sources :

Example 26 with GameState

use of ecgberht.GameState in project Ecgberht by Jabbo16.

the class Repair method execute.

@Override
public State execute() {
    try {
        if (((GameState) this.handler).chosenRepairer.repair(((GameState) this.handler).chosenBuildingRepair)) {
            if (((GameState) this.handler).workerIdle.contains(((GameState) this.handler).chosenRepairer)) {
                ((GameState) this.handler).workerIdle.remove(((GameState) this.handler).chosenRepairer);
            } else {
                if (((GameState) this.handler).workerMining.containsKey(((GameState) this.handler).chosenRepairer)) {
                    Unit mineral = ((GameState) this.handler).workerMining.get(((GameState) this.handler).chosenRepairer);
                    ((GameState) this.handler).workerMining.remove(((GameState) this.handler).chosenRepairer);
                    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).repairerTask.add(new Pair<Unit, Unit>(((GameState) this.handler).chosenRepairer, ((GameState) this.handler).chosenBuildingRepair));
            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)

Example 27 with GameState

use of ecgberht.GameState in project Ecgberht by Jabbo16.

the class CheckScan method execute.

@Override
public State execute() {
    try {
        if (((GameState) this.handler).CSs.isEmpty()) {
            return State.FAILURE;
        }
        if (((GameState) this.handler).getGame().elapsedTime() - ((GameState) this.handler).startCount > 1) {
            for (Unit u : ((GameState) this.handler).enemyCombatUnitMemory) {
                if ((u.isCloaked() || u.isBurrowed()) && !u.isDetected() && u.getType().canAttack()) {
                    ((GameState) this.handler).checkScan = u.getTilePosition();
                    return State.SUCCESS;
                }
            }
        }
        List<BaseLocation> valid = new ArrayList<>();
        for (BaseLocation b : ((GameState) this.handler).EnemyBLs) {
            if (((GameState) this.handler).getGame().isVisible(b.getTilePosition()) || b.isIsland()) {
                continue;
            }
            if (((GameState) this.handler).enemyBase != null) {
                if (((GameState) this.handler).enemyBase.getTilePosition().equals(b.getTilePosition())) {
                    continue;
                }
            }
            valid.add(b);
        }
        if (valid.isEmpty()) {
            return State.FAILURE;
        }
        for (Unit u : ((GameState) this.handler).CSs) {
            if (u.getEnergy() == 200) {
                Random random = new Random();
                ((GameState) this.handler).checkScan = valid.get(random.nextInt(valid.size())).getTilePosition();
                return State.SUCCESS;
            }
        }
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        System.err.println(e);
        return State.ERROR;
    }
}
Also used : Random(java.util.Random) ArrayList(java.util.ArrayList) GameState(ecgberht.GameState) Unit(bwapi.Unit) BaseLocation(bwta.BaseLocation)

Example 28 with GameState

use of ecgberht.GameState in project Ecgberht by Jabbo16.

the class ChooseBuildingToHarass method execute.

@Override
public State execute() {
    try {
        if (((GameState) this.handler).chosenUnitToHarass != null) {
            return State.FAILURE;
        }
        for (EnemyBuilding u : ((GameState) this.handler).enemyBuildingMemory.values()) {
            if (((GameState) this.handler).enemyBase != null) {
                if (u.type.isBuilding()) {
                    if (BWTA.getRegion(u.pos).getCenter().equals(BWTA.getRegion(((GameState) this.handler).enemyBase.getPosition()).getCenter())) {
                        ((GameState) this.handler).chosenUnitToHarass = u.unit;
                        return State.SUCCESS;
                    }
                }
            }
        }
        if (((GameState) this.handler).chosenHarasser.isIdle()) {
            ((GameState) this.handler).workerIdle.add(((GameState) this.handler).chosenHarasser);
            ((GameState) this.handler).chosenHarasser.stop();
            ((GameState) this.handler).chosenHarasser = null;
            ((GameState) this.handler).chosenUnitToHarass = 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) EnemyBuilding(ecgberht.EnemyBuilding)

Example 29 with GameState

use of ecgberht.GameState in project Ecgberht by Jabbo16.

the class ChooseWorker method execute.

@Override
public State execute() {
    try {
        Unit closestWorker = null;
        int frame = ((GameState) this.handler).frameCount;
        Position chosen = ((GameState) this.handler).chosenPosition.toPosition();
        if (!((GameState) this.handler).workerIdle.isEmpty()) {
            for (Unit u : ((GameState) this.handler).workerIdle) {
                if (u.getLastCommandFrame() == frame) {
                    continue;
                }
                if ((closestWorker == null || u.getDistance(chosen) < closestWorker.getDistance(chosen))) {
                    closestWorker = u;
                }
            }
        }
        if (!((GameState) this.handler).workerMining.isEmpty()) {
            for (Unit u : ((GameState) this.handler).workerMining.keySet()) {
                if (u.getLastCommandFrame() == frame) {
                    continue;
                }
                if ((closestWorker == null || u.getDistance(chosen) < closestWorker.getDistance(chosen)) && !u.isCarryingMinerals()) {
                    closestWorker = u;
                }
            }
        }
        if (closestWorker != null) {
            ((GameState) this.handler).chosenWorker = 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 30 with GameState

use of ecgberht.GameState 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)

Aggregations

GameState (ecgberht.GameState)40 Unit (bwapi.Unit)36 Position (bwapi.Position)9 Pair (bwapi.Pair)6 TilePosition (bwapi.TilePosition)5 ArrayList (java.util.ArrayList)5 BaseLocation (bwta.BaseLocation)4 Squad (ecgberht.Squad)4 EnemyBuilding (ecgberht.EnemyBuilding)3 HashSet (java.util.HashSet)2 Game (bwapi.Game)1 Player (bwapi.Player)1 UnitCommand (bwapi.UnitCommand)1 Area (bwem.Area)1 Base (bwem.Base)1 Region (bwta.Region)1 Status (ecgberht.Squad.Status)1 UnitInfo (ecgberht.UnitInfo)1 Util (ecgberht.Util.Util)1 java.util (java.util)1