use of bwem.Area in project Ecgberht by Jabbo16.
the class CheckMineralWalk method getCloserMineral.
private MineralPatch getCloserMineral() {
double bestDist = Double.MAX_VALUE;
MineralPatch closerMineral = null;
for (MineralPatch mineralPatch : gameState.walkingMinerals) {
if (!mineralPatch.isVisible() || gameState.chosenScout.getDistance(mineralPatch) <= 32 * 4)
continue;
double dist = mineralPatch.getDistance(gameState.scoutSLs.iterator().next().getLocation().toPosition());
if (dist > gameState.chosenScout.getDistance(gameState.scoutSLs.iterator().next().getLocation().toPosition()))
continue;
Area mineralArea = gameState.bwem.getMap().getArea(mineralPatch.getTilePosition());
Area workerArea = gameState.bwem.getMap().getArea(gameState.chosenScout.getTilePosition());
if (mineralPatch.equals(movingMineral) && mineralArea != null && mineralArea.equals(workerArea))
continue;
if (dist < bestDist) {
bestDist = dist;
closerMineral = mineralPatch;
}
}
return closerMineral;
}
use of bwem.Area in project Ecgberht by Jabbo16.
the class CheckPerimeter method execute.
@Override
public State execute() {
try {
gameState.enemyInBase.clear();
gameState.defense = false;
Set<Unit> enemyInvaders = new TreeSet<>(gameState.enemyCombatUnitMemory);
for (UnitInfo u : gameState.unitStorage.getEnemyUnits().values().stream().filter(u -> u.unitType.isBuilding()).collect(Collectors.toSet())) {
if (u.unitType.canAttack() || u.unitType == UnitType.Protoss_Pylon || u.unitType.canProduce() || u.unitType.isRefinery()) {
enemyInvaders.add(u.unit);
}
}
for (Unit u : enemyInvaders) {
UnitType uType = u.getType();
if (u instanceof Building || ((uType.canAttack() || uType.isSpellcaster() || u instanceof Loadable) && uType != UnitType.Zerg_Scourge && uType != UnitType.Terran_Valkyrie && uType != UnitType.Protoss_Corsair && !(u instanceof Overlord))) {
Area enemyArea = gameState.bwem.getMap().getArea(u.getTilePosition());
if (enemyArea != null) {
Area myMainArea = gameState.mainCC != null ? gameState.mainCC.first.getArea() : null;
Area myNatArea = gameState.naturalArea;
for (Base b : gameState.CCs.keySet()) {
if (!b.getArea().equals(enemyArea))
continue;
if ((myMainArea != null && !b.getArea().equals(myMainArea) && (myNatArea != null && !b.getArea().equals(myNatArea))))
continue;
gameState.enemyInBase.add(u);
break;
}
}
for (Map.Entry<SCV, Building> c : gameState.workerTask.entrySet()) {
int dist = c.getValue() instanceof CommandCenter ? 500 : 200;
if (Util.broodWarDistance(u.getPosition(), c.getValue().getPosition()) <= dist) {
gameState.enemyInBase.add(u);
break;
}
}
for (Unit c : gameState.CCs.values()) {
if (Util.broodWarDistance(u.getPosition(), c.getPosition()) <= 500) {
gameState.enemyInBase.add(u);
break;
}
}
for (Unit c : gameState.DBs.keySet()) {
if (Util.broodWarDistance(u.getPosition(), c.getPosition()) <= 200) {
gameState.enemyInBase.add(u);
break;
}
}
for (Unit c : gameState.SBs) {
if (Util.broodWarDistance(u.getPosition(), c.getPosition()) <= 200) {
gameState.enemyInBase.add(u);
break;
}
}
for (ResearchingFacility c : gameState.UBs) {
if (Util.broodWarDistance(u.getPosition(), c.getPosition()) <= 200) {
gameState.enemyInBase.add(u);
break;
}
}
if (!gameState.getStrat().name.equals("ProxyBBS") && !gameState.getStrat().name.equals("ProxyEightRax")) {
for (Unit c : gameState.MBs) {
if (Util.broodWarDistance(u.getPosition(), c.getPosition()) <= 200) {
gameState.enemyInBase.add(u);
break;
}
}
}
}
}
if (!gameState.enemyInBase.isEmpty()) {
/*if ((((GameState) gameState).getArmySize() >= 50 && ((GameState) gameState).getArmySize() / ((GameState) gameState).enemyInBase.size() > 10)) {
return State.FAILURE;
}*/
gameState.defense = true;
return State.SUCCESS;
}
int cFrame = gameState.frameCount;
List<Worker> toDelete = new ArrayList<>();
for (Worker u : gameState.workerDefenders.keySet()) {
if (u.getLastCommandFrame() == cFrame)
continue;
Position closestDefense;
if (gameState.learningManager.isNaughty()) {
if (!gameState.DBs.isEmpty()) {
closestDefense = gameState.DBs.keySet().iterator().next().getPosition();
u.move(closestDefense);
toDelete.add(u);
continue;
}
}
closestDefense = gameState.getNearestCC(u.getPosition(), false);
if (closestDefense != null) {
u.move(closestDefense);
toDelete.add(u);
}
}
for (Worker u : toDelete) {
u.stop(false);
gameState.workerDefenders.remove(u);
gameState.workerIdle.add(u);
}
for (Squad u : gameState.sqManager.squads.values()) {
if (u.status == Status.DEFENSE) {
Position closestCC = gameState.getNearestCC(u.getSquadCenter(), false);
if (closestCC != null) {
Area squad = gameState.bwem.getMap().getArea(u.getSquadCenter().toTilePosition());
Area regCC = gameState.bwem.getMap().getArea(closestCC.toTilePosition());
if (squad != null && regCC != null) {
if (!squad.equals(regCC)) {
if (!gameState.DBs.isEmpty() && gameState.CCs.size() == 1) {
u.giveMoveOrder(gameState.DBs.keySet().iterator().next().getPosition());
} else {
u.giveMoveOrder(Util.getClosestChokepoint(u.getSquadCenter()).getCenter().toPosition());
}
u.status = Status.IDLE;
u.attack = null;
continue;
}
}
u.status = Status.IDLE;
u.attack = null;
continue;
}
u.status = Status.IDLE;
u.attack = null;
}
}
gameState.defense = false;
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
e.printStackTrace();
return State.ERROR;
}
}
use of bwem.Area in project Ecgberht by Jabbo16.
the class ChooseWorker method execute.
@Override
public State execute() {
try {
Worker closestWorker = null;
int frame = gameState.frameCount;
Position chosen = gameState.chosenPosition.toPosition();
Area posArea = gameState.bwem.getMap().getArea(gameState.chosenPosition);
if (!gameState.workerIdle.isEmpty()) {
for (Worker u : gameState.workerIdle) {
if (u.getLastCommandFrame() == frame)
continue;
Area workerArea = gameState.bwem.getMap().getArea(u.getTilePosition());
if (workerArea == null)
continue;
if (posArea != null && !posArea.equals(workerArea) && !posArea.isAccessibleFrom(workerArea)) {
continue;
}
if ((closestWorker == null || u.getDistance(chosen) < closestWorker.getDistance(chosen)))
closestWorker = u;
}
}
if (!gameState.workerMining.isEmpty()) {
for (Worker u : gameState.workerMining.keySet()) {
if (u.getLastCommandFrame() == frame)
continue;
Area workerArea = gameState.bwem.getMap().getArea(u.getTilePosition());
if (workerArea == null)
continue;
if (posArea != null && !posArea.equals(workerArea) && !posArea.isAccessibleFrom(workerArea)) {
continue;
}
if ((closestWorker == null || u.getDistance(chosen) < closestWorker.getDistance(chosen)) && !u.isCarryingMinerals()) {
closestWorker = u;
}
}
}
if (closestWorker != null) {
gameState.chosenWorker = closestWorker;
return State.SUCCESS;
}
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
e.printStackTrace();
return State.ERROR;
}
}
use of bwem.Area in project Ecgberht by Jabbo16.
the class CheckMineralWalkGoldRush method getCloserMineral.
private MineralPatch getCloserMineral(Map.Entry<SCV, MutablePair<UnitType, TilePosition>> entry) {
double bestDist = Double.MAX_VALUE;
MineralPatch closerMineral = null;
SCV scv = entry.getKey();
Position buildTarget = entry.getValue().second.toPosition();
for (MineralPatch mineralPatch : gameState.walkingMinerals) {
if (!mineralPatch.isVisible() || scv.getDistance(mineralPatch) <= 32 * 4)
continue;
double dist = mineralPatch.getDistance(buildTarget) * 1.2;
if (dist > scv.getDistance(buildTarget))
continue;
Area mineralArea = gameState.bwem.getMap().getArea(mineralPatch.getTilePosition());
Area workerArea = gameState.bwem.getMap().getArea(scv.getTilePosition());
if (mineralPatch.equals(scv.getTargetUnit()) && mineralArea != null && mineralArea.equals(workerArea))
continue;
if (dist < bestDist) {
bestDist = dist;
closerMineral = mineralPatch;
}
}
return closerMineral;
}
Aggregations