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