Search in sources :

Example 1 with TilePosition

use of bwapi.TilePosition in project Ecgberht by Jabbo16.

the class CheckResourcesBuilding method execute.

@Override
public State execute() {
    try {
        Pair<Integer, Integer> cash = ((GameState) this.handler).getCash();
        Unit chosen = ((GameState) this.handler).chosenWorker;
        TilePosition start = chosen.getTilePosition();
        TilePosition end = ((GameState) this.handler).chosenPosition;
        Position realEnd = ((GameState) this.handler).getCenterFromBuilding(end.toPosition(), ((GameState) this.handler).chosenToBuild);
        if (cash.first + ((GameState) this.handler).getMineralsWhenReaching(chosen, start, realEnd.toTilePosition()) >= (((GameState) this.handler).chosenToBuild.mineralPrice() + ((GameState) this.handler).deltaCash.first) && cash.second >= (((GameState) this.handler).chosenToBuild.gasPrice()) + ((GameState) this.handler).deltaCash.second) {
            return State.SUCCESS;
        }
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        System.err.println(e);
        return State.ERROR;
    }
}
Also used : TilePosition(bwapi.TilePosition) Position(bwapi.Position) TilePosition(bwapi.TilePosition) GameState(ecgberht.GameState) Unit(bwapi.Unit)

Example 2 with TilePosition

use of bwapi.TilePosition in project Ecgberht by Jabbo16.

the class ChoosePosition method execute.

@Override
public State execute() {
    try {
        Game juego = ((GameState) this.handler).getGame();
        Player jugador = ((GameState) this.handler).getPlayer();
        TilePosition origin = null;
        if (((GameState) this.handler).chosenToBuild.isRefinery()) {
            if (!((GameState) this.handler).refineriesAssigned.isEmpty()) {
                for (Pair<Pair<Unit, Integer>, Boolean> g : ((GameState) this.handler).refineriesAssigned) {
                    if (!g.second) {
                        ((GameState) this.handler).chosenPosition = g.first.first.getTilePosition();
                        return State.SUCCESS;
                    }
                }
            }
        } else {
            if (!((GameState) this.handler).workerBuild.isEmpty()) {
                for (Pair<Unit, Pair<UnitType, TilePosition>> w : ((GameState) this.handler).workerBuild) {
                    ((GameState) this.handler).testMap.updateMap(w.second.second, w.second.first, false);
                }
            }
            if (!((GameState) this.handler).chosenToBuild.equals(UnitType.Terran_Bunker) && !((GameState) this.handler).chosenToBuild.equals(UnitType.Terran_Missile_Turret)) {
                if (((GameState) this.handler).strat.proxy && ((GameState) this.handler).chosenToBuild == UnitType.Terran_Barracks) {
                    origin = new TilePosition(((GameState) this.handler).getGame().mapWidth() / 2, ((GameState) this.handler).getGame().mapHeight() / 2);
                } else {
                    // origin = BWTA.getRegion(jugador.getStartLocation()).getCenter().toTilePosition();
                    origin = jugador.getStartLocation();
                }
            } else {
                if (((GameState) this.handler).chosenToBuild.equals(UnitType.Terran_Missile_Turret)) {
                    if (((GameState) this.handler).DBs.isEmpty()) {
                        origin = BWTA.getNearestChokepoint(jugador.getStartLocation()).getCenter().toTilePosition();
                    } else {
                        for (Unit b : ((GameState) this.handler).DBs.keySet()) {
                            origin = b.getTilePosition();
                            break;
                        }
                    }
                } else {
                    if (((GameState) this.handler).EI.naughty && ((GameState) this.handler).enemyRace == Race.Zerg) {
                        TilePosition raxTile = ((GameState) this.handler).MBs.iterator().next().getTilePosition();
                        origin = ((GameState) this.handler).testMap.findBunkerPositionAntiPool(raxTile.toPosition(), ((GameState) this.handler).closestChoke);
                        if (origin != null) {
                            ((GameState) this.handler).testMap = ((GameState) this.handler).map.clone();
                            ((GameState) this.handler).chosenPosition = origin;
                            return State.SUCCESS;
                        } else {
                            origin = ((GameState) this.handler).getBunkerPositionAntiPool();
                            if (origin != null) {
                                ((GameState) this.handler).testMap = ((GameState) this.handler).map.clone();
                                ((GameState) this.handler).chosenPosition = origin;
                                return State.SUCCESS;
                            } else {
                                origin = raxTile;
                            }
                        }
                    } else {
                        if (((GameState) this.handler).Ts.isEmpty()) {
                            if (((GameState) this.handler).closestChoke != null) {
                                origin = ((GameState) this.handler).testMap.findBunkerPosition(((GameState) this.handler).closestChoke);
                                if (origin != null) {
                                    ((GameState) this.handler).testMap = ((GameState) this.handler).map.clone();
                                    ((GameState) this.handler).chosenPosition = origin;
                                    return State.SUCCESS;
                                } else {
                                    origin = ((GameState) this.handler).closestChoke.getCenter().toTilePosition();
                                }
                            }
                        // else {
                        // origin = BWTA.getNearestChokepoint(jugador.getStartLocation()).getCenter().toTilePosition();
                        // }
                        } else {
                            for (Unit b : ((GameState) this.handler).Ts) {
                                origin = b.getTilePosition();
                                break;
                            }
                        }
                    }
                }
            }
            TilePosition posicion = ((GameState) this.handler).testMap.findPosition(((GameState) this.handler).chosenToBuild, origin);
            ((GameState) this.handler).testMap = ((GameState) this.handler).map.clone();
            if (posicion != null) {
                ((GameState) this.handler).chosenPosition = posicion;
                return State.SUCCESS;
            }
        }
        TilePosition posicion = juego.getBuildLocation(((GameState) this.handler).chosenToBuild, BWTA.getRegion(jugador.getStartLocation()).getCenter().toTilePosition(), 500);
        if (posicion != null) {
            if (juego.canBuildHere(posicion, ((GameState) this.handler).chosenToBuild)) {
                ((GameState) this.handler).chosenPosition = posicion;
                return State.SUCCESS;
            }
        }
        return State.FAILURE;
    } catch (Exception e) {
        System.err.println(this.getClass().getSimpleName());
        System.err.println(e);
        return State.ERROR;
    }
}
Also used : Player(bwapi.Player) Game(bwapi.Game) TilePosition(bwapi.TilePosition) GameState(ecgberht.GameState) Unit(bwapi.Unit) Pair(bwapi.Pair)

Example 3 with TilePosition

use of bwapi.TilePosition in project BWJSAL by RobinsonMann.

the class InformationManagerAcceptanceTest method resourceDepotToBaseLocationMappingCorrectlyKeptUpToDate.

/**
 * Verify that enemy base location manually set via setBaseAsEnemy is removed
 * when a command center that was later observed is destroyed.
 *
 * This test verifies that base locations can be tied to resource depots even
 * if the base location was already marked as an enemy location.
 */
@Test
public void resourceDepotToBaseLocationMappingCorrectlyKeptUpToDate() {
    final Race enemyRace = createMockRace(mock(UnitType.class), mock(UnitType.class));
    when(this.enemy.getRace()).thenReturn(enemyRace);
    final BaseLocation selfStartingLocation = mock(BaseLocation.class);
    final BaseLocation enemyStartingLocation = mock(BaseLocation.class);
    final BaseLocation otherStartingLocation = mock(BaseLocation.class);
    setStartingLocationsOnMock(this.bwtaWrapper, selfStartingLocation, enemyStartingLocation, otherStartingLocation);
    setSelfStartingLocationOnMock(this.bwtaWrapper, this.self, selfStartingLocation);
    this.target.onStart();
    assertThat(this.target.getEnemyBases()).as("no known enemy bases").isEmpty();
    // manually set base as enemy
    this.target.setBaseAsEnemy(enemyStartingLocation);
    assertThat(this.target.getEnemyBases()).as("sanctity test that setBaseAsEnemy actual sets the base as an enemy base").containsExactly(enemyStartingLocation);
    // observe enemy command center in enemy base
    final TilePosition commandCenterPosition = mock(TilePosition.class);
    setNearestBaseLocationOnMock(this.bwtaWrapper, commandCenterPosition, enemyStartingLocation);
    final Unit commandCenter = UnitBuilder.mockUnit(this.enemy, mockResourceDepotUnitType(), commandCenterPosition);
    this.target.onUnitDiscover(commandCenter);
    // command center destroyed
    this.target.onUnitDestroy(commandCenter);
    // verify location is not enemy
    assertThat(this.target.getEnemyBases()).as("because all bases mapped to base location have been destroyed, no more bases for enemy").isEmpty();
}
Also used : UnitType(bwapi.UnitType) UnitTypeUtils.mockResourceDepotUnitType(BWJSAL.utils.UnitTypeUtils.mockResourceDepotUnitType) RaceUtils.createMockRace(BWJSAL.utils.RaceUtils.createMockRace) Race(bwapi.Race) TilePosition(bwapi.TilePosition) Unit(bwapi.Unit) BaseLocation(bwta.BaseLocation) Test(org.junit.Test)

Example 4 with TilePosition

use of bwapi.TilePosition in project BWJSAL by RobinsonMann.

the class ReservedMapTest method freeTiles_tilePosition_freeSingleTile.

@Test
public void freeTiles_tilePosition_freeSingleTile() {
    final TilePosition tilePosition = new TilePosition(1, 2);
    this.target.reserveTiles(tilePosition);
    assertThatTileReserved(tilePosition);
    this.target.freeTiles(tilePosition);
    assertThatTileNotReserved(tilePosition);
}
Also used : TilePosition(bwapi.TilePosition) Test(org.junit.Test)

Example 5 with TilePosition

use of bwapi.TilePosition in project BWJSAL by RobinsonMann.

the class ReservedMapTest method isReserved_tilePosition_reserved.

@Test
public void isReserved_tilePosition_reserved() {
    final TilePosition tilePosition = new TilePosition(2, 2);
    this.target.reserveTiles(tilePosition);
    assertThat(this.target.isReserved(tilePosition)).isTrue();
}
Also used : TilePosition(bwapi.TilePosition) Test(org.junit.Test)

Aggregations

TilePosition (bwapi.TilePosition)22 Test (org.junit.Test)13 Unit (bwapi.Unit)9 UnitType (bwapi.UnitType)6 GameState (ecgberht.GameState)5 BaseLocation (bwta.BaseLocation)4 Pair (bwapi.Pair)3 RaceUtils.createMockRace (BWJSAL.utils.RaceUtils.createMockRace)2 UnitTypeUtils.mockResourceDepotUnitType (BWJSAL.utils.UnitTypeUtils.mockResourceDepotUnitType)2 Position (bwapi.Position)2 Race (bwapi.Race)2 Game (bwapi.Game)1 Player (bwapi.Player)1 EnemyBuilding (ecgberht.EnemyBuilding)1 Squad (ecgberht.Squad)1 Point (java.awt.Point)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 PriorityQueue (java.util.PriorityQueue)1