public Set<Integer> getPriorityUnitTargets() { return getBehaviorSettings().getPriorityUnitTargets(); }
public void setVerbosity(final LogLevel level) { getBehaviorSettings().setVerbosity(level); }
boolean getForcedWithdrawal() { return getBehaviorSettings().isForcedWithdrawal(); }
private double calculateFallMod(double successProbability, StringBuilder formula) { double pilotingFailure = (1 - successProbability); double fallShame = getOwner().getBehaviorSettings().getFallShameValue(); double fallMod = pilotingFailure * (pilotingFailure == 1 ? -1000 : fallShame); formula.append("fall mod [").append(LOG_DECIMAL.format(fallMod)).append(" = ") .append(LOG_DECIMAL.format(pilotingFailure)).append(" * ").append(LOG_DECIMAL.format(fallShame)) .append("]"); return fallMod; }
public LogLevel getVerbosity() { return getBehaviorSettings().getVerbosity(); }
/** * Logic to determine if this entity is "falling back" for any reason * @param entity The entity to check. * @return Whether or not the entity is falling back. */ boolean isFallingBack(final Entity entity) { return (getBehaviorSettings().getDestinationEdge() != CardinalEdge.NEAREST_OR_NONE) || (getBehaviorSettings().isForcedWithdrawal() && entity.isCrippled(true)); }
CardinalEdge getHomeEdge(Entity entity) { // if I am crippled and using forced withdrawal rules, my home edge is the "retreat" edge if(entity.isCrippled(true) && getBehaviorSettings().isForcedWithdrawal()) { if(getBehaviorSettings().getRetreatEdge() == CardinalEdge.NEAREST_OR_NONE) { return BoardUtilities.getClosestEdge(entity); } else { return getBehaviorSettings().getRetreatEdge(); } } // otherwise, return the destination edge return getBehaviorSettings().getDestinationEdge(); }
protected double calculateAggressionMod(Entity movingUnit, MovePath path, IGame game, StringBuilder formula) { double distToEnemy = distanceToClosestEnemy(movingUnit, path.getFinalCoords(), game); if ((distToEnemy == 0) && !(movingUnit instanceof Infantry)) { distToEnemy = 2; } double aggression = getOwner().getBehaviorSettings() .getHyperAggressionValue(); double aggressionMod = distToEnemy * aggression; formula.append(" - aggressionMod [") .append(LOG_DECIMAL.format(aggressionMod)).append(" = ") .append(LOG_DECIMAL.format(distToEnemy)).append(" * ") .append(LOG_DECIMAL.format(aggression)).append("]"); return aggressionMod; }
protected double calculateHerdingMod(Coords friendsCoords, MovePath path, StringBuilder formula) { if (friendsCoords == null) { formula.append(" - herdingMod [0 no friends]"); return 0; } double distanceToAllies = friendsCoords.distance(path.getFinalCoords()); double herding = getOwner().getBehaviorSettings() .getHerdMentalityValue(); double herdingMod = distanceToAllies * herding; formula.append(" - herdingMod [").append(LOG_DECIMAL.format(herdingMod)) .append(" = ") .append(LOG_DECIMAL.format(distanceToAllies)).append(" * ") .append(LOG_DECIMAL.format(herding)) .append("]"); return herdingMod; }
/** * Calculates the logarithmic scaling factor for target damage potential in * the utility equation, using the target's potential damage, the weight * value TARGET_POTENTIAL_DAMAGE_UTILITY, and Princess's self-preservation * value. This is mostly here to not clutter up the utility calculation * method with all this extra math. */ private double calcTargetPotentialDamageMultiplier(final Targetable target) { final double target_damage = calcTargetPotentialDamage(target); if (0.0 == target_damage) { // Do not calculate for zero damage units. return 1.0; } final double self_preservation = owner.getBehaviorSettings().getSelfPreservationValue(); final double max_self_preservation = owner.getBehaviorSettings() .getSelfPreservationValue(10); // the preservation value of the highest index, i.e. the max value. final double preservation_scaling_factor = max_self_preservation / self_preservation; // Because the variance in log value for large numbers is smaller, we need to make a big self-preservation value become a small multiplicative factor, and vice versa. return Math.log10(TARGET_POTENTIAL_DAMAGE_UTILITY * preservation_scaling_factor * target_damage + 10); // Add 10 to make the multiplier scale from 1 upwards(1 being a target that does 0 damage)). }
private double calcStrategicBuildingTargetUtility(final Targetable target) { if (!(target instanceof BuildingTarget)) { return 0; } final DecimalFormat coordsFormat = new DecimalFormat("00"); final Coords targetCoords = target.getPosition(); final String coords = coordsFormat.format(targetCoords.getX() + 1) + coordsFormat.format(targetCoords.getY() + 1); if (owner.getBehaviorSettings().getStrategicBuildingTargets().contains(coords)) { return STRATEGIC_TARGET_UTILITY; } return 0; }
public BasicPathRanker(Princess owningPrincess) { super(owningPrincess); final String METHOD_NAME = "BasicPathRanker(Princess)"; bestDamageByEnemies = new TreeMap<>(); getOwner().log( getClass(), METHOD_NAME, LogLevel.DEBUG, "Using " + getOwner().getBehaviorSettings().getDescription() + " behavior"); }
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; }
/** * gets the selected, configured bot from the dialog * * @param host The game server's host address. * @param port The gme server's host port. * @return A new bot-controlled client. */ BotClient getSelectedBot(String host, int port) { if (testBotRadiobutton.isSelected()) { return new TestBot(getBotName(), host, port); } else if (princessRadiobutton.isSelected()) { Princess toReturn = new Princess(getBotName(), host, port, LogLevel.getLogLevel((String) verbosityCombo.getSelectedItem())); toReturn.setBehaviorSettings(princessBehavior); toReturn.log(getClass(), "getSelectedBot(String, int)", LogLevel.DEBUG, toReturn.getBehaviorSettings().toLog()); return toReturn; } return null; // shouldn't happen }
@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); }
@Test public void testIsFallingBack() { Entity mockMech = Mockito.mock(BipedMech.class); Mockito.when(mockMech.isImmobile()).thenReturn(false); Mockito.when(mockMech.isCrippled(Mockito.anyBoolean())).thenReturn(false); Mockito.when(mockMech.getId()).thenReturn(1); Mockito.when(mockPrincess.wantsToFallBack(Mockito.any(Entity.class))).thenReturn(false); Mockito.when(mockPrincess.isFallingBack(Mockito.any(Entity.class))).thenCallRealMethod(); BehaviorSettings mockBehavior = Mockito.mock(BehaviorSettings.class); Mockito.when(mockBehavior.getDestinationEdge()).thenReturn(CardinalEdge.NEAREST_OR_NONE); Mockito.when(mockBehavior.isForcedWithdrawal()).thenReturn(true); Mockito.when(mockPrincess.getBehaviorSettings()).thenReturn(mockBehavior); // A normal undamaged mech. Assert.assertFalse(mockPrincess.isFallingBack(mockMech)); // A mobile mech that wants to fall back (for any reason). Mockito.when(mockMech.isCrippled(Mockito.anyBoolean())).thenReturn(true); Assert.assertTrue(mockPrincess.isFallingBack(mockMech)); }
"/replacePlayer", "-b:Princess", "-c:" + ((Princess) botClient).getBehaviorSettings().getDescription(), "-v:" + ((Princess) botClient).getVerbosity(), "-p:" + player
Mockito.doReturn(new HashSet<Coords>()).when(mockPrincess).getStrategicBuildingTargets(); Mockito.doReturn(new HashSet<Integer>()).when(mockPrincess).getPriorityUnitTargets(); Mockito.doCallRealMethod().when(mockPrincess).getBehaviorSettings(); Mockito.doCallRealMethod().when(mockPrincess).getVerbosity();
/** * 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); }
boolean enemyUnitBroken = owner.getHonorUtil().isEnemyBroken(entity.getId(), shooter.getOwnerId(), owner.getBehaviorSettings().isForcedWithdrawal());