Search in sources :

Example 11 with BaseLocation

use of bwta.BaseLocation 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 12 with BaseLocation

use of bwta.BaseLocation in project BWJSAL by RobinsonMann.

the class EnemyBaseTracker method possibleEnemyStartingLocation.

/**
 * Will return a base location belonging to the enemy if the given building
 * is inside of a region that also contains a starting location that could contain
 * an enemy base.
 */
private Optional<BaseLocation> possibleEnemyStartingLocation(final Unit building) {
    // Find the region that this building belongs to.
    final Region unitRegion = this.bwta.getRegion(building.getTilePosition());
    final List<BaseLocation> baseLocationsInsideRegion = unitRegion.getBaseLocations();
    // starting locations that could contain the enemy. If so, return.
    for (final BaseLocation baseLocationInsideRegion : baseLocationsInsideRegion) {
        if (this.startLocationsThatCouldContainEnemy.contains(baseLocationInsideRegion)) {
            return Optional.of(baseLocationInsideRegion);
        }
    }
    return Optional.empty();
}
Also used : Region(bwta.Region) BaseLocation(bwta.BaseLocation)

Example 13 with BaseLocation

use of bwta.BaseLocation in project BWJSAL by RobinsonMann.

the class EnemyBaseTracker method onUnitDiscover.

@Override
public void onUnitDiscover(final Unit unitDiscovered) {
    if (this.game.self().isEnemy(unitDiscovered.getPlayer()) == false) {
        return;
    }
    // of the enemy.
    if (scoutedAnEnemyBase() == false && unitDiscovered.getType().isBuilding()) {
        final Optional<BaseLocation> enemyBaseLocation = possibleEnemyStartingLocation(unitDiscovered);
        if (enemyBaseLocation.isPresent()) {
            // So the enemy probably spawned here.
            markBaseLocationAsEnemyBase(enemyBaseLocation.get());
        }
    }
    if (unitDiscovered.getType().isResourceDepot()) {
        final BaseLocation nearestBaseLocation = this.bwta.getNearestBaseLocation(unitDiscovered.getTilePosition());
        markBaseLocationAsEnemyBase(nearestBaseLocation, unitDiscovered);
    }
}
Also used : BaseLocation(bwta.BaseLocation)

Aggregations

BaseLocation (bwta.BaseLocation)13 Unit (bwapi.Unit)7 TilePosition (bwapi.TilePosition)4 GameState (ecgberht.GameState)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 RaceUtils.createMockRace (BWJSAL.utils.RaceUtils.createMockRace)2 UnitTypeUtils.mockResourceDepotUnitType (BWJSAL.utils.UnitTypeUtils.mockResourceDepotUnitType)2 Race (bwapi.Race)2 UnitType (bwapi.UnitType)2 Position (bwapi.Position)1 Chokepoint (bwta.Chokepoint)1 Region (bwta.Region)1 EnemyBuilding (ecgberht.EnemyBuilding)1 Random (java.util.Random)1