use of ecgberht.GameState 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;
}
}
use of ecgberht.GameState in project Ecgberht by Jabbo16.
the class ChooseScout method execute.
@Override
public State execute() {
try {
for (Unit u : ((GameState) this.handler).workerIdle) {
((GameState) this.handler).chosenScout = u;
((GameState) this.handler).workerIdle.remove(u);
break;
}
if (((GameState) this.handler).chosenScout == null) {
for (Unit u : ((GameState) this.handler).workerMining.keySet()) {
if (!u.isCarryingMinerals()) {
((GameState) this.handler).chosenScout = u;
((GameState) this.handler).workerMining.remove(u);
}
break;
}
}
if (((GameState) this.handler).chosenScout != null) {
return State.SUCCESS;
}
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
System.err.println(e);
return State.ERROR;
}
}
use of ecgberht.GameState in project Ecgberht by Jabbo16.
the class ChoosePosition method execute.
@Override
public State execute() {
try {
Game juego = ((GameState) this.handler).getGame();
Player jugador = ((GameState) this.handler).getPlayer();
TilePosition origin = null;
if (((GameState) this.handler).chosenToBuild.isRefinery()) {
if (!((GameState) this.handler).refineriesAssigned.isEmpty()) {
for (Pair<Pair<Unit, Integer>, Boolean> g : ((GameState) this.handler).refineriesAssigned) {
if (!g.second) {
((GameState) this.handler).chosenPosition = g.first.first.getTilePosition();
return State.SUCCESS;
}
}
}
} else {
if (!((GameState) this.handler).workerBuild.isEmpty()) {
for (Pair<Unit, Pair<UnitType, TilePosition>> w : ((GameState) this.handler).workerBuild) {
((GameState) this.handler).testMap.updateMap(w.second.second, w.second.first, false);
}
}
if (!((GameState) this.handler).chosenToBuild.equals(UnitType.Terran_Bunker) && !((GameState) this.handler).chosenToBuild.equals(UnitType.Terran_Missile_Turret)) {
if (((GameState) this.handler).strat.proxy && ((GameState) this.handler).chosenToBuild == UnitType.Terran_Barracks) {
origin = new TilePosition(((GameState) this.handler).getGame().mapWidth() / 2, ((GameState) this.handler).getGame().mapHeight() / 2);
} else {
// origin = BWTA.getRegion(jugador.getStartLocation()).getCenter().toTilePosition();
origin = jugador.getStartLocation();
}
} else {
if (((GameState) this.handler).chosenToBuild.equals(UnitType.Terran_Missile_Turret)) {
if (((GameState) this.handler).DBs.isEmpty()) {
origin = BWTA.getNearestChokepoint(jugador.getStartLocation()).getCenter().toTilePosition();
} else {
for (Unit b : ((GameState) this.handler).DBs.keySet()) {
origin = b.getTilePosition();
break;
}
}
} else {
if (((GameState) this.handler).EI.naughty && ((GameState) this.handler).enemyRace == Race.Zerg) {
TilePosition raxTile = ((GameState) this.handler).MBs.iterator().next().getTilePosition();
origin = ((GameState) this.handler).testMap.findBunkerPositionAntiPool(raxTile.toPosition(), ((GameState) this.handler).closestChoke);
if (origin != null) {
((GameState) this.handler).testMap = ((GameState) this.handler).map.clone();
((GameState) this.handler).chosenPosition = origin;
return State.SUCCESS;
} else {
origin = ((GameState) this.handler).getBunkerPositionAntiPool();
if (origin != null) {
((GameState) this.handler).testMap = ((GameState) this.handler).map.clone();
((GameState) this.handler).chosenPosition = origin;
return State.SUCCESS;
} else {
origin = raxTile;
}
}
} else {
if (((GameState) this.handler).Ts.isEmpty()) {
if (((GameState) this.handler).closestChoke != null) {
origin = ((GameState) this.handler).testMap.findBunkerPosition(((GameState) this.handler).closestChoke);
if (origin != null) {
((GameState) this.handler).testMap = ((GameState) this.handler).map.clone();
((GameState) this.handler).chosenPosition = origin;
return State.SUCCESS;
} else {
origin = ((GameState) this.handler).closestChoke.getCenter().toTilePosition();
}
}
// else {
// origin = BWTA.getNearestChokepoint(jugador.getStartLocation()).getCenter().toTilePosition();
// }
} else {
for (Unit b : ((GameState) this.handler).Ts) {
origin = b.getTilePosition();
break;
}
}
}
}
}
TilePosition posicion = ((GameState) this.handler).testMap.findPosition(((GameState) this.handler).chosenToBuild, origin);
((GameState) this.handler).testMap = ((GameState) this.handler).map.clone();
if (posicion != null) {
((GameState) this.handler).chosenPosition = posicion;
return State.SUCCESS;
}
}
TilePosition posicion = juego.getBuildLocation(((GameState) this.handler).chosenToBuild, BWTA.getRegion(jugador.getStartLocation()).getCenter().toTilePosition(), 500);
if (posicion != null) {
if (juego.canBuildHere(posicion, ((GameState) this.handler).chosenToBuild)) {
((GameState) this.handler).chosenPosition = posicion;
return State.SUCCESS;
}
}
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
System.err.println(e);
return State.ERROR;
}
}
use of ecgberht.GameState in project Ecgberht by Jabbo16.
the class ChooseRefinery method execute.
@Override
public State execute() {
try {
if (((GameState) this.handler).getPlayer().supplyUsed() < ((GameState) this.handler).strat.supplyForFirstRefinery || ((GameState) this.handler).getCash().second >= 300) {
return State.FAILURE;
}
if (((GameState) this.handler).refineriesAssigned.size() == 1) {
boolean found = false;
for (Pair<Unit, Pair<UnitType, TilePosition>> w : ((GameState) this.handler).workerBuild) {
if (w.second.first == UnitType.Terran_Barracks) {
found = true;
break;
}
}
for (Pair<Unit, Unit> w : ((GameState) this.handler).workerTask) {
if (w.second.getType() == UnitType.Terran_Barracks) {
found = true;
break;
}
}
if (((GameState) this.handler).MBs.isEmpty() && found == false) {
return State.FAILURE;
}
}
int count = 0;
Unit geyser = null;
for (Pair<Pair<Unit, Integer>, Boolean> r : ((GameState) this.handler).refineriesAssigned) {
if (r.second) {
count++;
} else {
geyser = r.first.first;
}
}
if (count == ((GameState) this.handler).refineriesAssigned.size()) {
return State.FAILURE;
}
for (Pair<Unit, Pair<UnitType, TilePosition>> w : ((GameState) this.handler).workerBuild) {
if (w.second.first == UnitType.Terran_Refinery) {
return State.FAILURE;
}
}
for (Pair<Unit, Unit> w : ((GameState) this.handler).workerTask) {
if (w.second.getType() == UnitType.Terran_Refinery && w.second.getPosition().equals(geyser.getPosition())) {
return State.FAILURE;
}
}
((GameState) this.handler).chosenToBuild = UnitType.Terran_Refinery;
return State.SUCCESS;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
System.err.println(e);
return State.ERROR;
}
}
use of ecgberht.GameState in project Ecgberht by Jabbo16.
the class CheckBuildingFlames method execute.
@Override
public State execute() {
try {
boolean isBeingRepaired = false;
for (Unit w : ((GameState) this.handler).DBs.keySet()) {
if (w.getType().maxHitPoints() != w.getHitPoints()) {
for (Pair<Unit, Unit> r : ((GameState) this.handler).repairerTask) {
if (w.equals(r.second)) {
isBeingRepaired = true;
}
}
if (!isBeingRepaired) {
((GameState) this.handler).chosenBuildingRepair = w;
return State.SUCCESS;
}
}
}
isBeingRepaired = false;
for (Unit b : ((GameState) this.handler).Ts) {
if (b.getType().maxHitPoints() != b.getHitPoints()) {
for (Pair<Unit, Unit> r : ((GameState) this.handler).repairerTask) {
if (b.equals(r.second)) {
isBeingRepaired = true;
}
}
if (!isBeingRepaired) {
((GameState) this.handler).chosenBuildingRepair = b;
return State.SUCCESS;
}
}
}
isBeingRepaired = false;
for (Unit b : ((GameState) this.handler).MBs) {
if (b.getType().maxHitPoints() != b.getHitPoints()) {
for (Pair<Unit, Unit> r : ((GameState) this.handler).repairerTask) {
if (b.equals(r.second)) {
isBeingRepaired = true;
}
}
if (!isBeingRepaired) {
((GameState) this.handler).chosenBuildingRepair = b;
return State.SUCCESS;
}
}
}
isBeingRepaired = false;
for (Unit b : ((GameState) this.handler).Fs) {
if (b.getType().maxHitPoints() != b.getHitPoints()) {
for (Pair<Unit, Unit> r : ((GameState) this.handler).repairerTask) {
if (b.equals(r.second)) {
isBeingRepaired = true;
}
}
if (!isBeingRepaired) {
((GameState) this.handler).chosenBuildingRepair = b;
return State.SUCCESS;
}
}
}
isBeingRepaired = false;
for (Unit b : ((GameState) this.handler).UBs) {
if (b.getType().maxHitPoints() != b.getHitPoints()) {
for (Pair<Unit, Unit> r : ((GameState) this.handler).repairerTask) {
if (b.equals(r.second)) {
isBeingRepaired = true;
}
}
if (!isBeingRepaired) {
((GameState) this.handler).chosenBuildingRepair = b;
return State.SUCCESS;
}
}
}
isBeingRepaired = false;
for (Unit b : ((GameState) this.handler).SBs) {
if (b.getType().maxHitPoints() != b.getHitPoints()) {
for (Pair<Unit, Unit> r : ((GameState) this.handler).repairerTask) {
if (b.equals(r.second)) {
isBeingRepaired = true;
}
}
if (!isBeingRepaired) {
((GameState) this.handler).chosenBuildingRepair = b;
return State.SUCCESS;
}
}
}
isBeingRepaired = false;
for (Unit b : ((GameState) this.handler).CCs.values()) {
if (b.getType().maxHitPoints() != b.getHitPoints()) {
for (Pair<Unit, Unit> r : ((GameState) this.handler).repairerTask) {
if (b.equals(r.second)) {
isBeingRepaired = true;
}
}
if (!isBeingRepaired) {
((GameState) this.handler).chosenBuildingRepair = b;
return State.SUCCESS;
}
}
}
isBeingRepaired = false;
for (Unit b : ((GameState) this.handler).CSs) {
if (b.getType().maxHitPoints() != b.getHitPoints()) {
for (Pair<Unit, Unit> r : ((GameState) this.handler).repairerTask) {
if (b.equals(r.second)) {
isBeingRepaired = true;
}
}
if (!isBeingRepaired) {
((GameState) this.handler).chosenBuildingRepair = b;
return State.SUCCESS;
}
}
}
isBeingRepaired = false;
for (Unit b : ((GameState) this.handler).Ps) {
if (b.getType().maxHitPoints() != b.getHitPoints()) {
for (Pair<Unit, Unit> r : ((GameState) this.handler).repairerTask) {
if (b.equals(r.second)) {
isBeingRepaired = true;
}
}
if (!isBeingRepaired) {
((GameState) this.handler).chosenBuildingRepair = b;
return State.SUCCESS;
}
}
}
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
System.err.println(e);
return State.ERROR;
}
}
Aggregations