use of bwapi.Position in project Ecgberht by Jabbo16.
the class CameraModule method moveCameraArmy.
@Override
public void moveCameraArmy() {
int prio = 1;
if (!shouldMoveCamera(prio)) {
return;
}
// Double loop, check if army units are close to each other
int radius = 50;
Unit bestPosUnit = null;
int mostUnitsNearby = 0;
for (Unit unit1 : game.getAllUnits()) {
if (!isArmyUnit(unit1)) {
continue;
}
Position uPos = unit1.getPosition();
int nrUnitsNearby = 0;
for (Unit unit2 : game.getUnitsInRadius(uPos, radius)) {
if (!isArmyUnit(unit2)) {
continue;
}
nrUnitsNearby++;
}
if (nrUnitsNearby > mostUnitsNearby) {
mostUnitsNearby = nrUnitsNearby;
bestPosUnit = unit1;
}
}
if (mostUnitsNearby > 1) {
moveCamera(bestPosUnit, prio);
}
}
use of bwapi.Position in project BWJSAL by RobinsonMann.
the class DrawUtils method highlightIslandBaseLocation.
public void highlightIslandBaseLocation(final BaseLocation baseLocation, final Color islandHighlightColor) {
final Position basePosition = baseLocation.getPosition();
game.drawCircle(Enum.Map, basePosition.getX(), basePosition.getY(), 80, islandHighlightColor, false);
}
use of bwapi.Position 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