use of bwapi.Pair in project Ecgberht by Jabbo16.
the class InfluenceMap method getPosition.
public Pair<Integer, Integer> getPosition(TilePosition start, boolean attack) {
double count = 0;
int sX = start.getX();
int sY = start.getY();
Pair<Integer, Integer> p = new Pair<Integer, Integer>();
for (int x = 0; x < alto; x++) {
for (int y = 0; y < ancho; y++) {
if (mapa[x][y] < count) {
if (attack) {
if (fixMapa(x, y)) {
continue;
}
}
count = mapa[x][y] / Math.pow(1 + Math.sqrt(Math.pow(x - sY, 2) + Math.pow(y - sX, 2)), 2);
p.first = x;
p.second = y;
}
}
}
return p;
}
use of bwapi.Pair 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;
}
}
use of bwapi.Pair 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;
}
}
Aggregations