protected double calculateSelfPreservationMod(Entity movingUnit, MovePath path, IGame game, StringBuilder formula) { if (getOwner().getFallBack() || movingUnit.isCrippled()) { int newDistanceToHome = distanceToHomeEdge(path.getFinalCoords(), getOwner().getHomeEdge(movingUnit), game); double selfPreservation = getOwner().getBehaviorSettings() .getSelfPreservationValue(); double selfPreservationMod = newDistanceToHome * selfPreservation; formula.append(" - selfPreservationMod [") .append(LOG_DECIMAL.format(selfPreservationMod)) .append(" = ").append(LOG_DECIMAL.format(newDistanceToHome)) .append(" * ") .append(LOG_DECIMAL.format(selfPreservation)).append("]"); return selfPreservationMod; } return 0.0; }
@Before public void setUp() { final BehaviorSettings mockBehavior = Mockito.mock(BehaviorSettings.class); Mockito.when(mockBehavior.getFallShameValue()).thenReturn(BehaviorSettings.FALL_SHAME_VALUES[5]); Mockito.when(mockBehavior.getBraveryValue()).thenReturn(BehaviorSettings.BRAVERY[5]); Mockito.when(mockBehavior.getHyperAggressionValue()).thenReturn(BehaviorSettings.HYPER_AGGRESSION_VALUES[5]); Mockito.when(mockBehavior.getHerdMentalityValue()).thenReturn(BehaviorSettings.HERD_MENTALITY_VALUES[5]); Mockito.when(mockBehavior.getSelfPreservationValue()).thenReturn(BehaviorSettings.SELF_PRESERVATION_VALUES[5]); mockFireControl = Mockito.mock(FireControl.class); final IHonorUtil mockHonorUtil = Mockito.mock(IHonorUtil.class); Mockito.when(mockHonorUtil.isEnemyBroken(Mockito.anyInt(), Mockito.anyInt(), Mockito.anyBoolean())) .thenReturn(false); final List<Targetable> testAdditionalTargets = new ArrayList<>(); mockFireControlState = Mockito.mock(FireControlState.class); Mockito.when(mockFireControlState.getAdditionalTargets()).thenReturn(testAdditionalTargets); final Map<MovePath.Key, Double> testSuccessProbabilities = new HashMap<>(); mockPathRankerState = Mockito.mock(PathRankerState.class); Mockito.when(mockPathRankerState.getPathSuccessProbabilities()).thenReturn(testSuccessProbabilities); mockPrincess = Mockito.mock(Princess.class); Mockito.when(mockPrincess.getBehaviorSettings()).thenReturn(mockBehavior); Mockito.when(mockPrincess.getFireControl(FireControlType.Basic)).thenReturn(mockFireControl); Mockito.when(mockPrincess.getHomeEdge(Mockito.any(Entity.class))).thenReturn(CardinalEdge.NORTH); Mockito.when(mockPrincess.getHonorUtil()).thenReturn(mockHonorUtil); Mockito.when(mockPrincess.getLogger()).thenReturn(fakeLogger); Mockito.when(mockPrincess.getFireControlState()).thenReturn(mockFireControlState); Mockito.when(mockPrincess.getPathRankerState()).thenReturn(mockPathRankerState); }
CardinalEdge homeEdge = getOwner().getHomeEdge(mover); boolean fleeing = getOwner().isFallingBack(mover);
Mockito.when(mockPrincess.getHomeEdge(Mockito.any(Entity.class))).thenReturn(CardinalEdge.NORTH); IGame mockGame = Mockito.mock(IGame.class); Mockito.when(mockPrincess.getGame()).thenReturn(mockGame);
boolean mustFleeBoard(final Entity entity) { if (!isFallingBack(entity)) { return false; } if (!entity.canFlee()) { return false; } if (0 < getPathRanker(entity).distanceToHomeEdge(entity.getPosition(), getHomeEdge(entity), getGame())) { return false; } //noinspection RedundantIfStatement if (!getFleeBoard() && !(entity.isCrippled() && getForcedWithdrawal())) { return false; } return true; }
/** * Tells me whether this path will result in me flying to a location * from which there is absolutely no way to remain on the board the following turn. * * We also take into account the possibility that we are intentionally trying to * a) retreat * b) fly off a particular edge * @param path The path to examine * @return 0 if we are A-Ok with it, .5 (maybe tune this) if we aren't looking to go off board */ @Override protected double calculateOffBoardMod(MovePath path) { // step one: project given path's vector over the next turn. OffBoardDirection offBoardDirection = calculateOffBoardDirection(path.getEntity(), path.getFinalCoords(), path.getFinalVectors()); // if we want to flee the board from the edge in question, we're ok if(getOwner().isFallingBack(path.getEntity()) && (getOwner().getHomeEdge(path.getEntity()) == CardinalEdge.getCardinalEdge(offBoardDirection.getValue()))) { return 0.0; } if(offBoardDirection == OffBoardDirection.NONE) { return 0.0; } return .5; }
/** * Gives the "utility" of a path; a number representing how good it is. * Rankers that extend this class should override this function */ RankedPath rankPath(MovePath path, IGame game) { double fallTolerance = getOwner().getBehaviorSettings().getFallShameIndex() / 10d; Entity me = path.getEntity(); int homeDistance = distanceToHomeEdge(me.getPosition(), getOwner().getHomeEdge(me), game); int maxWeaponRange = me.getMaxWeaponRange(); List<Entity> enemies = getOwner().getEnemyEntities(); List<Entity> friends = getOwner().getFriendEntities(); Coords allyCenter = calcAllyCenter(me.getId(), friends, game); return rankPath(path, game, maxWeaponRange, fallTolerance, homeDistance, enemies, allyCenter); }