use of bwta.Region in project Ecgberht by Jabbo16.
the class CheckPerimeter method execute.
@Override
public State execute() {
try {
((GameState) this.handler).enemyInBase.clear();
((GameState) this.handler).defense = false;
List<Unit> enemyInvaders = new ArrayList<>();
enemyInvaders.addAll(((GameState) this.handler).enemyCombatUnitMemory);
for (EnemyBuilding u : ((GameState) this.handler).enemyBuildingMemory.values()) {
if (u.type.canAttack() || u.type == UnitType.Protoss_Pylon || u.type.canProduce() || u.type.isRefinery()) {
enemyInvaders.add(u.unit);
}
}
for (Unit u : enemyInvaders) {
if ((u.getType().canAttack() || u.getType() == UnitType.Protoss_Pylon) && u.getType() != UnitType.Zerg_Scourge && u.getType() != UnitType.Protoss_Corsair) {
for (Unit c : ((GameState) this.handler).CCs.values()) {
if (((GameState) this.handler).broodWarDistance(u.getPosition(), c.getPosition()) < 500) {
((GameState) this.handler).enemyInBase.add(u);
continue;
}
}
for (Unit c : ((GameState) this.handler).DBs.keySet()) {
if (((GameState) this.handler).broodWarDistance(u.getPosition(), c.getPosition()) < 200) {
((GameState) this.handler).enemyInBase.add(u);
continue;
}
}
for (Unit c : ((GameState) this.handler).SBs) {
if (((GameState) this.handler).broodWarDistance(u.getPosition(), c.getPosition()) < 200) {
((GameState) this.handler).enemyInBase.add(u);
continue;
}
}
for (Unit c : ((GameState) this.handler).MBs) {
if (((GameState) this.handler).broodWarDistance(u.getPosition(), c.getPosition()) < 200) {
((GameState) this.handler).enemyInBase.add(u);
continue;
}
}
}
}
boolean overlordCheck = true;
for (Unit u : ((GameState) this.handler).enemyInBase) {
if (u.getType().canAttack() || u.getType() == UnitType.Protoss_Shuttle || u.getType() == UnitType.Terran_Dropship) {
overlordCheck = false;
break;
}
}
if (!((GameState) this.handler).enemyInBase.isEmpty() && !overlordCheck) {
if ((((GameState) this.handler).getArmySize() >= 50 && ((GameState) this.handler).getArmySize() / ((GameState) this.handler).enemyInBase.size() > 10)) {
return State.FAILURE;
}
((GameState) this.handler).defense = true;
return State.SUCCESS;
}
int cFrame = ((GameState) this.handler).frameCount;
for (Unit u : ((GameState) this.handler).workerDefenders) {
if (u.getLastCommandFrame() == cFrame) {
continue;
}
Position closestCC = ((GameState) this.handler).getNearestCC(u.getPosition());
if (closestCC != null) {
if (!BWTA.getRegion(u.getPosition()).getCenter().equals(BWTA.getRegion(closestCC).getCenter())) {
u.move(closestCC);
}
}
}
for (Squad u : ((GameState) this.handler).squads.values()) {
if (u.status == Status.DEFENSE) {
Position closestCC = ((GameState) this.handler).getNearestCC(((GameState) this.handler).getSquadCenter(u));
if (closestCC != null) {
Region squad = BWTA.getRegion(((GameState) this.handler).getSquadCenter(u));
Region regCC = BWTA.getRegion(closestCC);
if (squad != null && regCC != null) {
if (!squad.getCenter().equals(regCC.getCenter())) {
if (!((GameState) this.handler).DBs.isEmpty() && ((GameState) this.handler).CCs.size() == 1) {
u.giveMoveOrder(((GameState) this.handler).DBs.keySet().iterator().next().getPosition());
} else {
u.giveMoveOrder(BWTA.getNearestChokepoint(((GameState) this.handler).getSquadCenter(u)).getCenter());
}
u.status = Status.IDLE;
u.attack = Position.None;
continue;
}
}
u.status = Status.IDLE;
u.attack = Position.None;
continue;
}
u.status = Status.IDLE;
u.attack = Position.None;
continue;
}
}
((GameState) this.handler).defense = false;
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
System.err.println(e);
return State.ERROR;
}
}
use of bwta.Region in project BWAPI4J by OpenBW.
the class MainTest method testBWTA.
private void testBWTA() throws AssertionError {
BWTA bwta = new BWTA();
bwta.analyze();
for (Region region : bwta.getRegions()) {
System.out.println(region);
for (Chokepoint choke : region.getChokepoints()) {
System.out.println(" " + choke);
}
}
TilePosition startLocation = this.bw.getInteractionHandler().self().getStartLocation();
logger.debug("start location tile: {}", startLocation);
Region startRegion = bwta.getRegion(startLocation);
logger.debug("start region: {}", startRegion);
}
use of bwta.Region in project Ecgberht by Jabbo16.
the class GameState method moveUnitFromChokeWhenExpand.
public void moveUnitFromChokeWhenExpand() {
try {
if (!squads.isEmpty() && chosenBaseLocation != null) {
Region chosenRegion = BWTA.getRegion(chosenBaseLocation);
if (chosenRegion != null) {
if (chosenRegion.getCenter().equals(naturalRegion.getCenter())) {
TilePosition mapCenter = new TilePosition(game.mapWidth(), game.mapHeight());
List<Chokepoint> cs = chosenRegion.getChokepoints();
Chokepoint closestChoke = null;
for (Chokepoint c : cs) {
if (!c.getCenter().toTilePosition().equals(this.closestChoke.getCenter().toTilePosition())) {
double aux = broodWarDistance(c.getCenter(), chosenBaseLocation.toPosition());
if (aux > 0.0) {
if (closestChoke == null || aux < broodWarDistance(closestChoke.getCenter(), mapCenter.toPosition())) {
closestChoke = c;
}
}
}
}
if (closestChoke != null) {
for (Squad s : squads.values()) {
if (s.status == Status.IDLE) {
s.giveAttackOrder(closestChoke.getCenter());
}
}
}
}
}
}
} catch (Exception e) {
System.err.println("MoveUnitFromChokeWhenExpand");
System.err.println(e);
}
}
use of bwta.Region in project Ecgberht by Jabbo16.
the class GameState method initClosestChoke.
public void initClosestChoke() {
List<BaseLocation> aux = BLs;
// aux.removeAll(blockedBLs);
Region naturalArea = aux.get(1).getRegion();
naturalRegion = naturalArea;
double distBest = Double.MAX_VALUE;
for (Chokepoint choke : naturalArea.getChokepoints()) {
double dist = BWTA.getGroundDistance(choke.getCenter().toTilePosition(), game.self().getStartLocation());
if (dist < distBest && dist > 0.0)
closestChoke = choke;
distBest = dist;
}
if (closestChoke != null) {
initAttackPosition = closestChoke.getCenter().toTilePosition();
initDefensePosition = closestChoke.getCenter().toTilePosition();
} else {
initAttackPosition = self.getStartLocation();
initDefensePosition = self.getStartLocation();
}
}
use of bwta.Region in project Ecgberht by Jabbo16.
the class GameState method printer.
public void printer() {
Integer counter = 0;
for (BaseLocation b : BLs) {
game.drawTextMap(b.getPosition(), counter.toString());
counter++;
}
int apm = game.getAPM(false);
if (apm > 9000 && !firstAPM) {
game.sendText("My APM is over 9000!");
firstAPM = true;
}
for (Vulture vulture : agents) {
game.drawTextMap(vulture.unit.getPosition(), vulture.statusToString());
}
game.drawTextScreen(10, 65, Utils.formatText("MGPF: ", Utils.White) + Utils.formatText(String.valueOf(getMineralRate()), Utils.White));
game.drawTextScreen(10, 80, Utils.formatText("Strategy: ", Utils.White) + Utils.formatText(strat.name, Utils.White));
game.drawTextScreen(10, 50, Utils.formatText("APM: ", Utils.White) + Utils.formatText(String.valueOf(apm), Utils.White));
if (closestChoke != null) {
game.drawTextMap(closestChoke.getCenter(), "Choke");
}
if (chosenBuilderBL != null) {
game.drawTextMap(chosenBuilderBL.getPosition(), "BuilderBL");
print(chosenBuilderBL, Color.Blue);
}
if (chosenHarasser != null) {
game.drawTextMap(chosenHarasser.getPosition(), "Harasser");
print(chosenHarasser, Color.Blue);
}
if (chosenBaseLocation != null) {
print(chosenBaseLocation, UnitType.Terran_Command_Center, Color.Cyan);
}
for (Pair<Unit, Pair<UnitType, TilePosition>> u : workerBuild) {
game.drawTextMap(u.first.getPosition(), "ChosenBuilder");
print(u.second.second, u.second.first, Color.Teal);
}
if (chosenUnitToHarass != null) {
print(chosenUnitToHarass, Color.Red);
game.drawTextMap(chosenUnitToHarass.getPosition(), "UnitToHarass");
}
for (Pair<Unit, Unit> r : repairerTask) {
print(r.first, Color.Yellow);
game.drawTextMap(r.first.getPosition(), "Repairer");
}
game.drawTextScreen(10, 5, Utils.formatText(self.getName(), Utils.Green) + Utils.formatText(" vs ", Utils.Yellow) + Utils.formatText(game.enemy().getName(), Utils.Red));
if (chosenScout != null) {
game.drawTextMap(chosenScout.getPosition(), "Scouter");
print(chosenScout, Color.Purple);
game.drawTextScreen(10, 20, Utils.formatText("Scouting: ", Utils.White) + Utils.formatText("True", Utils.Green));
} else {
game.drawTextScreen(10, 20, Utils.formatText("Scouting: ", Utils.White) + Utils.formatText("False", Utils.Red));
}
if (enemyBase != null) {
game.drawTextScreen(10, 35, Utils.formatText("Enemy Base Found: ", Utils.White) + Utils.formatText("True", Utils.Green));
} else {
game.drawTextScreen(10, 35, Utils.formatText("Enemy Base Found: ", Utils.White) + Utils.formatText("False", Utils.Red));
}
// }
if (chosenRepairer != null) {
game.drawTextMap(chosenRepairer.getPosition(), "ChosenRepairer");
}
// if(enemyCombatUnitMemory.size()>0) {
// for(Unit u : enemyCombatUnitMemory) {
// game.drawTextMap(u.getPosition(), u.getType().toString());
// print(u,Color.Red);
// }
// }
List<Region> regions = BWTA.getRegions();
for (Region reg : regions) {
List<Chokepoint> ch = reg.getChokepoints();
for (Chokepoint c : ch) {
Pair<Position, Position> lados = c.getSides();
game.drawLineMap(lados.first, lados.second, Color.Green);
}
}
for (Unit u : CCs.values()) {
print(u, Color.Yellow);
game.drawCircleMap(u.getPosition(), 500, Color.Orange);
}
for (Unit u : DBs.keySet()) {
game.drawCircleMap(u.getPosition(), 300, Color.Orange);
}
for (Unit u : workerIdle) {
print(u, Color.Green);
}
for (Unit u : workerDefenders) {
print(u, Color.Purple);
game.drawTextMap(u.getPosition(), "Spartan");
}
for (Entry<String, Squad> s : squads.entrySet()) {
Position centro = getSquadCenter(s.getValue());
game.drawCircleMap(centro, 80, Color.Green);
game.drawTextMap(centro, s.getKey());
}
if (enemyRace == Race.Zerg && EI.naughty) {
game.drawTextScreen(10, 95, Utils.formatText("Naughty Zerg: ", Utils.White) + Utils.formatText("yes", Utils.Green));
}
for (Unit m : mineralsAssigned.keySet()) {
print(m, Color.Cyan);
game.drawTextMap(m.getPosition(), mineralsAssigned.get(m).toString());
}
}
Aggregations