Search in sources :

Example 11 with WalkPosition

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));
    }
}
Also used : WalkPosition(org.openbw.bwapi4j.WalkPosition)

Example 12 with WalkPosition

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;
}
Also used : Area(bwem.Area) TilePosition(org.openbw.bwapi4j.TilePosition) WalkPosition(org.openbw.bwapi4j.WalkPosition) Result(org.bk.ass.path.Result)

Example 13 with WalkPosition

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();
}
Also used : WalkPosition(org.openbw.bwapi4j.WalkPosition) TilePosition(org.openbw.bwapi4j.TilePosition) Position(org.openbw.bwapi4j.Position)

Example 14 with WalkPosition

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));
    }
}
Also used : AreaInitializerImpl(bwem.area.AreaInitializerImpl) WalkPosition(org.openbw.bwapi4j.WalkPosition) AreaId(bwem.area.typedef.AreaId)

Example 15 with WalkPosition

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;
}
Also used : Utils(bwem.util.Utils) Altitude(bwem.typedef.Altitude) MutableInt(org.apache.commons.lang3.mutable.MutableInt) PriorityQueue(java.util.PriorityQueue) Map(bwem.map.Map) HashMap(java.util.HashMap) TilePosition(org.openbw.bwapi4j.TilePosition) Pair(org.openbw.bwapi4j.util.Pair) ArrayList(java.util.ArrayList) Area(bwem.area.Area) MutablePair(org.apache.commons.lang3.tuple.MutablePair) GroupId(bwem.area.typedef.GroupId) AreaId(bwem.area.typedef.AreaId) CPPath(bwem.typedef.CPPath) Index(bwem.typedef.Index) AdvancedData(bwem.map.AdvancedData) StaticBuilding(bwem.unit.StaticBuilding) Position(org.openbw.bwapi4j.Position) Tile(bwem.tile.Tile) Neutral(bwem.unit.Neutral) AreaInitializer(bwem.area.AreaInitializer) WalkPosition(org.openbw.bwapi4j.WalkPosition) Mineral(bwem.unit.Mineral) TileImpl(bwem.tile.TileImpl) List(java.util.List) Geyser(bwem.unit.Geyser) AreaInitializerImpl(bwem.area.AreaInitializerImpl) BwemExt(bwem.util.BwemExt) Queue(java.util.Queue) Comparator(java.util.Comparator) MiniTile(bwem.tile.MiniTile) HashMap(java.util.HashMap) AreaId(bwem.area.typedef.AreaId) ArrayList(java.util.ArrayList) MutablePair(org.apache.commons.lang3.tuple.MutablePair) WalkPosition(org.openbw.bwapi4j.WalkPosition) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

WalkPosition (org.openbw.bwapi4j.WalkPosition)24 ArrayList (java.util.ArrayList)10 TilePosition (org.openbw.bwapi4j.TilePosition)7 ChokePoint (bwem.ChokePoint)5 MiniTile (bwem.tile.MiniTile)5 Area (bwem.area.Area)4 AreaId (bwem.area.typedef.AreaId)4 Pair (bwem.util.Pair)4 MutablePair (org.apache.commons.lang3.tuple.MutablePair)4 AreaInitializerImpl (bwem.area.AreaInitializerImpl)3 Tile (bwem.tile.Tile)3 TileImpl (bwem.tile.TileImpl)3 Altitude (bwem.typedef.Altitude)3 CPPath (bwem.typedef.CPPath)3 Geyser (bwem.unit.Geyser)3 Mineral (bwem.unit.Mineral)3 StaticBuilding (bwem.unit.StaticBuilding)3 BwemExt (bwem.util.BwemExt)3 Utils (bwem.util.Utils)3 HashMap (java.util.HashMap)3