|
| 1 | +package bwapi; |
| 2 | + |
| 3 | +import org.junit.Test; |
| 4 | + |
| 5 | +import java.util.Collections; |
| 6 | + |
| 7 | +import static org.junit.Assert.assertEquals; |
| 8 | +import static org.mockito.Mockito.mock; |
| 9 | +import static org.mockito.Mockito.when; |
| 10 | + |
| 11 | +public class BuildingPlacerTest { |
| 12 | + |
| 13 | + @Test |
| 14 | + public void reserveExistingAddonPlacementShouldUseHalfMaxRangeOffset() { |
| 15 | + Game game = mock(Game.class); |
| 16 | + Player self = mock(Player.class); |
| 17 | + when(game.self()).thenReturn(self); |
| 18 | + |
| 19 | + TilePosition desired = new TilePosition(40, 40); |
| 20 | + // start should be desired - (64, 64)/2 = (8, 8). |
| 21 | + // Factory at (40, 40) has its 2x2 addon at world tiles (44, 41)..(45, 42), |
| 22 | + // which corresponds to reserve coordinates (36, 33)..(37, 34). |
| 23 | + Unit factory = mock(Unit.class); |
| 24 | + when(factory.exists()).thenReturn(true); |
| 25 | + when(factory.getType()).thenReturn(UnitType.Terran_Factory); |
| 26 | + when(factory.getTilePosition()).thenReturn(new TilePosition(40, 40)); |
| 27 | + when(self.getUnits()).thenReturn(Collections.singletonList(factory)); |
| 28 | + |
| 29 | + BuildingPlacer.PlacementReserve reserve = new BuildingPlacer.PlacementReserve(64); |
| 30 | + reserve.setRange(0, 0, 64, 64, (byte) 1); |
| 31 | + |
| 32 | + BuildingPlacer.ReserveExistingAddonPlacement(reserve, desired, game); |
| 33 | + |
| 34 | + assertEquals(0, reserve.getValue(36, 33)); |
| 35 | + assertEquals(0, reserve.getValue(37, 34)); |
| 36 | + } |
| 37 | + |
| 38 | + @Test |
| 39 | + public void reserveDefaultShouldUsePaddingTwoForFactory() { |
| 40 | + Game game = mock(Game.class); |
| 41 | + Player self = mock(Player.class); |
| 42 | + when(game.self()).thenReturn(self); |
| 43 | + |
| 44 | + TilePosition desired = new TilePosition(40, 40); |
| 45 | + Unit factory = mock(Unit.class); |
| 46 | + when(factory.exists()).thenReturn(true); |
| 47 | + when(factory.getType()).thenReturn(UnitType.Terran_Factory); |
| 48 | + when(factory.getTilePosition()).thenReturn(new TilePosition(40, 40)); |
| 49 | + when(factory.getPosition()).thenReturn(new TilePosition(40, 40).toPosition()); |
| 50 | + when(self.getUnits()).thenReturn(Collections.singletonList(factory)); |
| 51 | + |
| 52 | + BuildingPlacer.PlacementReserve reserve = new BuildingPlacer.PlacementReserve(64); |
| 53 | + reserve.setRange(0, 0, 64, 64, (byte) 1); |
| 54 | + |
| 55 | + BuildingPlacer.ReserveDefault(reserve, UnitType.Terran_Supply_Depot, desired, game); |
| 56 | + |
| 57 | + // For a 4x3 Factory at (40, 40) (reserve 32, 32) and a 3x2 Supply Depot: |
| 58 | + // padding=1 reserves x in [25, 35), y in [27, 35) |
| 59 | + // padding=2 reserves x in [24, 36), y in [26, 36) |
| 60 | + assertEquals(0, reserve.getValue(24, 26)); |
| 61 | + assertEquals(0, reserve.getValue(35, 35)); |
| 62 | + } |
| 63 | +} |
0 commit comments