use of bwapi.Unit in project Ecgberht by Jabbo16.
the class ChooseMarineRange method execute.
@Override
public State execute() {
try {
if (((GameState) this.handler).UBs.isEmpty()) {
return State.FAILURE;
}
for (Unit u : ((GameState) this.handler).UBs) {
if (((GameState) this.handler).getPlayer().hasResearched(TechType.Stim_Packs) && ((GameState) this.handler).getPlayer().getUpgradeLevel(UpgradeType.U_238_Shells) != 1 && u.canUpgrade(UpgradeType.U_238_Shells) && !u.isResearching() && !u.isUpgrading()) {
((GameState) this.handler).chosenUnitUpgrader = u;
((GameState) this.handler).chosenUpgrade = UpgradeType.U_238_Shells;
return State.SUCCESS;
}
}
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
System.err.println(e);
return State.ERROR;
}
}
use of bwapi.Unit in project Ecgberht by Jabbo16.
the class ChooseWeaponInfUp method execute.
@Override
public State execute() {
try {
if (((GameState) this.handler).UBs.isEmpty()) {
return State.FAILURE;
}
for (Unit u : ((GameState) this.handler).UBs) {
if (u.canUpgrade(UpgradeType.Terran_Infantry_Weapons) && !u.isResearching() && !u.isUpgrading()) {
((GameState) this.handler).chosenUnitUpgrader = u;
((GameState) this.handler).chosenUpgrade = UpgradeType.Terran_Infantry_Weapons;
return State.SUCCESS;
}
}
return State.FAILURE;
} catch (Exception e) {
System.err.println(this.getClass().getSimpleName());
System.err.println(e);
return State.ERROR;
}
}
use of bwapi.Unit 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);
}
use of bwapi.Unit in project BWJSAL by RobinsonMann.
the class UnitTrackerTest method assertThatDataExtractedFromUnit.
/**
* Verifies that targetToInvoke returns Unit.methodToMock.
*
* This is used to verify that unit getters are called when the unit exists.
*/
private <T> void assertThatDataExtractedFromUnit(Class<T> responseClass, Function<Unit, T> methodToMock, Function<Unit, T> targetToInvoke) {
final Unit unit = createMockUnit(true);
final T mockResponse = Mockito.mock(responseClass);
when(methodToMock.apply(unit)).thenReturn(mockResponse);
assertThat(targetToInvoke.apply(unit)).isEqualTo(mockResponse);
}
use of bwapi.Unit in project BWJSAL by RobinsonMann.
the class UnitTrackerTest method assertThatTrackedInformationReturned.
/**
* Verify that UnitTracker returns the last information saved available when the unit existed.
*
* @param invocationTargetReturnType The class that is being tracked
* @param unitGetterMethodThatIsTracked What method is called to get the tracked data from the unit
* @param targetMethodToInvoke What method is called from the target to get the tracked data
* @param <T> The class that is being tracked
*/
public <T> void assertThatTrackedInformationReturned(Class<T> invocationTargetReturnType, Function<Unit, T> unitGetterMethodThatIsTracked, Function<Unit, T> targetMethodToInvoke) {
final Unit unit = createMockUnit(true);
// First value returned by getter. This should tracked, and will be updated in frame 2
final T getterValueAtDiscovery = Mockito.mock(invocationTargetReturnType);
when(unitGetterMethodThatIsTracked.apply(unit)).thenReturn(getterValueAtDiscovery);
this.target.onUnitDiscover(unit, 0);
this.target.onFrame(0);
// Last value of getter that will be tracked
final T lastGetterValueWhileUnitExisted = Mockito.mock(invocationTargetReturnType);
when(unitGetterMethodThatIsTracked.apply(unit)).thenReturn(lastGetterValueWhileUnitExisted);
this.target.onFrame(1);
// Unit no longer exists
when(unit.exists()).thenReturn(false);
// Update getter to a new value. This value should NOT be returned.
final Position getterValueButUnitDoesntExist = Mockito.mock(Position.class);
when(unit.getPosition()).thenReturn(getterValueButUnitDoesntExist);
this.target.onFrame(2);
// Verify that the value tracked in frame 1 is returned.
assertThat(targetMethodToInvoke.apply(unit)).isEqualTo(lastGetterValueWhileUnitExisted).isNotEqualTo(getterValueAtDiscovery).isNotEqualTo(getterValueButUnitDoesntExist);
}
Aggregations