Search in sources :

Example 1 with Race

use of bwapi.Race 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 2 with Race

use of bwapi.Race in project BWJSAL by RobinsonMann.

the class BuildTimeTrackerTest method enemyHasBuilt_enemyZerg_additionalStartingUnitTypes.

@Test
public void enemyHasBuilt_enemyZerg_additionalStartingUnitTypes() throws Exception {
    final Race mockZerg = createMockRace(UnitType.Zerg_Hatchery, UnitType.Zerg_Drone);
    setStaticFinalField(Race.class, "Zerg", mockZerg);
    when(this.mockGame.self().isEnemy(this.mockEnemy)).thenReturn(true);
    when(this.mockEnemy.getRace()).thenReturn(Race.Zerg);
    this.target.onStart();
    assertEnemyHasBuilt(UnitType.Zerg_Overlord, "Zerg starts with overlord");
    assertEnemyHasBuilt(UnitType.Zerg_Larva, "Zerg starts with larva");
}
Also used : RaceUtils.createMockRace(BWJSAL.utils.RaceUtils.createMockRace) Race(bwapi.Race) Test(org.junit.Test)

Example 3 with Race

use of bwapi.Race in project BWJSAL by RobinsonMann.

the class BuildTimeTrackerTest method enemyHasBuilt_mockEnemyRace_hasBuiltForCenterAndWorkersTrue.

@Test
public void enemyHasBuilt_mockEnemyRace_hasBuiltForCenterAndWorkersTrue() throws Exception {
    final UnitType mockCenter = Mockito.mock(UnitType.class);
    final UnitType mockWorker = Mockito.mock(UnitType.class);
    final Race mockRace = createMockRace(mockCenter, mockWorker);
    when(this.mockEnemy.getRace()).thenReturn(mockRace);
    this.target.onStart();
    assertEnemyHasBuilt(mockCenter, "Race's Center UnitType always built");
    assertEnemyHasBuilt(mockWorker, "Race's Worker UnitType always built");
}
Also used : UnitType(bwapi.UnitType) RaceUtils.createMockRace(BWJSAL.utils.RaceUtils.createMockRace) Race(bwapi.Race) Test(org.junit.Test)

Example 4 with Race

use of bwapi.Race in project BWJSAL by RobinsonMann.

the class InformationManagerAcceptanceTest method multipleResourceDepotsAtBaseOneDestroyed_baseLocationStillEnemies.

/**
 * Verify that enemy base locations are not removed if multiple resource depots are observed at the same location.
 */
@Test
public void multipleResourceDepotsAtBaseOneDestroyed_baseLocationStillEnemies() {
    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();
    // observe multiple resource depots in enemy base location
    final TilePosition firstResourceDepotPosition = mock(TilePosition.class);
    setNearestBaseLocationOnMock(this.bwtaWrapper, firstResourceDepotPosition, enemyStartingLocation);
    final Unit firstResourceDepot = UnitBuilder.mockUnit(this.enemy, mockResourceDepotUnitType(), firstResourceDepotPosition);
    this.target.onUnitDiscover(firstResourceDepot);
    final TilePosition secondResourceDepotPosition = mock(TilePosition.class);
    setNearestBaseLocationOnMock(this.bwtaWrapper, secondResourceDepotPosition, enemyStartingLocation);
    final Unit secondResourceDepot = UnitBuilder.mockUnit(this.enemy, mockResourceDepotUnitType(), firstResourceDepotPosition);
    this.target.onUnitDiscover(secondResourceDepot);
    // first resource depot destroyed
    this.target.onUnitDestroy(firstResourceDepot);
    // verify location is still enemy
    assertThat(this.target.getEnemyBases()).as("selfStartingLocation still enemy base").containsExactly(enemyStartingLocation);
}
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 5 with Race

use of bwapi.Race in project BWJSAL by RobinsonMann.

the class RaceUtils method createMockRace.

/**
 * Creates a mock Race instance.
 */
public static Race createMockRace(final UnitType raceCenter, final UnitType raceWorker) {
    final Race mockRace = Mockito.mock(Race.class);
    when(mockRace.getCenter()).thenReturn(raceCenter);
    when(mockRace.getWorker()).thenReturn(raceWorker);
    return mockRace;
}
Also used : Race(bwapi.Race)

Aggregations

Race (bwapi.Race)7 RaceUtils.createMockRace (BWJSAL.utils.RaceUtils.createMockRace)5 Test (org.junit.Test)5 UnitType (bwapi.UnitType)3 UnitTypeUtils.mockResourceDepotUnitType (BWJSAL.utils.UnitTypeUtils.mockResourceDepotUnitType)2 TilePosition (bwapi.TilePosition)2 Unit (bwapi.Unit)2 BaseLocation (bwta.BaseLocation)2