use of bwapi.TilePosition in project BWJSAL by RobinsonMann.
the class ReservedMapTest method canBuildHere_gameCanBuildHereFalse.
@Test
public void canBuildHere_gameCanBuildHereFalse() {
final TilePosition positionToBuild = new TilePosition(2, 2);
final Unit builder = Mockito.mock(Unit.class);
final UnitType typeToBuild = Mockito.mock(UnitType.class);
verifyNoMoreInteractions(typeToBuild);
when(this.mockGame.canBuildHere(positionToBuild, typeToBuild, builder)).thenReturn(false);
assertThat(this.target.canBuildHere(builder, positionToBuild, typeToBuild)).isFalse();
verify(this.mockGame).canBuildHere(positionToBuild, typeToBuild, builder);
}
use of bwapi.TilePosition in project BWJSAL by RobinsonMann.
the class ReservedMapTest method canBuildHere_partialTilesReserved.
@Test
public void canBuildHere_partialTilesReserved() {
final TilePosition positionToBuild = new TilePosition(2, 2);
final Unit builder = Mockito.mock(Unit.class);
final UnitType typeToBuild = Mockito.mock(UnitType.class);
when(typeToBuild.tileWidth()).thenReturn(2);
when(typeToBuild.tileHeight()).thenReturn(2);
when(this.mockGame.canBuildHere(positionToBuild, typeToBuild, builder)).thenReturn(true);
this.target.reserveTiles(3, 3);
assertThat(this.target.canBuildHere(builder, positionToBuild, typeToBuild)).isFalse();
verify(this.mockGame).canBuildHere(positionToBuild, typeToBuild, builder);
verify(typeToBuild, times(1)).tileWidth();
verify(typeToBuild, times(1)).tileHeight();
}
use of bwapi.TilePosition in project BWJSAL by RobinsonMann.
the class ReservedMapTest method reserveTiles_tilePosition_customWidth.
@Test
public void reserveTiles_tilePosition_customWidth() {
final TilePosition tilePosition = new TilePosition(1, 1);
final int width = 2, height = 3;
this.target.reserveTiles(tilePosition, UnitType.Terran_Barracks, width, height);
assertThatOnlyRectangleReserved(tilePosition, width, height);
assertTileReservedType(tilePosition, UnitType.Terran_Barracks, width, height);
}
use of bwapi.TilePosition in project BWJSAL by RobinsonMann.
the class ReservedMapTest method getReservedType_tilePosition_tileReserved.
@Test
public void getReservedType_tilePosition_tileReserved() {
final TilePosition tilePosition = new TilePosition(2, 2);
this.target.reserveTiles(tilePosition, UnitType.Terran_Command_Center);
assertThat(this.target.getReservedType(tilePosition)).isEqualTo(UnitType.Terran_Command_Center);
}
use of bwapi.TilePosition in project BWJSAL by RobinsonMann.
the class BfsBuildingPlacer method getBuildLocationNear.
private TilePosition getBuildLocationNear(ReservedMap reservedMap, UnitType type, TilePosition position, Unit builder, int buildDist) {
// returns a valid build location near the specified tile position.
if (type.isAddon()) {
type = type.whatBuilds().first;
}
PriorityQueue<Pair<TilePosition, Integer>> searchHeap = new PriorityQueue<>((o1, o2) -> o1.second.compareTo(o2.second));
searchHeap.add(new Pair<>(position, 0));
Set<TilePosition> closed = new HashSet<>();
// Do a breadth first search to find a nearby valid build location with space
while (searchHeap.isEmpty() == false) {
TilePosition t = searchHeap.peek().first;
int s = searchHeap.peek().second;
searchHeap.poll();
if (canBuildHereWithSpace(reservedMap, type, t, builder, buildDist)) {
// We can build here with space so return this tile position
return t;
}
int tx = t.getX();
int ty = t.getY();
int minx = Math.max(tx - 1, 0);
int maxx = Math.min(tx + 1, game.mapWidth() - 1);
int miny = Math.max(ty - 1, 0);
int maxy = Math.min(ty + 1, game.mapHeight() - 1);
for (int x = minx; x <= maxx; x++) {
for (int y = miny; y <= maxy; y++) {
if (walkable[x][y]) {
TilePosition t2 = new TilePosition(x, y);
if (!closed.contains(t2)) {
int ds = 10;
if (x != tx && y != ty) {
// diagonal distance, approximation of 10*sqrt( 2 )
ds = 14;
}
closed.add(t2);
searchHeap.add(new Pair(t2, s + ds));
}
}
}
}
}
// We didn't find a build position, try looking for one with less space
if (buildDist > 0) {
return getBuildLocationNear(reservedMap, type, position, builder, buildDist - 1);
}
return TilePosition.None;
}
Aggregations