Search in sources :

Example 1 with AreaId

use of bwem.area.typedef.AreaId in project BWAPI4J by OpenBW.

the class MapImpl method onBlockingNeutralDestroyed.

public void onBlockingNeutralDestroyed(Neutral pBlocking) {
    // bwem_assert(pBlocking && pBlocking->blocking());
    if (!(pBlocking != null && pBlocking.isBlocking())) {
        throw new IllegalArgumentException();
    }
    for (Area pArea : pBlocking.getBlockedAreas()) for (ChokePoint cp : pArea.getChokePoints()) {
        ((ChokePointImpl) cp).onBlockingNeutralDestroyed(pBlocking);
    }
    if (getData().getTile(pBlocking.getTopLeft()).getNeutral() != null) {
        // there remains some blocking Neutrals at the same location
        return;
    }
    // Unblock the miniTiles of pBlocking:
    AreaId newId = pBlocking.getBlockedAreas().iterator().next().getId();
    WalkPosition pBlockingW = pBlocking.getSize().toWalkPosition();
    for (int dy = 0; dy < pBlockingW.getY(); ++dy) for (int dx = 0; dx < pBlockingW.getX(); ++dx) {
        MiniTile miniTile = ((AdvancedDataInitializer) getData()).getMiniTile_(pBlocking.getTopLeft().toWalkPosition().add(new WalkPosition(dx, dy)));
        if (miniTile.isWalkable()) {
            ((MiniTileImpl) miniTile).replaceBlockedAreaId(newId);
        }
    }
    // Unblock the Tiles of pBlocking:
    for (int dy = 0; dy < pBlocking.getSize().getY(); ++dy) for (int dx = 0; dx < pBlocking.getSize().getX(); ++dx) {
        ((TileImpl) ((AdvancedDataInitializer) getData()).getTile_(pBlocking.getTopLeft().add(new TilePosition(dx, dy)))).resetAreaId();
        setAreaIdInTile(pBlocking.getTopLeft().add(new TilePosition(dx, dy)));
    }
    if (automaticPathUpdate()) {
        getGraph().computeChokePointDistanceMatrix();
    }
}
Also used : Area(bwem.area.Area) AreaId(bwem.area.typedef.AreaId) MiniTile(bwem.tile.MiniTile)

Example 2 with AreaId

use of bwem.area.typedef.AreaId in project BWAPI4J by OpenBW.

the class MapImpl method findNeighboringAreas.

public MutablePair<AreaId, AreaId> findNeighboringAreas(final WalkPosition p) {
    final MutablePair<AreaId, AreaId> result = new MutablePair<>(null, null);
    final WalkPosition[] deltas = { new WalkPosition(0, -1), new WalkPosition(-1, 0), new WalkPosition(+1, 0), new WalkPosition(0, +1) };
    for (final WalkPosition delta : deltas) {
        if (getData().getMapData().isValid(p.add(delta))) {
            final AreaId areaId = getData().getMiniTile(p.add(delta), CheckMode.NO_CHECK).getAreaId();
            if (areaId.intValue() > 0) {
                if (result.getLeft() == null) {
                    result.setLeft(areaId);
                } else if (!result.getLeft().equals(areaId)) {
                    if (result.getRight() == null || ((areaId.intValue() < result.getRight().intValue()))) {
                        result.setRight(areaId);
                    }
                }
            }
        }
    }
    return result;
}
Also used : MutablePair(org.apache.commons.lang3.tuple.MutablePair) AreaId(bwem.area.typedef.AreaId)

Example 3 with AreaId

use of bwem.area.typedef.AreaId 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 4 with AreaId

use of bwem.area.typedef.AreaId 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)

Example 5 with AreaId

use of bwem.area.typedef.AreaId in project BWAPI4J by OpenBW.

the class PairGenericMiniTileAltitudeComparatorTest method testPairGenericMiniTileAltitudeComparator.

@Test
public void testPairGenericMiniTileAltitudeComparator() {
    final List<MutablePair<WalkPosition, MiniTile>> list = new ArrayList<>();
    final MiniTile m1 = new MiniTileImpl();
    ((MiniTileImpl) m1).setAreaId(new AreaId(2));
    ((MiniTileImpl) m1).setAltitude(new Altitude(5));
    final MiniTile m2 = new MiniTileImpl();
    ((MiniTileImpl) m2).setAreaId(new AreaId(1));
    ((MiniTileImpl) m2).setAltitude(new Altitude(2));
    final MiniTile m3 = new MiniTileImpl();
    ((MiniTileImpl) m3).setAreaId(new AreaId(3));
    ((MiniTileImpl) m3).setAltitude(new Altitude(7));
    final MiniTile m4 = new MiniTileImpl();
    ((MiniTileImpl) m4).setAreaId(new AreaId(5));
    ((MiniTileImpl) m4).setAltitude(new Altitude(1));
    final MiniTile m5 = new MiniTileImpl();
    ((MiniTileImpl) m5).setAreaId(new AreaId(4));
    ((MiniTileImpl) m5).setAltitude(new Altitude(8));
    list.add(new MutablePair<>(new WalkPosition(5, 15), m1));
    list.add(new MutablePair<>(new WalkPosition(2, 98), m2));
    list.add(new MutablePair<>(new WalkPosition(63, 123), m3));
    list.add(new MutablePair<>(new WalkPosition(103, 435), m4));
    list.add(new MutablePair<>(new WalkPosition(89, 77), m5));
    // Sort by descending order.
    Collections.sort(list, new PairGenericMiniTileAltitudeComparator<>());
    Collections.reverse(list);
    Assert.assertEquals(new MutablePair<>(new WalkPosition(89, 77), m5), list.get(0));
    Assert.assertEquals(new MutablePair<>(new WalkPosition(63, 123), m3), list.get(1));
    Assert.assertEquals(new MutablePair<>(new WalkPosition(5, 15), m1), list.get(2));
    Assert.assertEquals(new MutablePair<>(new WalkPosition(2, 98), m2), list.get(3));
    Assert.assertEquals(new MutablePair<>(new WalkPosition(103, 435), m4), list.get(4));
}
Also used : MutablePair(org.apache.commons.lang3.tuple.MutablePair) ArrayList(java.util.ArrayList) MiniTile(bwem.tile.MiniTile) AreaId(bwem.area.typedef.AreaId) WalkPosition(org.openbw.bwapi4j.WalkPosition) MiniTileImpl(bwem.tile.MiniTileImpl) Altitude(bwem.typedef.Altitude) Test(org.junit.Test)

Aggregations

AreaId (bwem.area.typedef.AreaId)10 MutablePair (org.apache.commons.lang3.tuple.MutablePair)7 ArrayList (java.util.ArrayList)6 Altitude (bwem.typedef.Altitude)5 MiniTile (bwem.tile.MiniTile)4 WalkPosition (org.openbw.bwapi4j.WalkPosition)4 Area (bwem.area.Area)3 AreaInitializerImpl (bwem.area.AreaInitializerImpl)3 List (java.util.List)3 AreaInitializer (bwem.area.AreaInitializer)2 TempAreaInfo (bwem.area.TempAreaInfo)2 GroupId (bwem.area.typedef.GroupId)2 AdvancedData (bwem.map.AdvancedData)2 Map (bwem.map.Map)2 Tile (bwem.tile.Tile)2 TileImpl (bwem.tile.TileImpl)2 CPPath (bwem.typedef.CPPath)2 Index (bwem.typedef.Index)2 Geyser (bwem.unit.Geyser)2 Mineral (bwem.unit.Mineral)2