use of org.openbw.bwapi4j.WalkPosition in project Ecgberht by Jabbo16.
the class Graph method createAreas.
// Creates a new Area for each pair (top, miniTiles) in areasList (See Area::top() and
// Area::miniTiles())
void createAreas(final List<Pair<WalkPosition, Integer>> areasList) {
for (int id = 1; id <= areasList.size(); ++id) {
final WalkPosition top = areasList.get(id - 1).getLeft();
final int miniTileCount = areasList.get(id - 1).getRight();
this.areas.add(new AreaInitializer(getMap(), new AreaId(id), top, miniTileCount));
}
}
use of org.openbw.bwapi4j.WalkPosition 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 org.openbw.bwapi4j.WalkPosition in project Ecgberht by Jabbo16.
the class UnitInfo method update.
// TODO completion frames
void update() {
player = unit.getPlayer();
unitType = unit.getType();
visible = unit.isVisible();
position = visible ? unit.getPosition() : position;
currentOrder = unit.getOrder();
completed = !completed && visible ? unit.isCompleted() : completed;
tileposition = visible ? unit.getTilePosition() : tileposition;
if (!unitType.isBuilding())
walkposition = new Position(unit.getLeft(), unit.getTop()).toWalkPosition();
else
walkposition = tileposition.toWalkPosition();
if (visible) {
lastPosition = position;
lastTileposition = tileposition;
lastWalkposition = walkposition;
}
lastVisibleFrame = visible ? getGs().frameCount : lastVisibleFrame;
lastAttackFrame = unit.isStartingAttack() ? getGs().frameCount : lastVisibleFrame;
if (unit instanceof GroundAttacker)
groundRange = player.getUnitStatCalculator().weaponMaxRange(unitType.groundWeapon());
if (unit instanceof AirAttacker)
airRange = player.getUnitStatCalculator().weaponMaxRange(unitType.airWeapon());
if (unit instanceof Bunker) {
airRange = 5 * 32;
groundRange = 5 * 32;
}
health = visible ? unit.getHitPoints() : expectedHealth();
shields = visible ? unit.getShields() : expectedShields();
if (unit instanceof SpellCaster)
energy = ((SpellCaster) unit).getEnergy();
percentHealth = unitType.maxHitPoints() > 0 ? (double) health / (double) unitType.maxHitPoints() : 1.0;
percentShield = unitType.maxShields() > 0 ? (double) shields / (double) unitType.maxShields() : 1.0;
if (unit instanceof Burrowable && visible)
burrowed = ((Burrowable) unit).isBurrowed();
if (visible)
flying = unit.isFlying();
speed = Util.getSpeed(this);
target = unit instanceof Attacker ? ((Attacker) unit).getTargetUnit() : unit.getOrderTarget();
attackers.clear();
}
use of org.openbw.bwapi4j.WalkPosition in project BWAPI4J by OpenBW.
the class Graph method createAreas.
// Creates a new Area for each pair (top, miniTiles) in areasList (See Area::top() and Area::miniTiles())
public void createAreas(final List<MutablePair<WalkPosition, Integer>> areasList) {
for (int id = 1; id <= areasList.size(); ++id) {
final WalkPosition top = areasList.get(id - 1).getLeft();
final int miniTileCount = areasList.get(id - 1).getRight();
this.areas.add(new AreaInitializerImpl(getMap(), new AreaId(id), top, miniTileCount));
}
}
use of org.openbw.bwapi4j.WalkPosition in project BWAPI4J by OpenBW.
the class Graph method createRawFrontierByAreaPairMap.
// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
// 2) Dispatch the global raw frontier between all the relevant pairs of areas:
// ----------------------------------------------------------------------
private java.util.Map<MutablePair<AreaId, AreaId>, List<WalkPosition>> createRawFrontierByAreaPairMap(final List<MutablePair<MutablePair<AreaId, AreaId>, WalkPosition>> rawFrontier) {
final java.util.Map<MutablePair<AreaId, AreaId>, List<WalkPosition>> rawFrontierByAreaPair = new HashMap<>();
for (final MutablePair<MutablePair<AreaId, AreaId>, WalkPosition> raw : rawFrontier) {
int a = raw.getLeft().getLeft().intValue();
int b = raw.getLeft().getRight().intValue();
if (a > b) {
final int a_tmp = a;
a = b;
b = a_tmp;
}
// bwem_assert(a <= b);
if (!(a <= b)) {
throw new IllegalStateException();
}
// bwem_assert((a >= 1) && (b <= areasCount()));
if (!((a >= 1) && (b <= getAreaCount()))) {
throw new IllegalStateException();
}
final MutablePair<AreaId, AreaId> key = new MutablePair<>(new AreaId(a), new AreaId(b));
rawFrontierByAreaPair.computeIfAbsent(key, mp -> new ArrayList<>()).add(raw.getRight());
}
return rawFrontierByAreaPair;
}
Aggregations