Search in sources :

Example 41 with TilePosition

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

the class CheckResourcesIsland method execute.

@Override
public State execute() {
    try {
        MutablePair<Integer, Integer> cash = gameState.getCash();
        Worker chosen = gameState.chosenWorkerDrop;
        UnitType chosenType = UnitType.Terran_Command_Center;
        TilePosition start = chosen.getTilePosition();
        TilePosition end = gameState.chosenIsland.getLocation();
        Position realEnd = Util.getUnitCenterPosition(end.toPosition(), chosenType);
        if (cash.first + gameState.getMineralsWhenReaching(start, realEnd.toTilePosition()) >= chosenType.mineralPrice() + gameState.deltaCash.first) {
            return State.SUCCESS;
        }
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        e.printStackTrace();
        return State.ERROR;
    }
}
Also used : TilePosition(org.openbw.bwapi4j.TilePosition) Position(org.openbw.bwapi4j.Position) UnitType(org.openbw.bwapi4j.type.UnitType) TilePosition(org.openbw.bwapi4j.TilePosition) Worker(org.openbw.bwapi4j.unit.Worker)

Example 42 with TilePosition

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

the class BuildingMap method updateMap.

// Updates a portion of the map around the building
public void updateMap(TilePosition position, UnitType building, boolean destroyed) {
    TilePosition buildingSize = building.tileSize();
    int tamY = buildingSize.getY();
    int tamX = buildingSize.getX();
    // Updates the map with the next building to be built
    for (int i = position.getY() - 1; i < position.getY() + tamY + 1; i++) {
        for (int j = position.getX() - 1; j < position.getX() + tamX + 1; j++) {
            if (i < 0 || i >= height || j < 0 || j >= width)
                continue;
            if (destroyed) {
                if (i == position.getY() - 1 || i == position.getY() + tamY || j == position.getX() - 1 || j == position.getX() + tamX) {
                    if (!map[i][j].equals("0"))
                        map[i][j] = "6";
                } else if (!map[i][j].equals("V"))
                    map[i][j] = "6";
            } else if (i != position.getY() - 1 && i != position.getY() + tamY && j != position.getX() - 1 && j != position.getX() + tamX) {
                if (!map[i][j].equals("M") && !map[i][j].equals("V") && !map[i][j].equals("0") && !map[i][j].equals("E") && !map[i][j].equals("B")) {
                    if (building == UnitType.Terran_Bunker)
                        map[i][j] = "0";
                    else
                        map[i][j] = "E";
                }
            }
        }
    }
    if (building.canBuildAddon()) {
        for (int i = position.getY() + tamY; i > position.getY() + tamY - 4; i--) {
            for (int j = position.getX() + tamX - 1; j < position.getX() + tamX + 3; j++) {
                if (i < 0 || i >= height || j < 0 || j >= width)
                    continue;
                if (destroyed) {
                    if (i == position.getY() + tamY - 3 || i == position.getY() + tamY || j == position.getX() + tamX + 2 || j == position.getX() + tamX - 1) {
                        if (!map[i][j].equals("0"))
                            map[i][j] = "6";
                    } else if (!map[i][j].equals("V"))
                        map[i][j] = "6";
                } else if (i != position.getY() + tamY - 3 && i != position.getY() + tamY && j != position.getX() + tamX + 2 && j != position.getX() + tamX - 1) {
                    if (!map[i][j].equals("M") && !map[i][j].equals("V") && !map[i][j].equals("0") && !map[i][j].equals("E") && !map[i][j].equals("B")) {
                        map[i][j] = "E";
                    }
                }
            }
        }
    }
    // Finds the corners around the building
    int init_i = 0;
    if (position.getY() - height > 0)
        init_i = position.getY() - height;
    int end_i = height;
    if (position.getY() + tamY + height < height)
        end_i = position.getY() + tamY + height;
    int init_j = 0;
    if (position.getX() - width > 0)
        init_j = position.getX() - width;
    int fin_j = width;
    if (position.getX() + tamX + width < width)
        fin_j = position.getX() + tamX + width;
    // Generates a submatrix as a portion of the map delimited by the corners and resets the 1,2,3 values for 4
    String[][] submap = new String[end_i - init_i][fin_j - init_j];
    int i = 0;
    int j;
    for (int ii = init_i; ii < end_i; ii++) {
        j = 0;
        for (int jj = init_j; jj < fin_j; jj++) {
            if (map[ii][jj].equals("M") || map[ii][jj].equals("V") || map[ii][jj].equals("0") || map[ii][jj].equals("E") || map[ii][jj].equals("B")) {
                submap[i][j] = map[ii][jj];
            } else
                submap[i][j] = "6";
            j++;
        }
        i++;
    }
    submap = fillMap(submap);
    // Updates the map using the submatrix
    i = 0;
    for (int ii = init_i; ii < end_i; ii++) {
        j = 0;
        for (int jj = init_j; jj < fin_j; jj++) {
            map[ii][jj] = submap[i][j];
            j++;
        }
        i++;
    }
}
Also used : TilePosition(org.openbw.bwapi4j.TilePosition) ChokePoint(bwem.ChokePoint)

Example 43 with TilePosition

use of org.openbw.bwapi4j.TilePosition 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;
}
Also used : TilePosition(org.openbw.bwapi4j.TilePosition) ChokePoint(bwem.ChokePoint) ChokePoint(bwem.ChokePoint)

Example 44 with TilePosition

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

the class AreaInitializer method computeDistances.

int[] computeDistances(final ChokePoint startCP, final List<ChokePoint> targetCPs) {
    if (targetCPs.contains(startCP)) {
        map.asserter.throwIllegalStateException("");
    }
    final TilePosition start = this.map.breadthFirstSearch(startCP.getNodePositionInArea(ChokePoint.Node.MIDDLE, this).toTilePosition(), // findCond
    (Tile tile, TilePosition unused) -> tile.getAreaId().equals(getId()), // visitCond
    (Tile tile, TilePosition unused) -> true);
    final List<TilePosition> targets = new ArrayList<>();
    for (final ChokePoint cp : targetCPs) {
        final TilePosition t = this.map.breadthFirstSearch(cp.getNodePositionInArea(ChokePoint.Node.MIDDLE, this).toTilePosition(), // findCond
        (Tile tile, TilePosition position) -> (tile.getAreaId().equals(getId())), // visitCond
        (Tile tile, TilePosition unused) -> true);
        targets.add(t);
    }
    return computeDistances(start, targets);
}
Also used : TilePosition(org.openbw.bwapi4j.TilePosition)

Example 45 with TilePosition

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

the class AreaInitializer method validateBaseLocation.

private boolean validateBaseLocation(final TerrainData terrainData, final TilePosition location, final List<Mineral> blockingMinerals) {
    final TilePosition dimCC = UnitType.Terran_Command_Center.tileSize();
    blockingMinerals.clear();
    for (int dy = -3; dy < dimCC.getY() + 3; ++dy) {
        for (int dx = -3; dx < dimCC.getX() + 3; ++dx) {
            final TilePosition deltaLocation = location.add(new TilePosition(dx, dy));
            if (terrainData.getMapData().isValid(deltaLocation)) {
                final Tile deltaTile = terrainData.getTile(deltaLocation, CheckMode.NO_CHECK);
                final Neutral deltaTileNeutral = deltaTile.getNeutral();
                if (deltaTileNeutral != null) {
                    if (deltaTileNeutral instanceof Geyser) {
                        return false;
                    } else if (deltaTileNeutral instanceof Mineral) {
                        final Mineral deltaTileMineral = (Mineral) deltaTileNeutral;
                        if (deltaTileMineral.getInitialAmount() <= 8) {
                            blockingMinerals.add(deltaTileMineral);
                        } else {
                            return false;
                        }
                    }
                }
            }
        }
    }
    // checks the distance to the bases already created:
    for (final Base base : getBases()) {
        if (BwemExt.roundedDist(base.getLocation(), location) < BwemExt.MIN_TILES_BETWEEN_BASES) {
            return false;
        }
    }
    return true;
}
Also used : TilePosition(org.openbw.bwapi4j.TilePosition)

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