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