Search in sources :

Example 1 with TempAreaInfo

use of bwem.area.TempAreaInfo in project BWAPI4J by OpenBW.

the class MapInitializerImpl method computeTempAreas.

@Override
public List<TempAreaInfo> computeTempAreas(final List<MutablePair<WalkPosition, MiniTile>> miniTilesByDescendingAltitude) {
    final List<TempAreaInfo> tempAreaList = new ArrayList<>();
    // tempAreaList[0] left unused, as AreaIds are > 0
    tempAreaList.add(new TempAreaInfo());
    for (final MutablePair<WalkPosition, MiniTile> current : miniTilesByDescendingAltitude) {
        final WalkPosition pos = new WalkPosition(current.getLeft().getX(), current.getLeft().getY());
        final MiniTile cur = current.getRight();
        final MutablePair<AreaId, AreaId> neighboringAreas = findNeighboringAreas(pos);
        if (neighboringAreas.getLeft() == null) {
            // no neighboring area : creates of a new area
            tempAreaList.add(new TempAreaInfo(new AreaId(tempAreaList.size()), cur, pos));
        } else if (neighboringAreas.getRight() == null) {
            // one neighboring area : adds cur to the existing area
            tempAreaList.get(neighboringAreas.getLeft().intValue()).add(cur);
        } else {
            // two neighboring areas : adds cur to one of them  &  possible merging
            AreaId smaller = neighboringAreas.getLeft();
            AreaId bigger = neighboringAreas.getRight();
            if (tempAreaList.get(smaller.intValue()).getSize() > tempAreaList.get(bigger.intValue()).getSize()) {
                AreaId smallerTmp = smaller;
                smaller = bigger;
                bigger = smallerTmp;
            }
            // Condition for the neighboring areas to merge:
            // any_of(StartingLocations().begin(), StartingLocations().end(), [&pos](const TilePosition & startingLoc)
            // { return dist(TilePosition(pos), startingLoc + TilePosition(2, 1)) <= 3;})
            boolean cppAlgorithmStdAnyOf = getData().getMapData().getStartingLocations().stream().anyMatch(startingLoc -> BwemExt.dist(pos.toTilePosition(), startingLoc.add(new TilePosition(2, 1))) <= 3.0);
            final int curAltitude = cur.getAltitude().intValue();
            final int biggerHighestAltitude = tempAreaList.get(bigger.intValue()).getHighestAltitude().intValue();
            final int smallerHighestAltitude = tempAreaList.get(smaller.intValue()).getHighestAltitude().intValue();
            if ((tempAreaList.get(smaller.intValue()).getSize() < 80) || (smallerHighestAltitude < 80) || ((double) curAltitude / (double) biggerHighestAltitude >= 0.90) || ((double) curAltitude / (double) smallerHighestAltitude >= 0.90) || cppAlgorithmStdAnyOf) {
                // adds cur to the absorbing area:
                tempAreaList.get(bigger.intValue()).add(cur);
                // merges the two neighboring areas:
                replaceAreaIds(tempAreaList.get(smaller.intValue()).getWalkPositionWithHighestAltitude(), bigger);
                tempAreaList.get(bigger.intValue()).merge(tempAreaList.get(smaller.intValue()));
            } else {
                // no merge : cur starts or continues the frontier between the two neighboring areas
                // adds cur to the chosen Area:
                tempAreaList.get(chooseNeighboringArea(smaller, bigger).intValue()).add(cur);
                super.rawFrontier.add(new MutablePair<>(neighboringAreas, pos));
            }
        }
    }
    // Remove from the frontier obsolete positions
    rawFrontier.removeIf(f -> f.getLeft().getLeft().equals(f.getLeft().getRight()));
    return tempAreaList;
}
Also used : TempAreaInfo(bwem.area.TempAreaInfo) bwem.util(bwem.util) Altitude(bwem.typedef.Altitude) bwem.unit(bwem.unit) Collection(java.util.Collection) org.openbw.bwapi4j(org.openbw.bwapi4j) MineralPatch(org.openbw.bwapi4j.unit.MineralPatch) bwem.tile(bwem.tile) ArrayList(java.util.ArrayList) CheckMode(bwem.CheckMode) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Unit(org.openbw.bwapi4j.unit.Unit) MutablePair(org.apache.commons.lang3.tuple.MutablePair) PlayerUnit(org.openbw.bwapi4j.unit.PlayerUnit) VespeneGeyser(org.openbw.bwapi4j.unit.VespeneGeyser) AreaId(bwem.area.typedef.AreaId) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) MutablePair(org.apache.commons.lang3.tuple.MutablePair) ArrayList(java.util.ArrayList) AreaId(bwem.area.typedef.AreaId) TempAreaInfo(bwem.area.TempAreaInfo)

Example 2 with TempAreaInfo

use of bwem.area.TempAreaInfo in project BWAPI4J by OpenBW.

the class MapInitializerImpl method createAreas.

// Initializes Graph with the valid and big enough areas in tempAreaList.
@Override
public void createAreas(final List<TempAreaInfo> tempAreaList, final int areaMinMiniTiles) {
    final List<MutablePair<WalkPosition, Integer>> areasList = new ArrayList<>();
    int newAreaId = 1;
    int newTinyAreaId = -2;
    for (final TempAreaInfo tempArea : tempAreaList) {
        if (tempArea.isValid()) {
            if (tempArea.getSize() >= areaMinMiniTiles) {
                // bwem_assert(newAreaId <= tempArea.id());
                if (!(newAreaId <= tempArea.getId().intValue())) {
                    throw new IllegalStateException();
                }
                if (newAreaId != tempArea.getId().intValue()) {
                    replaceAreaIds(tempArea.getWalkPositionWithHighestAltitude(), new AreaId(newAreaId));
                }
                areasList.add(new MutablePair<>(tempArea.getWalkPositionWithHighestAltitude(), tempArea.getSize()));
                ++newAreaId;
            } else {
                replaceAreaIds(tempArea.getWalkPositionWithHighestAltitude(), new AreaId(newTinyAreaId));
                --newTinyAreaId;
            }
        }
    }
    getGraph().createAreas(areasList);
}
Also used : MutablePair(org.apache.commons.lang3.tuple.MutablePair) ArrayList(java.util.ArrayList) AreaId(bwem.area.typedef.AreaId) TempAreaInfo(bwem.area.TempAreaInfo)

Aggregations

TempAreaInfo (bwem.area.TempAreaInfo)2 AreaId (bwem.area.typedef.AreaId)2 ArrayList (java.util.ArrayList)2 MutablePair (org.apache.commons.lang3.tuple.MutablePair)2 CheckMode (bwem.CheckMode)1 bwem.tile (bwem.tile)1 Altitude (bwem.typedef.Altitude)1 bwem.unit (bwem.unit)1 bwem.util (bwem.util)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 org.openbw.bwapi4j (org.openbw.bwapi4j)1 MineralPatch (org.openbw.bwapi4j.unit.MineralPatch)1 PlayerUnit (org.openbw.bwapi4j.unit.PlayerUnit)1 Unit (org.openbw.bwapi4j.unit.Unit)1 VespeneGeyser (org.openbw.bwapi4j.unit.VespeneGeyser)1