Search in sources :

Example 16 with TilePosition

use of org.openbw.bwapi4j.TilePosition in project Ecgberht by Jabbo16.

the class CameraModule method isNearStartLocation.

private boolean isNearStartLocation(Position pos) {
    int distance = 1000;
    List<TilePosition> startLocations = game.getBWMap().getStartPositions();
    for (TilePosition it : startLocations) {
        Position startLocation = it.toPosition();
        // if the start position is not our own home, and the start position is closer than distance
        if (!isNearOwnStartLocation(startLocation) && startLocation.getDistance(pos) <= distance)
            return true;
    }
    return false;
}
Also used : TilePosition(org.openbw.bwapi4j.TilePosition) Position(org.openbw.bwapi4j.Position) TilePosition(org.openbw.bwapi4j.TilePosition)

Example 17 with TilePosition

use of org.openbw.bwapi4j.TilePosition in project Ecgberht by Jabbo16.

the class WorkerScoutAgent method canProxyInThisMap.

private void canProxyInThisMap() {
    Area enemyArea = this.enemyBase.getArea();
    Set<TilePosition> tilesArea = getGs().map.getTilesArea(enemyArea);
    if (tilesArea == null)
        return;
    Result path = getGs().silentCartographer.getWalkablePath(enemyBase.getLocation().toWalkPosition(), getGs().enemyNaturalBase.getLocation().toWalkPosition());
    for (TilePosition t : tilesArea) {
        if (!getGs().map.tileBuildable(t, UnitType.Terran_Factory))
            continue;
        if (t.getDistance(Util.getUnitCenterPosition(enemyBase.getLocation().toPosition(), UnitType.Zerg_Hatchery).toTilePosition()) <= 13)
            continue;
        if (enemyBase.getGeysers().stream().anyMatch(u -> t.getDistance(u.getCenter().toTilePosition()) <= 9))
            continue;
        if (path.path.stream().anyMatch(u -> t.getDistance(new WalkPosition(u.x, u.y).toTilePosition()) <= 10))
            continue;
        validTiles.add(t);
    }
    if (validTiles.isEmpty())
        return;
    double bestDist = 0.0;
    for (TilePosition p : validTiles) {
        double dist = p.getDistance(enemyBase.getLocation());
        if (dist > bestDist) {
            bestDist = dist;
            proxyTile = p;
        }
    }
    if (proxyTile != null)
        ableToProxy = true;
}
Also used : Area(bwem.Area) TilePosition(org.openbw.bwapi4j.TilePosition) WalkPosition(org.openbw.bwapi4j.WalkPosition) Result(org.bk.ass.path.Result)

Example 18 with TilePosition

use of org.openbw.bwapi4j.TilePosition in project Ecgberht by Jabbo16.

the class WorkerScoutAgent method updateBorders.

private void updateBorders() {
    final Area enemyRegion = enemyBase.getArea();
    if (enemyRegion == null)
        return;
    final Position enemyCenter = enemyBase.getLocation().toPosition().add(new Position(64, 48));
    final List<TilePosition> closestTobase = new ArrayList<>(BuildingMap.tilesArea.get(enemyRegion));
    List<Position> unsortedVertices = new ArrayList<>();
    for (TilePosition tp : closestTobase) {
        if (getGs().bwem.getMap().getArea(tp) != enemyRegion)
            continue;
        TilePosition right = new TilePosition(tp.getX() + 1, tp.getY());
        TilePosition bottom = new TilePosition(tp.getX(), tp.getY() + 1);
        TilePosition left = new TilePosition(tp.getX() - 1, tp.getY());
        TilePosition up = new TilePosition(tp.getX(), tp.getY() - 1);
        final boolean edge = (!getGs().getGame().getBWMap().isValidPosition(right) || getGs().bwem.getMap().getArea(right) != enemyRegion || !getGs().getGame().getBWMap().isBuildable(right)) || (!getGs().getGame().getBWMap().isValidPosition(bottom) || getGs().bwem.getMap().getArea(bottom) != enemyRegion || !getGs().getGame().getBWMap().isBuildable(bottom)) || (!getGs().getGame().getBWMap().isValidPosition(left) || getGs().bwem.getMap().getArea(left) != enemyRegion || !getGs().getGame().getBWMap().isBuildable(left)) || (!getGs().getGame().getBWMap().isValidPosition(up) || getGs().bwem.getMap().getArea(up) != enemyRegion || !getGs().getGame().getBWMap().isBuildable(up));
        if (edge && getGs().getGame().getBWMap().isBuildable(tp)) {
            Position vertex = tp.toPosition().add(new Position(16, 16));
            double dist = enemyCenter.getDistance(vertex);
            if (dist > 368.0) {
                double pullBy = Math.min(dist - 368.0, 120.0);
                if (vertex.getX() == enemyCenter.getX()) {
                    vertex = vertex.add(new Position(0, vertex.getY() > enemyCenter.getY() ? (int) (-pullBy) : (int) pullBy));
                } else {
                    double m = (double) (enemyCenter.getY() - vertex.getY()) / (double) (enemyCenter.getX() - vertex.getX());
                    double x = vertex.getX() + (vertex.getX() > enemyCenter.getX() ? -1.0 : 1.0) * pullBy / (Math.sqrt(1 + m * m));
                    double y = m * (x - vertex.getX()) + vertex.getY();
                    vertex = new Position((int) x, (int) y);
                }
            }
            if (getGs().getGame().getBWMap().isValidPosition(vertex) && getGs().getGame().getBWMap().isWalkable(vertex.toWalkPosition()))
                unsortedVertices.add(vertex);
        }
    }
    List<Position> sortedVertices = new ArrayList<>();
    Position current = unsortedVertices.get(0);
    enemyBaseBorders.add(current);
    unsortedVertices.remove(current);
    while (!unsortedVertices.isEmpty()) {
        double bestDist = 1000000;
        Position bestPos = null;
        for (final Position pos : unsortedVertices) {
            double dist = pos.getDistance(current);
            if (dist < bestDist) {
                bestDist = dist;
                bestPos = pos;
            }
        }
        current = bestPos;
        sortedVertices.add(sortedVertices.size(), bestPos);
        unsortedVertices.remove(bestPos);
    }
    int distanceThreshold = 100;
    while (true) {
        int maxFarthest = 0;
        int maxFarthestStart = 0;
        int maxFarthestEnd = 0;
        for (int i = 0; i < sortedVertices.size(); ++i) {
            int farthest = 0;
            int farthestIndex = 0;
            for (int j = 1; j < sortedVertices.size() / 2; ++j) {
                int jindex = (i + j) % sortedVertices.size();
                if (sortedVertices.get(i).getDistance(sortedVertices.get(jindex)) < distanceThreshold) {
                    farthest = j;
                    farthestIndex = jindex;
                }
            }
            if (farthest > maxFarthest) {
                maxFarthest = farthest;
                maxFarthestStart = i;
                maxFarthestEnd = farthestIndex;
            }
        }
        if (maxFarthest < 4)
            break;
        List<Position> temp = new ArrayList<>();
        for (int s = maxFarthestEnd; s != maxFarthestStart; s = (s + 1) % sortedVertices.size()) {
            temp.add(temp.size(), sortedVertices.get(s));
        }
        sortedVertices = temp;
    }
    enemyBaseBorders = sortedVertices;
    currentVertex = 0;
    if (!getGs().learningManager.isNaughty()) {
        Base enemyNatural = getGs().enemyNaturalBase;
        if (enemyNatural != null) {
            Position enemyNaturalPos = enemyNatural.getLocation().toPosition();
            int index = -1;
            double distMax = Double.MAX_VALUE;
            for (int ii = 0; ii < enemyBaseBorders.size(); ii++) {
                double dist = Util.getGroundDistance(enemyBaseBorders.get(ii), enemyNaturalPos);
                if (index == -1 || dist < distMax) {
                    index = ii;
                    distMax = dist;
                }
            }
            enemyBaseBorders.add(index, enemyNaturalPos);
            this.enemyNaturalIndex = index;
        }
    } else {
        enemyNaturalIndex = -1;
        removedIndex = true;
    }
}
Also used : Area(bwem.Area) WalkPosition(org.openbw.bwapi4j.WalkPosition) TilePosition(org.openbw.bwapi4j.TilePosition) Position(org.openbw.bwapi4j.Position) TilePosition(org.openbw.bwapi4j.TilePosition) ArrayList(java.util.ArrayList) Base(bwem.Base)

Example 19 with TilePosition

use of org.openbw.bwapi4j.TilePosition in project Ecgberht by Jabbo16.

the class BuildingMap method findBunkerPosition.

public TilePosition findBunkerPosition(ChokePoint choke) {
    TilePosition buildingSize = UnitType.Terran_Bunker.tileSize();
    int size = Math.max(buildingSize.getY(), buildingSize.getX());
    double chokeWidth = Util.getChokeWidth(choke);
    Position starting = choke.getCenter().toPosition();
    int x = starting.toTilePosition().getY();
    int y = starting.toTilePosition().getX();
    int i = 10;
    int j = 10;
    boolean expandBunker = choke.equals(getGs().naturalChoke);
    // Finds the first valid tileposition starting around the given tileposition
    TilePosition position = 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) {
                    Area area = bwem.getMap().getArea(new TilePosition(jj, ii));
                    if (area != null && area.equals(getGs().naturalArea) && !expandBunker)
                        continue;
                    if (area != null && !area.equals(getGs().naturalArea) && expandBunker)
                        continue;
                    if (checkUnitsChosenBuildingGrid(new TilePosition(jj, ii), UnitType.Terran_Bunker)) {
                        TilePosition newPosition = new TilePosition(jj, ii);
                        Position centerBunker = Util.getUnitCenterPosition(newPosition.toPosition(), UnitType.Terran_Bunker);
                        if (chokeWidth <= 64.0 && Util.broodWarDistance(choke.getCenter().toPosition(), centerBunker) <= 64)
                            continue;
                        double newDist = Util.broodWarDistance(centerBunker, starting);
                        if (position == null || newDist < dist) {
                            position = newPosition;
                            dist = newDist;
                        }
                    }
                }
            }
        }
    }
    return position;
}
Also used : Area(bwem.Area) TilePosition(org.openbw.bwapi4j.TilePosition) Position(org.openbw.bwapi4j.Position) TilePosition(org.openbw.bwapi4j.TilePosition) ChokePoint(bwem.ChokePoint)

Example 20 with TilePosition

use of org.openbw.bwapi4j.TilePosition in project Ecgberht by Jabbo16.

the class BuildingMap method checkUnitsChosenBuildingGrid.

private boolean checkUnitsChosenBuildingGrid(TilePosition BL, UnitType type) {
    try {
        Position topLeft = new Position(BL.getX() * TilePosition.SIZE_IN_PIXELS, BL.getY() * TilePosition.SIZE_IN_PIXELS);
        Position bottomRight = new Position(topLeft.getX() + type.tileWidth() * TilePosition.SIZE_IN_PIXELS, topLeft.getY() + type.tileHeight() * TilePosition.SIZE_IN_PIXELS);
        // Test
        List<Unit> blockers = Util.getUnitsInRectangle(topLeft, bottomRight);
        if (blockers.isEmpty() && !getGs().getGame().canBuildHere(BL, type))
            return false;
        if (blockers.isEmpty())
            return true;
        if (blockers.size() > 1)
            return false;
        else {
            Unit blocker = blockers.get(0);
            return blocker instanceof PlayerUnit && ((PlayerUnit) blocker).getPlayer().getId() == self.getId() && blocker instanceof Worker && ((Worker) blocker).getBuildType() == type;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}
Also used : TilePosition(org.openbw.bwapi4j.TilePosition) Position(org.openbw.bwapi4j.Position) IOException(java.io.IOException)

Aggregations

TilePosition (org.openbw.bwapi4j.TilePosition)46 ChokePoint (bwem.ChokePoint)13 Position (org.openbw.bwapi4j.Position)13 Area (bwem.Area)9 WalkPosition (org.openbw.bwapi4j.WalkPosition)8 Base (bwem.Base)7 MiniTile (bwem.tile.MiniTile)7 Tile (bwem.tile.Tile)7 ArrayList (java.util.ArrayList)7 UnitType (org.openbw.bwapi4j.type.UnitType)6 TileImpl (bwem.tile.TileImpl)4 Geyser (bwem.unit.Geyser)4 Mineral (bwem.unit.Mineral)4 Worker (org.openbw.bwapi4j.unit.Worker)4 MutablePair (ecgberht.Util.MutablePair)3 Building (org.openbw.bwapi4j.unit.Building)3 MineralPatch (org.openbw.bwapi4j.unit.MineralPatch)3 SCV (org.openbw.bwapi4j.unit.SCV)3 Area (bwem.area.Area)2 StaticBuilding (bwem.unit.StaticBuilding)2