use of bwem.ChokePoint 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.ChokePoint in project BWAPI4J by OpenBW.
the class MapPrinterExample method printMap.
public void printMap(Map theMap) {
java.util.Map<Integer, Color> mapZoneColor = new HashMap<>();
for (int y = 0; y < theMap.getData().getMapData().getWalkSize().getY(); ++y) for (int x = 0; x < theMap.getData().getMapData().getWalkSize().getX(); ++x) {
WalkPosition p = new WalkPosition(x, y);
MiniTile miniTile = theMap.getData().getMiniTile(p, CheckMode.NO_CHECK);
Color col;
if (miniTile.isSea()) {
if (mapPrinter.showSeaSide && theMap.getData().isSeaWithNonSeaNeighbors(p))
col = MapPrinter.CustomColor.SEA_SIDE.color();
else
col = MapPrinter.CustomColor.SEA.color();
} else {
if (mapPrinter.showLakes && miniTile.isLake()) {
col = MapPrinter.CustomColor.LAKE.color();
} else {
if (mapPrinter.showAltitude) {
int c = 255 - ((miniTile.getAltitude().intValue() * 255) / theMap.getHighestAltitude().intValue());
col = new Color(c, c, c);
} else {
col = MapPrinter.CustomColor.TERRAIN.color();
}
if (mapPrinter.showAreas || mapPrinter.showContinents)
if (miniTile.getAreaId().intValue() > 0) {
Area area = theMap.getArea(miniTile.getAreaId());
Color zoneColor = getZoneColor(area, mapZoneColor);
int red = zoneColor.getRed() * col.getRed() / 255;
int green = zoneColor.getGreen() * col.getGreen() / 255;
col = new Color(red, green, 0);
} else {
col = MapPrinter.CustomColor.TINY_AREA.color();
}
}
}
mapPrinter.point(p, col);
}
if (mapPrinter.showData)
for (int y = 0; y < theMap.getData().getMapData().getTileSize().getY(); ++y) for (int x = 0; x < theMap.getData().getMapData().getTileSize().getX(); ++x) {
int data = ((TileImpl) theMap.getData().getTile(new TilePosition(x, y))).getInternalData();
int c = (((data / 1) * 1) % 256);
Color col = new Color(c, c, c);
WalkPosition origin = (new TilePosition(x, y)).toWalkPosition();
mapPrinter.rectangle(origin, origin.add(new WalkPosition(3, 3)), col, MapPrinter.fill_t.fill);
}
if (mapPrinter.showUnbuildable)
for (int y = 0; y < theMap.getData().getMapData().getTileSize().getY(); ++y) for (int x = 0; x < theMap.getData().getMapData().getTileSize().getX(); ++x) if (!theMap.getData().getTile(new TilePosition(x, y)).isBuildable()) {
WalkPosition origin = (new TilePosition(x, y)).toWalkPosition();
mapPrinter.rectangle(origin.add(new WalkPosition(1, 1)), origin.add(new WalkPosition(2, 2)), MapPrinter.CustomColor.UNBUILDABLE.color());
}
if (mapPrinter.showGroundHeight)
for (int y = 0; y < theMap.getData().getMapData().getTileSize().getY(); ++y) for (int x = 0; x < theMap.getData().getMapData().getTileSize().getX(); ++x) {
Tile.GroundHeight groundHeight = theMap.getData().getTile(new TilePosition(x, y)).getGroundHeight();
if (groundHeight.intValue() >= Tile.GroundHeight.HIGH_GROUND.intValue())
for (int dy = 0; dy < 4; ++dy) for (int dx = 0; dx < 4; ++dx) {
WalkPosition p = (new TilePosition(x, y).toWalkPosition()).add(new WalkPosition(dx, dy));
if (// groundHeight is usefull only for walkable miniTiles
theMap.getData().getMiniTile(p, CheckMode.NO_CHECK).isWalkable())
if (((dx + dy) & (groundHeight == Tile.GroundHeight.HIGH_GROUND ? 1 : 3)) != 0)
mapPrinter.point(p, MapPrinter.CustomColor.HIGHER_GROUND.color());
}
}
if (mapPrinter.showAssignedResources)
for (Area area : theMap.getAreas()) for (Base base : area.getBases()) {
for (Mineral m : base.getMinerals()) mapPrinter.line(base.getCenter().toWalkPosition(), m.getCenter().toWalkPosition(), MapPrinter.CustomColor.BASES.color());
for (Geyser g : base.getGeysers()) mapPrinter.line(base.getCenter().toWalkPosition(), g.getCenter().toWalkPosition(), MapPrinter.CustomColor.BASES.color());
}
if (mapPrinter.showGeysers)
for (Geyser g : theMap.getNeutralData().getGeysers()) printNeutral(theMap, g, MapPrinter.CustomColor.GEYSERS.color());
if (mapPrinter.showMinerals)
for (Mineral m : theMap.getNeutralData().getMinerals()) printNeutral(theMap, m, MapPrinter.CustomColor.MINERALS.color());
if (mapPrinter.showStaticBuildings)
for (StaticBuilding s : theMap.getNeutralData().getStaticBuildings()) printNeutral(theMap, s, MapPrinter.CustomColor.STATIC_BUILDINGS.color());
if (mapPrinter.showStartingLocations)
for (TilePosition t : theMap.getData().getMapData().getStartingLocations()) {
WalkPosition origin = t.toWalkPosition();
// same size for other races
WalkPosition size = UnitType.Terran_Command_Center.tileSize().toWalkPosition();
mapPrinter.rectangle(origin, origin.add(size).subtract(new WalkPosition(1, 1)), MapPrinter.CustomColor.STARTING_LOCATIONS.color(), MapPrinter.fill_t.fill);
}
if (mapPrinter.showBases)
for (Area area : theMap.getAreas()) {
for (Base base : area.getBases()) {
WalkPosition origin = base.getLocation().toWalkPosition();
// same size for other races
WalkPosition size = UnitType.Terran_Command_Center.tileSize().toWalkPosition();
MapPrinter.dashed_t dashMode = base.getBlockingMinerals().isEmpty() ? MapPrinter.dashed_t.not_dashed : MapPrinter.dashed_t.dashed;
mapPrinter.rectangle(origin, origin.add(size).subtract(new WalkPosition(1, 1)), MapPrinter.CustomColor.BASES.color(), MapPrinter.fill_t.do_not_fill, dashMode);
}
}
if (mapPrinter.showChokePoints) {
for (MutablePair<MutablePair<AreaId, AreaId>, WalkPosition> f : theMap.getRawFrontier()) mapPrinter.point(f.getRight(), mapPrinter.showAreas ? MapPrinter.CustomColor.CHOKE_POINTS_SHOW_AREAS.color() : MapPrinter.CustomColor.CHOKE_POINTS_SHOW_CONTINENTS.color());
for (Area area : theMap.getAreas()) for (ChokePoint cp : area.getChokePoints()) {
ChokePoint.Node[] nodes = { ChokePoint.Node.END1, ChokePoint.Node.END2 };
for (ChokePoint.Node n : nodes) mapPrinter.square(cp.getNodePosition(n), 1, new Color(255, 0, 255), MapPrinter.fill_t.fill);
mapPrinter.square(cp.getCenter(), 1, new Color(0, 0, 255), MapPrinter.fill_t.fill);
}
}
try {
mapPrinter.writeImageToFile(Paths.get("map.png"), "png");
} catch (IOException ex) {
ex.printStackTrace();
}
}
use of bwem.ChokePoint in project Ecgberht by Jabbo16.
the class Util method getClosestChokepoint.
public static ChokePoint getClosestChokepoint(Position pos) {
ChokePoint closestChoke = null;
double dist = Double.MAX_VALUE;
for (ChokePoint choke : getGs().bwem.getMap().getChokePoints()) {
double cDist = broodWarDistance(pos, choke.getCenter().toPosition());
if (closestChoke == null || cDist < dist) {
closestChoke = choke;
dist = cDist;
}
}
return closestChoke;
}
use of bwem.ChokePoint in project Ecgberht by Jabbo16.
the class DebugManager method debugScreen.
private void debugScreen(GameState gameState) {
try {
if (!ConfigManager.getConfig().ecgConfig.debugScreen)
return;
if (gameState.naturalArea != null) {
print(gameState.naturalArea.getTop().toTilePosition(), Color.RED);
for (ChokePoint c : gameState.naturalArea.getChokePoints()) {
if (c.getGeometry().size() > 2)
mapDrawer.drawLineMap(c.getGeometry().get(0).toPosition(), c.getGeometry().get(c.getGeometry().size() - 1).toPosition(), Color.GREY);
}
}
for (ChokePoint c : gameState.bwem.getMap().getChokePoints()) {
if (c.getGeometry().size() > 2)
mapDrawer.drawLineMap(c.getGeometry().get(0).toPosition(), c.getGeometry().get(c.getGeometry().size() - 1).toPosition(), Color.GREEN);
}
/*for(Entry<Base, MutablePair<MineralPatch, MineralPatch>> u : fortressSpecialBLs.entrySet()){
if(u.getValue().first != null) bw.getMapDrawer().drawLineMap(u.getKey().getLocation().toPosition(), u.getValue().first.getPosition(),Color.RED);
if(u.getValue().second != null)bw.getMapDrawer().drawLineMap(u.getKey().getLocation().toPosition(), u.getValue().second.getPosition(),Color.ORANGE);
}*/
for (MineralPatch m : gameState.walkingMinerals) print(m, Color.RED);
for (MineralPatch d : gameState.blockingMinerals.values()) print(d, Color.RED);
int counter = 0;
for (Base b : gameState.BLs) {
mapDrawer.drawTextMap(Util.getUnitCenterPosition(b.getLocation().toPosition(), UnitType.Terran_Command_Center), ColorUtil.formatText(Integer.toString(counter), ColorUtil.White));
for (Mineral m : b.getBlockingMinerals()) print(m.getUnit(), Color.RED);
counter++;
}
for (Building b : gameState.buildingLot) print(b, Color.PURPLE);
for (Unit u : gameState.enemyInBase) print(u, Color.RED);
for (Base b : gameState.islandBases) mapDrawer.drawTextMap(b.getLocation().toPosition(), ColorUtil.formatText("Island", ColorUtil.White));
for (Unit u : gameState.islandCCs.values()) {
print(u, Color.YELLOW);
}
for (Agent ag : gameState.agents.values()) {
if (ag instanceof VultureAgent) {
VultureAgent vulture = (VultureAgent) ag;
mapDrawer.drawTextMap(vulture.myUnit.getPosition(), ColorUtil.formatText(ag.statusToString(), ColorUtil.White));
} else if (ag instanceof VesselAgent) {
VesselAgent vessel = (VesselAgent) ag;
mapDrawer.drawTextMap(vessel.myUnit.getPosition(), ColorUtil.formatText(ag.statusToString(), ColorUtil.White));
if (vessel.follow != null)
mapDrawer.drawLineMap(vessel.myUnit.getPosition(), vessel.follow.getSquadCenter(), Color.YELLOW);
} else if (ag instanceof WraithAgent) {
WraithAgent wraith = (WraithAgent) ag;
mapDrawer.drawTextMap(wraith.myUnit.getPosition().add(new Position(-16, UnitType.Terran_Wraith.dimensionUp())), ColorUtil.formatText(wraith.name, ColorUtil.White));
} else if (ag instanceof DropShipAgent) {
DropShipAgent dropShip = (DropShipAgent) ag;
mapDrawer.drawTextMap(dropShip.myUnit.getPosition(), ColorUtil.formatText(ag.statusToString(), ColorUtil.White));
} else if (ag instanceof WorkerScoutAgent) {
WorkerScoutAgent worker = (WorkerScoutAgent) ag;
mapDrawer.drawTextMap(worker.myUnit.getPosition().add(new Position(-16, UnitType.Terran_SCV.dimensionUp())), ColorUtil.formatText(worker.statusToString(), ColorUtil.White));
}
}
if (gameState.enemyStartBase != null)
mapDrawer.drawTextMap(gameState.enemyStartBase.getLocation().toPosition(), ColorUtil.formatText("EnemyStartBase", ColorUtil.White));
if (gameState.disrupterBuilding != null)
mapDrawer.drawTextMap(gameState.disrupterBuilding.getPosition().add(new Position(0, -8)), ColorUtil.formatText("BM!", ColorUtil.White));
if (gameState.enemyNaturalBase != null)
mapDrawer.drawTextMap(gameState.enemyNaturalBase.getLocation().toPosition(), ColorUtil.formatText("EnemyNaturalBase", ColorUtil.White));
if (gameState.mainChoke != null) {
mapDrawer.drawTextMap(gameState.mainChoke.getCenter().toPosition(), ColorUtil.formatText("MainChoke", ColorUtil.White));
// bw.getMapDrawer().drawTextMap(mainChoke.getCenter().toPosition(), ColorUtil.formatText(Double.toString(Util.getChokeWidth(mainChoke)), ColorUtil.White));
}
if (gameState.naturalChoke != null)
mapDrawer.drawTextMap(gameState.naturalChoke.getCenter().toPosition(), ColorUtil.formatText("NatChoke", ColorUtil.White));
if (gameState.chosenHarasser != null) {
mapDrawer.drawTextMap(gameState.chosenHarasser.getPosition(), ColorUtil.formatText("Harasser", ColorUtil.White));
print(gameState.chosenHarasser, Color.BLUE);
}
for (Map.Entry<SCV, MutablePair<UnitType, TilePosition>> u : gameState.workerBuild.entrySet()) {
print(u.getKey(), Color.TEAL);
mapDrawer.drawTextMap(u.getKey().getPosition(), ColorUtil.formatText("Building " + u.getValue().first.toString(), ColorUtil.White));
print(u.getValue().second, u.getValue().first, Color.TEAL);
mapDrawer.drawLineMap(u.getKey().getPosition(), Util.getUnitCenterPosition(u.getValue().second.toPosition(), u.getValue().first), Color.RED);
}
if (gameState.chosenUnitToHarass != null) {
print(gameState.chosenUnitToHarass, Color.RED);
mapDrawer.drawTextMap(gameState.chosenUnitToHarass.getPosition(), ColorUtil.formatText("UnitToHarass", ColorUtil.White));
}
for (Map.Entry<SCV, Mechanical> r : gameState.repairerTask.entrySet()) {
print(r.getKey(), Color.YELLOW);
mapDrawer.drawTextMap(r.getKey().getPosition(), ColorUtil.formatText("Repairer", ColorUtil.White));
if (r.getValue() == null || !r.getValue().exists())
continue;
print(r.getValue(), Color.YELLOW);
mapDrawer.drawLineMap(r.getKey().getPosition(), r.getValue().getPosition(), Color.YELLOW);
}
for (UnitInfo ui : gameState.unitStorage.getEnemyUnits().values()) {
mapDrawer.drawTextMap(ui.lastPosition.add(new Position(0, 16)), ColorUtil.formatText(ui.unitType.toString(), ColorUtil.White));
print(ui.unit, Color.RED);
}
/*for (UnitInfo ui : gameState.myArmy) {
mapDrawer.drawTextMap(ui.position.add(new Position(0, 16)), ColorUtil.formatText(ui.unitType.toString(), ColorUtil.White));
print(ui.unit, Color.BLUE);
}*/
if (gameState.chosenScout != null) {
mapDrawer.drawTextMap(gameState.chosenScout.getPosition(), ColorUtil.formatText("Scouter", ColorUtil.White));
print(gameState.chosenScout, Color.PURPLE);
}
if (gameState.chosenRepairer != null)
mapDrawer.drawTextMap(gameState.chosenRepairer.getPosition(), ColorUtil.formatText("ChosenRepairer", ColorUtil.White));
for (ChokePoint c : gameState.bwem.getMap().getChokePoints()) {
List<WalkPosition> sides = c.getGeometry();
if (sides.size() == 3) {
mapDrawer.drawLineMap(sides.get(1).toPosition(), sides.get(2).toPosition(), Color.GREEN);
}
}
for (Unit u : gameState.CCs.values()) {
print(u, Color.YELLOW);
mapDrawer.drawCircleMap(u.getPosition(), 500, Color.ORANGE);
}
for (Unit u : gameState.DBs.keySet()) {
mapDrawer.drawCircleMap(u.getPosition(), 300, Color.ORANGE);
}
for (Unit u : gameState.workerIdle) print(u, Color.ORANGE);
for (Map.Entry<SCV, Building> u : gameState.workerTask.entrySet()) {
print(u.getKey(), Color.TEAL);
mapDrawer.drawTextMap(u.getKey().getPosition(), ColorUtil.formatText("Tasked: " + u.getValue().getType().toString(), ColorUtil.White));
print(u.getValue(), Color.TEAL);
mapDrawer.drawLineMap(u.getKey().getPosition(), u.getValue().getPosition(), Color.RED);
}
for (Worker u : gameState.workerDefenders.keySet()) {
print(u, Color.PURPLE);
mapDrawer.drawTextMap(u.getPosition(), ColorUtil.formatText("SpartanSCV", ColorUtil.White));
}
for (Map.Entry<Worker, MineralPatch> u : gameState.workerMining.entrySet()) {
print(u.getKey(), Color.CYAN);
mapDrawer.drawLineMap(u.getKey().getPosition(), u.getValue().getPosition(), Color.CYAN);
}
for (Map.Entry<Worker, GasMiningFacility> u : gameState.workerGas.entrySet()) {
if (u.getKey().getOrder() == Order.HarvestGas)
continue;
print(u.getKey(), Color.GREEN);
mapDrawer.drawLineMap(u.getKey().getPosition(), u.getValue().getPosition(), Color.GREEN);
}
for (Map.Entry<VespeneGeyser, Boolean> u : gameState.vespeneGeysers.entrySet()) {
print(u.getKey(), Color.GREEN);
if (gameState.refineriesAssigned.containsKey(u.getKey())) {
int gas = gameState.refineriesAssigned.get(u.getKey());
mapDrawer.drawTextMap(u.getKey().getPosition(), ColorUtil.formatText(Integer.toString(gas), ColorUtil.White));
}
}
gameState.sim.drawClusters();
for (Squad s : gameState.sqManager.squads.values()) {
if (s.status == Squad.Status.ATTACK && s.attack != null)
mapDrawer.drawLineMap(s.getSquadCenter(), s.attack, Color.ORANGE);
}
for (Squad s : gameState.sqManager.squads.values()) {
if (s.members.isEmpty())
continue;
Position center = s.getSquadCenter();
// mapDrawer.drawCircleMap(center, 90, Color.GREEN);
mapDrawer.drawTextMap(center.add(new Position(0, UnitType.Terran_Marine.dimensionUp())), ColorUtil.formatText(s.status.toString(), ColorUtil.White));
mapDrawer.drawTextMap(center.add(new Position(0, UnitType.Terran_Marine.dimensionUp() * 2)), ColorUtil.formatText(s.lose ? "Lose" : "Win", ColorUtil.White));
}
for (Map.Entry<MineralPatch, Integer> m : gameState.mineralsAssigned.entrySet()) {
print(m.getKey(), Color.CYAN);
if (m.getValue() == 0)
continue;
mapDrawer.drawTextMap(m.getKey().getPosition(), ColorUtil.formatText(m.getValue().toString(), ColorUtil.White));
}
} catch (Exception e) {
System.err.println("debugScreen Exception");
e.printStackTrace();
}
}
use of bwem.ChokePoint in project Ecgberht by Jabbo16.
the class BuildingMap method findBunkerPositionAntiPool.
public TilePosition findBunkerPositionAntiPool() {
TilePosition starting = getGs().MBs.iterator().next().getTilePosition();
TilePosition buildingSize = UnitType.Terran_Bunker.tileSize();
int size = Math.max(buildingSize.getY(), buildingSize.getX());
int x = starting.getY();
int y = starting.getX();
ChokePoint choke = getGs().mainChoke;
int i = 4;
int j = 4;
// Finds the first valid tileposition starting around the given tileposition
TilePosition bunkerPlace = null;
double dist = Double.MAX_VALUE;
for (int ii = (x - i); ii <= (x + i); ii++) {
for (int jj = (y - j); jj <= (y + j); jj++) {
if ((ii >= 0 && ii < height) && (jj >= 0 && jj < width)) {
if ((!map[ii][jj].equals("M") && !map[ii][jj].equals("V") && !map[ii][jj].equals("E") && !map[ii][jj].equals("B")) && Integer.parseInt(map[ii][jj]) >= size) {
if (bwem.getMap().getArea(new TilePosition(jj, ii)).equals(getGs().naturalArea))
continue;
if (checkUnitsChosenBuildingGrid(new TilePosition(jj, ii), UnitType.Terran_Bunker)) {
TilePosition newPosition = new TilePosition(jj, ii);
double newDist = Util.broodWarDistance(Util.getUnitCenterPosition(newPosition.toPosition(), UnitType.Terran_Bunker), choke.getCenter().toPosition());
if (bunkerPlace == null || newDist < dist) {
bunkerPlace = newPosition;
dist = newDist;
}
}
}
}
}
}
return bunkerPlace;
}
Aggregations