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;
}
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);
}
Aggregations