Search in sources :

Example 6 with Tile

use of bwem.tile.Tile in project BWAPI4J by OpenBW.

the class AreaInitializerImpl method computeDistances.

@Override
public int[] computeDistances(final ChokePoint startCP, final List<ChokePoint> targetCPs) {
    // bwem_assert(!contains(targetCPs, startCP));
    if (targetCPs.contains(startCP)) {
        throw new IllegalStateException();
    }
    final TilePosition start = getMap().breadthFirstSearch(startCP.getNodePositionInArea(ChokePoint.Node.MIDDLE, this).toTilePosition(), // findCond
    args -> {
        final Object ttile = args[0];
        if (ttile instanceof Tile) {
            final Tile tile = (Tile) ttile;
            return tile.getAreaId().equals(getId());
        } else {
            throw new IllegalArgumentException();
        }
    }, // visitCond
    args -> true);
    final List<TilePosition> targets = new ArrayList<>();
    for (final ChokePoint cp : targetCPs) {
        final TilePosition t = getMap().breadthFirstSearch(cp.getNodePositionInArea(ChokePoint.Node.MIDDLE, this).toTilePosition(), // findCond
        args -> {
            final Object ttile = args[0];
            if (ttile instanceof Tile) {
                final Tile tile = (Tile) ttile;
                return (tile.getAreaId().equals(getId()));
            } else {
                throw new IllegalArgumentException();
            }
        }, // visitCond
        args -> true);
        targets.add(t);
    }
    return computeDistances(start, targets);
}
Also used : TilePosition(org.openbw.bwapi4j.TilePosition) ArrayList(java.util.ArrayList) Tile(bwem.tile.Tile) MiniTile(bwem.tile.MiniTile) ChokePoint(bwem.ChokePoint)

Example 7 with Tile

use of bwem.tile.Tile in project BWAPI4J by OpenBW.

the class AreaInitializerImpl method computeBaseLocationScore.

@Override
public int computeBaseLocationScore(final AdvancedData mapAdvancedData, final TilePosition location) {
    final TilePosition dimCC = UnitType.Terran_Command_Center.tileSize();
    int sumScore = 0;
    for (int dy = 0; dy < dimCC.getY(); ++dy) for (int dx = 0; dx < dimCC.getX(); ++dx) {
        final Tile tile = mapAdvancedData.getTile(location.add(new TilePosition(dx, dy)), CheckMode.NO_CHECK);
        if (!tile.isBuildable()) {
            return -1;
        }
        if (((TileImpl) tile).getInternalData() == -1) {
            // Unfortunately, this is guaranteed only for the resources in this Area, which is the very reason of validateBaseLocation
            return -1;
        }
        if (!tile.getAreaId().equals(getId())) {
            return -1;
        }
        if (tile.getNeutral() != null && (tile.getNeutral() instanceof StaticBuilding)) {
            return -1;
        }
        sumScore += ((TileImpl) tile).getInternalData();
    }
    return sumScore;
}
Also used : TileImpl(bwem.tile.TileImpl) StaticBuilding(bwem.unit.StaticBuilding) TilePosition(org.openbw.bwapi4j.TilePosition) Tile(bwem.tile.Tile) MiniTile(bwem.tile.MiniTile) ChokePoint(bwem.ChokePoint)

Example 8 with Tile

use of bwem.tile.Tile in project BWAPI4J by OpenBW.

the class MapImpl method breadthFirstSearch.

public TilePosition breadthFirstSearch(TilePosition start, Pred findCond, Pred visitCond, boolean connect8) {
    if (findCond.isTrue(getData().getTile(start), start, this)) {
        return start;
    }
    List<TilePosition> visited = new ArrayList<>();
    Queue<TilePosition> toVisit = new ArrayDeque<>();
    toVisit.add(start);
    visited.add(start);
    TilePosition[] dir8 = { new TilePosition(-1, -1), new TilePosition(0, -1), new TilePosition(1, -1), new TilePosition(-1, 0), new TilePosition(1, 0), new TilePosition(-1, 1), new TilePosition(0, 1), new TilePosition(1, 1) };
    TilePosition[] dir4 = { new TilePosition(0, -1), new TilePosition(-1, 0), new TilePosition(+1, 0), new TilePosition(0, +1) };
    TilePosition[] directions = connect8 ? dir8 : dir4;
    while (!toVisit.isEmpty()) {
        TilePosition current = toVisit.remove();
        for (TilePosition delta : directions) {
            TilePosition next = current.add(delta);
            if (getData().getMapData().isValid(next)) {
                Tile nextTile = getData().getTile(next, CheckMode.NO_CHECK);
                if (findCond.isTrue(nextTile, next, this)) {
                    return next;
                }
                if (visitCond.isTrue(nextTile, next, this) && !visited.contains(next)) {
                    toVisit.add(next);
                    visited.add(next);
                }
            }
        }
    }
    // bwem_assert(false);
    throw new IllegalStateException();
// return start;
}
Also used : Tile(bwem.tile.Tile) MiniTile(bwem.tile.MiniTile)

Aggregations

MiniTile (bwem.tile.MiniTile)8 Tile (bwem.tile.Tile)8 TilePosition (org.openbw.bwapi4j.TilePosition)7 ChokePoint (bwem.ChokePoint)5 TileImpl (bwem.tile.TileImpl)4 Geyser (bwem.unit.Geyser)3 Mineral (bwem.unit.Mineral)3 ArrayList (java.util.ArrayList)3 Area (bwem.area.Area)2 Neutral (bwem.unit.Neutral)2 StaticBuilding (bwem.unit.StaticBuilding)2 PriorityQueue (java.util.PriorityQueue)2 Pair (org.openbw.bwapi4j.util.Pair)2 Base (bwem.Base)1 BaseImpl (bwem.BaseImpl)1 AreaInitializer (bwem.area.AreaInitializer)1 AreaInitializerImpl (bwem.area.AreaInitializerImpl)1 AreaId (bwem.area.typedef.AreaId)1 GroupId (bwem.area.typedef.GroupId)1 AdvancedData (bwem.map.AdvancedData)1