Search in sources :

Example 6 with TilePosition

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);
}
Also used : UnitType(bwapi.UnitType) TilePosition(bwapi.TilePosition) Unit(bwapi.Unit) Test(org.junit.Test)

Example 7 with TilePosition

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();
}
Also used : UnitType(bwapi.UnitType) TilePosition(bwapi.TilePosition) Unit(bwapi.Unit) Test(org.junit.Test)

Example 8 with TilePosition

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);
}
Also used : TilePosition(bwapi.TilePosition) Test(org.junit.Test)

Example 9 with TilePosition

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);
}
Also used : TilePosition(bwapi.TilePosition) Test(org.junit.Test)

Example 10 with TilePosition

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;
}
Also used : TilePosition(bwapi.TilePosition) PriorityQueue(java.util.PriorityQueue) Pair(bwapi.Pair) HashSet(java.util.HashSet)

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