Search in sources :

Example 31 with GameState

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

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

Example 33 with GameState

use of ecgberht.GameState in project Ecgberht by Jabbo16.

the class ChooseMachineShop method execute.

@Override
public State execute() {
    try {
        if (!((GameState) this.handler).Fs.isEmpty()) {
            for (Unit c : ((GameState) this.handler).Fs) {
                if (!c.isTraining() && c.getAddon() == null) {
                    ((GameState) this.handler).chosenBuildingAddon = c;
                    ((GameState) this.handler).chosenAddon = UnitType.Terran_Machine_Shop;
                    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)

Example 34 with GameState

use of ecgberht.GameState in project Ecgberht by Jabbo16.

the class SendScout method execute.

@Override
public State execute() {
    try {
        if (((GameState) this.handler).enemyBase == null) {
            if (!((GameState) this.handler).ScoutSLs.isEmpty()) {
                List<BaseLocation> aux = new ArrayList<BaseLocation>();
                for (BaseLocation b : ((GameState) this.handler).ScoutSLs) {
                    if (BWTA.isConnected(b.getTilePosition(), ((GameState) this.handler).chosenScout.getTilePosition())) {
                        if (((GameState) this.handler).chosenScout.move(b.getPosition().makeValid())) {
                            return State.SUCCESS;
                        }
                    } else {
                        aux.add(b);
                    }
                }
                ((GameState) this.handler).ScoutSLs.removeAll(aux);
            }
        }
        ((GameState) this.handler).workerIdle.add(((GameState) this.handler).chosenScout);
        ((GameState) this.handler).chosenScout.stop();
        ((GameState) this.handler).chosenScout = null;
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        System.err.println(e);
        return State.ERROR;
    }
}
Also used : ArrayList(java.util.ArrayList) GameState(ecgberht.GameState) BaseLocation(bwta.BaseLocation)

Example 35 with GameState

use of ecgberht.GameState in project Ecgberht by Jabbo16.

the class ChooseMarine method execute.

@Override
public State execute() {
    try {
        if (!((GameState) this.handler).MBs.isEmpty()) {
            for (Unit b : ((GameState) this.handler).MBs) {
                if (!b.isTraining()) {
                    ((GameState) this.handler).chosenUnit = UnitType.Terran_Marine;
                    ((GameState) this.handler).chosenBuilding = 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

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