use of org.openbw.bwapi4j.Position in project Ecgberht by Jabbo16.
the class CheckResourcesIsland method execute.
@Override
public State execute() {
try {
MutablePair<Integer, Integer> cash = gameState.getCash();
Worker chosen = gameState.chosenWorkerDrop;
UnitType chosenType = UnitType.Terran_Command_Center;
TilePosition start = chosen.getTilePosition();
TilePosition end = gameState.chosenIsland.getLocation();
Position realEnd = Util.getUnitCenterPosition(end.toPosition(), chosenType);
if (cash.first + gameState.getMineralsWhenReaching(start, realEnd.toTilePosition()) >= chosenType.mineralPrice() + gameState.deltaCash.first) {
return State.SUCCESS;
}
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
e.printStackTrace();
return State.ERROR;
}
}
use of org.openbw.bwapi4j.Position in project Ecgberht by Jabbo16.
the class ChooseIsland method execute.
@Override
public State execute() {
try {
Base chosen = null;
double distMax = Double.MAX_VALUE;
Position drop = gameState.chosenDropShip.unit.getPosition();
for (Base b : gameState.islandBases) {
if (gameState.islandCCs.containsKey(b))
continue;
double dist = Util.broodWarDistance(b.getLocation().toPosition(), drop);
if (dist < distMax) {
distMax = dist;
chosen = b;
}
}
if (chosen != null) {
gameState.chosenIsland = chosen;
return State.SUCCESS;
}
gameState.chosenDropShip = null;
gameState.chosenWorker = null;
gameState.chosenIsland = null;
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
e.printStackTrace();
return State.ERROR;
}
}
use of org.openbw.bwapi4j.Position in project Ecgberht by Jabbo16.
the class ChooseRepairer method execute.
@Override
public State execute() {
try {
SCV closestWorker = null;
Position chosen = gameState.chosenUnitRepair.getPosition();
int frame = gameState.frameCount;
for (Worker u : gameState.workerIdle) {
if (u.getLastCommandFrame() == frame)
continue;
if ((closestWorker == null || u.getDistance(chosen) < closestWorker.getDistance(chosen))) {
closestWorker = (SCV) u;
}
}
for (Worker u : gameState.workerMining.keySet()) {
if (u.getLastCommandFrame() == frame)
continue;
if ((closestWorker == null || u.getDistance(chosen) < closestWorker.getDistance(chosen)) && !u.isCarryingMinerals()) {
closestWorker = (SCV) u;
}
}
if (closestWorker != null) {
gameState.chosenRepairer = closestWorker;
return State.SUCCESS;
}
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
e.printStackTrace();
return State.ERROR;
}
}
use of org.openbw.bwapi4j.Position in project Ecgberht by Jabbo16.
the class ChooseWorkerDrop method execute.
@Override
public State execute() {
try {
Worker closestWorker = null;
int frame = gameState.frameCount;
Position chosen = gameState.chosenDropShip.unit.getPosition();
if (!gameState.workerIdle.isEmpty()) {
for (Worker u : gameState.workerIdle) {
if (u.isCarryingMinerals())
continue;
if (u.getLastCommandFrame() == frame)
continue;
if ((closestWorker == null || u.getDistance(chosen) < closestWorker.getDistance(chosen))) {
closestWorker = u;
}
}
}
if (!gameState.workerMining.isEmpty()) {
for (Worker u : gameState.workerMining.keySet()) {
if (u.isCarryingMinerals())
continue;
if (u.getLastCommandFrame() == frame)
continue;
if ((closestWorker == null || u.getDistance(chosen) < closestWorker.getDistance(chosen)) && !u.isCarryingMinerals()) {
closestWorker = u;
}
}
}
if (closestWorker != null) {
gameState.chosenWorker = closestWorker;
return State.SUCCESS;
}
gameState.chosenDropShip = null;
gameState.chosenWorker = null;
gameState.chosenIsland = null;
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
e.printStackTrace();
return State.ERROR;
}
}
use of org.openbw.bwapi4j.Position in project Ecgberht by Jabbo16.
the class SimulationTheory method drawCluster.
/**
* Draws a cluster on the screen
*
* @param c The cluster to be drawn
* @param ally If true draws the cluster using green lines otherwise red lines
* @param id Cluster identifier
*/
private void drawCluster(Cluster c, boolean ally, int id) {
Color color = Color.RED;
if (ally)
color = Color.GREEN;
Position centroid = new Position((int) c.modeX, (int) c.modeY);
getGs().getGame().getMapDrawer().drawCircleMap(centroid, 4, color, true);
// getGs().getGame().getMapDrawer().drawTextMap(centroid.add(new Position(0, 5)), ColorUtil.formatText(Integer.toString(id), ColorUtil.White));
for (UnitInfo u : c.units) getGs().getGame().getMapDrawer().drawLineMap(u.lastPosition, centroid, color);
}
Aggregations