use of bwapi.TilePosition in project Ecgberht by Jabbo16.
the class ChooseBaseLocation method execute.
@Override
public State execute() {
try {
if (((GameState) this.handler).chosenBaseLocation != null) {
return State.SUCCESS;
}
TilePosition main = null;
if (((GameState) this.handler).MainCC != null) {
main = ((GameState) this.handler).MainCC.getTilePosition();
} else {
main = ((GameState) this.handler).getPlayer().getStartLocation();
}
List<BaseLocation> valid = new ArrayList<>();
for (BaseLocation b : ((GameState) this.handler).BLs) {
if (!((GameState) this.handler).CCs.containsKey(b.getRegion().getCenter()) && BWTA.isConnected(b.getTilePosition(), main)) {
valid.add(b);
}
}
List<BaseLocation> remove = new ArrayList<>();
for (BaseLocation b : valid) {
for (Unit u : ((GameState) this.handler).enemyCombatUnitMemory) {
if (BWTA.getRegion(u.getPosition()) == null || !u.getType().canAttack() || u.getType().isWorker()) {
continue;
}
if (BWTA.getRegion(u.getPosition()).getCenter().equals(BWTA.getRegion(b.getPosition()).getCenter())) {
remove.add(b);
break;
}
}
for (EnemyBuilding u : ((GameState) this.handler).enemyBuildingMemory.values()) {
if (BWTA.getRegion(u.pos) == null) {
continue;
}
if (BWTA.getRegion(u.pos).getCenter().equals(BWTA.getRegion(b.getPosition()).getCenter())) {
remove.add(b);
break;
}
}
}
valid.removeAll(remove);
if (valid.isEmpty()) {
System.out.println("wut");
((GameState) this.handler).chosenBaseLocation = null;
((GameState) this.handler).movingToExpand = false;
((GameState) this.handler).chosenBuilderBL.stop();
((GameState) this.handler).workerIdle.add(((GameState) this.handler).chosenBuilderBL);
((GameState) this.handler).chosenBuilderBL = null;
((GameState) this.handler).expanding = false;
((GameState) this.handler).deltaCash.first -= UnitType.Terran_Command_Center.mineralPrice();
((GameState) this.handler).deltaCash.second -= UnitType.Terran_Command_Center.gasPrice();
return State.FAILURE;
}
((GameState) this.handler).chosenBaseLocation = valid.get(0).getTilePosition();
// System.out.println("----------------------------");
return State.SUCCESS;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
System.err.println(e);
return State.ERROR;
}
}
use of bwapi.TilePosition in project Ecgberht by Jabbo16.
the class ChooseAttackPosition method execute.
@Override
public State execute() {
try {
if (((GameState) this.handler).squads.isEmpty()) {
return State.FAILURE;
}
for (Squad u : ((GameState) this.handler).squads.values()) {
Pair<Integer, Integer> p = ((GameState) this.handler).inMap.getPosition(((GameState) this.handler).getSquadCenter(u).toTilePosition(), true);
if (p.first != null && p.second != null) {
if (!((GameState) this.handler).firstProxyBBS && ((GameState) this.handler).strat.name == "ProxyBBS") {
((GameState) this.handler).firstProxyBBS = true;
((GameState) this.handler).getGame().sendText("Get ready for a party in your house!");
}
u.giveAttackOrder(new TilePosition(p.second, p.first).toPosition());
u.status = Status.ATTACK;
continue;
} else if (((GameState) this.handler).enemyBase != null) {
((GameState) this.handler).attackPosition = ((GameState) this.handler).enemyBase.getPosition();
continue;
} else {
u.status = Status.IDLE;
continue;
}
}
return State.SUCCESS;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
System.err.println(e);
return State.ERROR;
}
}
use of bwapi.TilePosition in project Ecgberht by Jabbo16.
the class BaseLocationComparator method compare.
@Override
public int compare(BaseLocation a, BaseLocation b) {
try {
TilePosition start = null;
if (!enemy) {
if (getGs().MainCC != null) {
start = getGs().MainCC.getTilePosition();
}
if (start == null) {
start = getGs().getPlayer().getStartLocation();
}
BaseLocation closestBase = BWTA.getNearestBaseLocation(start);
if (closestBase != null) {
if (BWTA.getNearestBaseLocation(start).getTilePosition().equals(a.getTilePosition())) {
return -1;
}
if (BWTA.getNearestBaseLocation(start).getTilePosition().equals(b.getTilePosition())) {
return 1;
}
}
if (a.isIsland()) {
return 1;
}
if (b.isIsland()) {
return -1;
}
double distA = getGs().getGroundDistance(a.getTilePosition(), start);
double distB = getGs().getGroundDistance(b.getTilePosition(), start);
if (distA == 0.0 && distB > 0.0) {
return 1;
}
if (distB == 0.0 && distA > 0.0) {
return -1;
}
if (a.isMineralOnly() && !b.isMineralOnly()) {
return 1;
}
if (b.isMineralOnly() && !a.isMineralOnly()) {
return -1;
}
if (distA < distB && distA > 0.0) {
if (getGs().blockedBLs.contains(a)) {
return 1;
}
return -1;
} else {
if (distA > distB && distB > 0.0) {
if (getGs().blockedBLs.contains(b)) {
return -1;
}
return 1;
}
}
return 1;
} else {
if (getGs().enemyBase != null) {
start = getGs().enemyBase.getTilePosition();
} else {
return -1;
}
if (a.isIsland()) {
return 1;
}
if (b.isIsland()) {
return -1;
}
double distA = getGs().getGroundDistance(a.getTilePosition(), start);
double distB = getGs().getGroundDistance(b.getTilePosition(), start);
if (distA == 0.0 && distB > 0.0) {
return 1;
}
if (distB == 0.0 && distA > 0.0) {
return -1;
}
if (a.isMineralOnly() && !b.isMineralOnly()) {
return 1;
}
if (b.isMineralOnly() && !a.isMineralOnly()) {
return -1;
}
if (distA < distB && distA > 0.0) {
if (getGs().blockedBLs.contains(a)) {
return 1;
}
return 1;
} else {
if (distA > distB && distB > 0.0) {
if (getGs().blockedBLs.contains(b)) {
return -1;
}
return 1;
}
}
return 1;
}
} catch (Exception e) {
System.err.println("Sorter");
System.err.println(e);
}
return 0;
}
use of bwapi.TilePosition in project Ecgberht by Jabbo16.
the class InfluenceMap method updateMap.
public void updateMap(Unit arg0, boolean Destroyed) {
int influence = 0;
UnitType type = arg0.getType();
TilePosition tile = arg0.getTilePosition().makeValid();
if (type.isBuilding()) {
if (type.canAttack() || type.equals(UnitType.Terran_Bunker)) {
influence = defensivo;
} else {
if (type.canProduce()) {
influence = ofensivo;
} else {
influence = neutro;
}
}
} else {
if (type.isFlyer()) {
influence = volador;
} else if (type.isMechanical()) {
influence = maquina;
} else {
influence = biologica;
}
}
if (Destroyed) {
influence *= -1;
}
if (arg0.getPlayer().isEnemy(self)) {
influence *= -1;
}
updateCellInfluence(new Pair<Point, Integer>(new Point(tile.getY(), tile.getX()), influence), type.isBuilding());
}
use of bwapi.TilePosition 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;
}
}
Aggregations