use of bwem.Area in project Ecgberht by Jabbo16.
the class WorkerWalkBuild method execute.
@Override
public State execute() {
try {
for (Entry<SCV, MutablePair<UnitType, TilePosition>> u : gameState.workerBuild.entrySet()) {
SCV chosen = u.getKey();
if (u.getValue().first != UnitType.Terran_Command_Center || gameState.getGame().getBWMap().isVisible(u.getValue().second) || !gameState.fortressSpecialBLsTiles.contains(u.getValue().second))
continue;
Base myBase = Util.getClosestBaseLocation(u.getValue().second.toPosition());
MutablePair<MineralPatch, MineralPatch> minerals = gameState.fortressSpecialBLs.get(myBase);
Area scvArea = gameState.bwem.getMap().getArea(chosen.getTilePosition());
if (!u.getValue().second.equals(new TilePosition(7, 118))) {
if (scvArea != null && scvArea.equals(myBase.getArea())) {
if (chosen.getDistance(minerals.first) > 3 * 32) {
chosen.move(u.getValue().second.toPosition());
continue;
}
if (minerals.second.isVisible()) {
chosen.gather(minerals.second);
continue;
}
}
if (minerals.second.isVisible()) {
chosen.gather(minerals.second);
continue;
}
if (minerals.first.isVisible()) {
chosen.gather(minerals.first);
}
} else {
// Weird logic :/
if (scvArea != null && scvArea.equals(myBase.getArea())) {
if (chosen.getDistance(minerals.first) > 3 * 32) {
chosen.move(u.getValue().second.toPosition());
continue;
} else {
chosen.gather(minerals.second);
continue;
}
}
chosen.gather(minerals.first);
}
}
return State.SUCCESS;
} 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 WorkerScoutAgent method disrupt.
private void disrupt() {
if (disrupter == null) {
if (unit.getBuildUnit() != null) {
disrupter = (Building) unit.getBuildUnit();
return;
}
if (unit.getOrder() != Order.PlaceBuilding) {
unit.build(getGs().enemyNaturalBase.getLocation(), UnitType.Terran_Engineering_Bay);
}
} else if (disrupter.getRemainingBuildTime() <= 25) {
unit.haltConstruction();
finishedDisrupting = true;
stoppedDisrupting = true;
removedIndex = true;
} else if (!stoppedDisrupting) {
if (mySim.enemies.stream().anyMatch(u -> unitInfo.getDistance(u) <= 4 * 32)) {
if (mySim.enemies.stream().anyMatch(u -> u.unit instanceof Zergling)) {
unit.haltConstruction();
stoppedDisrupting = true;
if (!removedIndex) {
enemyBaseBorders.remove(enemyNaturalIndex);
enemyNaturalIndex = -1;
removedIndex = true;
}
return;
}
if (mySim.enemies.size() == 1) {
UnitInfo closest = mySim.enemies.iterator().next();
Area enemyArea = getGs().bwem.getMap().getArea(closest.tileposition);
if (closest.unit instanceof Drone && enemyArea != null && enemyArea.equals(getGs().enemyNaturalArea)) {
if (mySim.lose) {
unit.haltConstruction();
stoppedDisrupting = true;
if (!removedIndex) {
enemyBaseBorders.remove(enemyNaturalIndex);
enemyNaturalIndex = -1;
removedIndex = true;
}
}
}
}
}
} else if (mySim.enemies.isEmpty() && disrupter != null && !finishedDisrupting)
unit.resumeBuilding(disrupter);
else if (!mySim.enemies.isEmpty() && (unitInfo.attackers.isEmpty() || !mySim.lose)) {
UnitInfo target = Util.getRangedTarget(unitInfo, mySim.enemies);
if (target != null)
UtilMicro.attack(unitInfo, target);
else if (disrupter != null && !finishedDisrupting)
unit.resumeBuilding(disrupter);
}
if (disrupter != null && !finishedDisrupting)
unit.resumeBuilding(disrupter);
}
use of bwem.Area in project Ecgberht by Jabbo16.
the class WorkerScoutAgent method canProxyInThisMap.
private void canProxyInThisMap() {
Area enemyArea = this.enemyBase.getArea();
Set<TilePosition> tilesArea = getGs().map.getTilesArea(enemyArea);
if (tilesArea == null)
return;
Result path = getGs().silentCartographer.getWalkablePath(enemyBase.getLocation().toWalkPosition(), getGs().enemyNaturalBase.getLocation().toWalkPosition());
for (TilePosition t : tilesArea) {
if (!getGs().map.tileBuildable(t, UnitType.Terran_Factory))
continue;
if (t.getDistance(Util.getUnitCenterPosition(enemyBase.getLocation().toPosition(), UnitType.Zerg_Hatchery).toTilePosition()) <= 13)
continue;
if (enemyBase.getGeysers().stream().anyMatch(u -> t.getDistance(u.getCenter().toTilePosition()) <= 9))
continue;
if (path.path.stream().anyMatch(u -> t.getDistance(new WalkPosition(u.x, u.y).toTilePosition()) <= 10))
continue;
validTiles.add(t);
}
if (validTiles.isEmpty())
return;
double bestDist = 0.0;
for (TilePosition p : validTiles) {
double dist = p.getDistance(enemyBase.getLocation());
if (dist > bestDist) {
bestDist = dist;
proxyTile = p;
}
}
if (proxyTile != null)
ableToProxy = true;
}
use of bwem.Area in project Ecgberht by Jabbo16.
the class WorkerScoutAgent method updateBorders.
private void updateBorders() {
final Area enemyRegion = enemyBase.getArea();
if (enemyRegion == null)
return;
final Position enemyCenter = enemyBase.getLocation().toPosition().add(new Position(64, 48));
final List<TilePosition> closestTobase = new ArrayList<>(BuildingMap.tilesArea.get(enemyRegion));
List<Position> unsortedVertices = new ArrayList<>();
for (TilePosition tp : closestTobase) {
if (getGs().bwem.getMap().getArea(tp) != enemyRegion)
continue;
TilePosition right = new TilePosition(tp.getX() + 1, tp.getY());
TilePosition bottom = new TilePosition(tp.getX(), tp.getY() + 1);
TilePosition left = new TilePosition(tp.getX() - 1, tp.getY());
TilePosition up = new TilePosition(tp.getX(), tp.getY() - 1);
final boolean edge = (!getGs().getGame().getBWMap().isValidPosition(right) || getGs().bwem.getMap().getArea(right) != enemyRegion || !getGs().getGame().getBWMap().isBuildable(right)) || (!getGs().getGame().getBWMap().isValidPosition(bottom) || getGs().bwem.getMap().getArea(bottom) != enemyRegion || !getGs().getGame().getBWMap().isBuildable(bottom)) || (!getGs().getGame().getBWMap().isValidPosition(left) || getGs().bwem.getMap().getArea(left) != enemyRegion || !getGs().getGame().getBWMap().isBuildable(left)) || (!getGs().getGame().getBWMap().isValidPosition(up) || getGs().bwem.getMap().getArea(up) != enemyRegion || !getGs().getGame().getBWMap().isBuildable(up));
if (edge && getGs().getGame().getBWMap().isBuildable(tp)) {
Position vertex = tp.toPosition().add(new Position(16, 16));
double dist = enemyCenter.getDistance(vertex);
if (dist > 368.0) {
double pullBy = Math.min(dist - 368.0, 120.0);
if (vertex.getX() == enemyCenter.getX()) {
vertex = vertex.add(new Position(0, vertex.getY() > enemyCenter.getY() ? (int) (-pullBy) : (int) pullBy));
} else {
double m = (double) (enemyCenter.getY() - vertex.getY()) / (double) (enemyCenter.getX() - vertex.getX());
double x = vertex.getX() + (vertex.getX() > enemyCenter.getX() ? -1.0 : 1.0) * pullBy / (Math.sqrt(1 + m * m));
double y = m * (x - vertex.getX()) + vertex.getY();
vertex = new Position((int) x, (int) y);
}
}
if (getGs().getGame().getBWMap().isValidPosition(vertex) && getGs().getGame().getBWMap().isWalkable(vertex.toWalkPosition()))
unsortedVertices.add(vertex);
}
}
List<Position> sortedVertices = new ArrayList<>();
Position current = unsortedVertices.get(0);
enemyBaseBorders.add(current);
unsortedVertices.remove(current);
while (!unsortedVertices.isEmpty()) {
double bestDist = 1000000;
Position bestPos = null;
for (final Position pos : unsortedVertices) {
double dist = pos.getDistance(current);
if (dist < bestDist) {
bestDist = dist;
bestPos = pos;
}
}
current = bestPos;
sortedVertices.add(sortedVertices.size(), bestPos);
unsortedVertices.remove(bestPos);
}
int distanceThreshold = 100;
while (true) {
int maxFarthest = 0;
int maxFarthestStart = 0;
int maxFarthestEnd = 0;
for (int i = 0; i < sortedVertices.size(); ++i) {
int farthest = 0;
int farthestIndex = 0;
for (int j = 1; j < sortedVertices.size() / 2; ++j) {
int jindex = (i + j) % sortedVertices.size();
if (sortedVertices.get(i).getDistance(sortedVertices.get(jindex)) < distanceThreshold) {
farthest = j;
farthestIndex = jindex;
}
}
if (farthest > maxFarthest) {
maxFarthest = farthest;
maxFarthestStart = i;
maxFarthestEnd = farthestIndex;
}
}
if (maxFarthest < 4)
break;
List<Position> temp = new ArrayList<>();
for (int s = maxFarthestEnd; s != maxFarthestStart; s = (s + 1) % sortedVertices.size()) {
temp.add(temp.size(), sortedVertices.get(s));
}
sortedVertices = temp;
}
enemyBaseBorders = sortedVertices;
currentVertex = 0;
if (!getGs().learningManager.isNaughty()) {
Base enemyNatural = getGs().enemyNaturalBase;
if (enemyNatural != null) {
Position enemyNaturalPos = enemyNatural.getLocation().toPosition();
int index = -1;
double distMax = Double.MAX_VALUE;
for (int ii = 0; ii < enemyBaseBorders.size(); ii++) {
double dist = Util.getGroundDistance(enemyBaseBorders.get(ii), enemyNaturalPos);
if (index == -1 || dist < distMax) {
index = ii;
distMax = dist;
}
}
enemyBaseBorders.add(index, enemyNaturalPos);
this.enemyNaturalIndex = index;
}
} else {
enemyNaturalIndex = -1;
removedIndex = true;
}
}
use of bwem.Area in project Ecgberht by Jabbo16.
the class BuildingMap method findBunkerPosition.
public TilePosition findBunkerPosition(ChokePoint choke) {
TilePosition buildingSize = UnitType.Terran_Bunker.tileSize();
int size = Math.max(buildingSize.getY(), buildingSize.getX());
double chokeWidth = Util.getChokeWidth(choke);
Position starting = choke.getCenter().toPosition();
int x = starting.toTilePosition().getY();
int y = starting.toTilePosition().getX();
int i = 10;
int j = 10;
boolean expandBunker = choke.equals(getGs().naturalChoke);
// Finds the first valid tileposition starting around the given tileposition
TilePosition position = null;
double dist = Double.MAX_VALUE;
for (int ii = (x - i); ii <= (x + i); ii++) {
for (int jj = (y - j); jj <= (y + j); jj++) {
if ((ii >= 0 && ii < height) && (jj >= 0 && jj < width)) {
if ((!map[ii][jj].equals("M") && !map[ii][jj].equals("V") && !map[ii][jj].equals("E") && !map[ii][jj].equals("B")) && Integer.parseInt(map[ii][jj]) >= size) {
Area area = bwem.getMap().getArea(new TilePosition(jj, ii));
if (area != null && area.equals(getGs().naturalArea) && !expandBunker)
continue;
if (area != null && !area.equals(getGs().naturalArea) && expandBunker)
continue;
if (checkUnitsChosenBuildingGrid(new TilePosition(jj, ii), UnitType.Terran_Bunker)) {
TilePosition newPosition = new TilePosition(jj, ii);
Position centerBunker = Util.getUnitCenterPosition(newPosition.toPosition(), UnitType.Terran_Bunker);
if (chokeWidth <= 64.0 && Util.broodWarDistance(choke.getCenter().toPosition(), centerBunker) <= 64)
continue;
double newDist = Util.broodWarDistance(centerBunker, starting);
if (position == null || newDist < dist) {
position = newPosition;
dist = newDist;
}
}
}
}
}
}
return position;
}
Aggregations