/** * 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 }
@Override protected MovePath continueMovementFor(final Entity entity) { final String METHOD_NAME = "continueMovementFor(Entity)"; methodBegin(getClass(), METHOD_NAME); log(getClass(), METHOD_NAME, "Moving " + entity.getDisplayName() + " (ID " + entity.getId() + ")"); getPrecognition().ensureUpToDate(); if (isFallingBack(entity)) { String msg = entity.getDisplayName(); if (getFallBack()) { msg += " is falling back."; } else if (entity.isCrippled()) { msg += " is crippled and withdrawing."; log(getClass(), METHOD_NAME, msg); sendChat(msg, LogLevel.WARNING); if (mustFleeBoard(entity)) { final MovePath mp = new MovePath(game, entity); mp.addStep(MovePath.MoveStepType.FLEE); if (isImmobilized(entity) && entity.isEjectionPossible()) { msg = entity.getDisplayName() + " is immobile. Abandoning unit."; log(getClass(), METHOD_NAME, LogLevel.INFO, msg); sendChat(msg, LogLevel.WARNING); final MovePath mp = new MovePath(game, entity);
/** * Load the list of units considered crippled at the time the bot was loaded or the beginning of the turn, * whichever is the more recent. */ public void refreshCrippledUnits() { // if we're not following 'forced withdrawal' rules, there's no need for this if(!getForcedWithdrawal()) { return; } // this approach is a little bit inefficient, but the running time is only O(n) where n is the number // of princess owned units, so it shouldn't be a big deal. crippledUnits.clear(); for(Entity e : this.getEntitiesOwned()) { if(e.isCrippled(true)) { crippledUnits.add(e.getId()); } } }
@Override protected MovePath calculateMoveTurn() { final String METHOD_NAME = "calculateMoveTurn()"; methodBegin(getClass(), METHOD_NAME); try { return continueMovementFor(getEntityToMove()); } finally { methodEnd(getClass(), METHOD_NAME); } }
private void checkForBrokenEnemies() { // If the Forced Withdrawal rule is not turned on, then it's a fight // to the death anyway. if (!getForcedWithdrawal()) { return; } for (final Entity entity : getEnemyEntities()) { getHonorUtil().checkEnemyBroken(entity, getForcedWithdrawal()); } }
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"); }
Mockito.when(mockChatEvent.getMessage()).thenReturn(chatMessage); Mockito.when(mockChatEvent.getPlayer()).thenReturn(mockHumanPlayerDave); Princess mockPrincess = Mockito.spy(new Princess(mockBotPlayerVGer.getName(), "test", 1, LOG_LEVEL)); Mockito.doReturn(MOCK_GAME).when(mockPrincess).getGame(); Mockito.doNothing().when(mockPrincess).log(Matchers.any(Class.class), Matchers.anyString(), Matchers.any(LogLevel.class), Matchers.anyString()); Mockito.doReturn(mockBotPlayerVGer).when(mockPrincess).getLocalPlayer(); Mockito.doNothing().when(mockPrincess).sendChat(Matchers.anyString()); testChatProcessor.additionalPrincessCommands(mockChatEvent, mockPrincess); Assert.assertTrue(mockPrincess.getFallBack()); Mockito.when(mockChatEvent.getMessage()).thenReturn(chatMessage); Mockito.when(mockChatEvent.getPlayer()).thenReturn(mockHumanPlayerKirk); mockPrincess = Mockito.spy(new Princess(mockBotPlayerVGer.getName(), "test", 1, LOG_LEVEL)); Mockito.doReturn(MOCK_GAME).when(mockPrincess).getGame(); Mockito.doNothing().when(mockPrincess).log(Matchers.any(Class.class), Matchers.anyString(), Matchers.any(LogLevel.class), Matchers.anyString()); Mockito.doReturn(mockBotPlayerVGer).when(mockPrincess).getLocalPlayer(); Mockito.doNothing().when(mockPrincess).sendChat(Matchers.anyString()); testChatProcessor.additionalPrincessCommands(mockChatEvent, mockPrincess); Assert.assertFalse(mockPrincess.getFallBack()); Mockito.when(mockChatEvent.getMessage()).thenReturn(chatMessage); Mockito.when(mockChatEvent.getPlayer()).thenReturn(mockHumanPlayerDave); mockPrincess = Mockito.spy(new Princess(mockBotPlayerVGer.getName(), "test", 1, LOG_LEVEL)); Mockito.doReturn(MOCK_GAME).when(mockPrincess).getGame(); Mockito.doNothing().when(mockPrincess).log(Matchers.any(Class.class), Matchers.anyString(), Matchers.any(LogLevel.class), Matchers.anyString()); Mockito.doReturn(mockBotPlayerVGer).when(mockPrincess).getLocalPlayer();
princess.log(getClass(), METHOD_NAME, LogLevel.INFO, msg); IPlayer princessPlayer = princess.getLocalPlayer(); if (princessPlayer == null) { princess.log(getClass(), METHOD_NAME, LogLevel.ERROR, "Princess Player is NULL."); return; princess.sendChat("I do not recognize that command."); speakerPlayer = getPlayer(princess.getGame(), from); if (speakerPlayer == null) { princess.log(getClass(), METHOD_NAME, LogLevel.ERROR, "speakerPlayer is NULL."); return; if (arguments == null || arguments.length == 0) { msg = "No log level specified."; princess.log(getClass(), METHOD_NAME, LogLevel.WARNING, msg + "\n" + chatEvent.getMessage()); princess.sendChat(msg); return; if (newLevel == null) { msg = "Invalid verbosity specified: " + arguments[0]; princess.log(getClass(), METHOD_NAME, LogLevel.WARNING, msg); princess.sendChat(msg); return; princess.setVerbosity(newLevel); msg = "Verbosity set to " + princess.getVerbosity().toString(); princess.log(getClass(), METHOD_NAME, LogLevel.DEBUG, msg);
Mockito.when(mockClient.getPort()).thenReturn(1); mockPrincess = Mockito.spy(new Princess("Princess", "mockHost", 1, LogLevel.ERROR)); Mockito.doCallRealMethod().when(mockPrincess).setBehaviorSettings(Mockito.any(BehaviorSettings.class)); Mockito.doReturn(mockGame).when(mockPrincess).getGame(); Mockito.doReturn(true).when(mockPrincess).connect(); 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();
@Override protected void calculateDeployment() { final String METHOD_NAME = "calculateDeployment()"; methodBegin(getClass(), METHOD_NAME); if (getLogger().getLogLevel(LOGGING_CATEGORY).toInt() > LogLevel.WARNING.toInt()) { sendChat("deploying unit " + getEntity(entityNum).getChassis(), LogLevel.INFO); if(getForcedWithdrawal() && getEntity(entityNum).isCrippled()) { log(getClass(), METHOD_NAME, LogLevel.INFO, "Declining to deploy crippled unit: " + getEntity(entityNum).getChassis() + ". Removing unit."); sendDeleteEntity(entityNum); return; final List<Coords> startingCoords = getStartingCoordsArray(game.getEntity(entityNum)); if (0 == startingCoords.size()) { log(getClass(), METHOD_NAME, LogLevel.ERROR, "No valid locations to deploy " + getEntity(entityNum).getDisplayName()); final Coords deployCoords = getFirstValidCoords(getEntity(entityNum), startingCoords); if (null == deployCoords) { log(getClass(), METHOD_NAME, LogLevel.ERROR, "getCoordsAround gave no location for "
"double, int, int, List<Entity>, Coords)"; getOwner().methodBegin(getClass(), METHOD_NAME); if (getOwner().getHonorUtil().isEnemyBroken(enemy.getId(), enemy.getOwnerId(), getOwner().getForcedWithdrawal())) { continue; calcDamageToStrategicTargets(pathCopy, game, getOwner().getFireControlState(), damageEstimate); double maximumDamageDone = damageEstimate.firingDamage; getOwner().getBehaviorSettings().getBraveryValue(); double braveryMod = (maximumDamageDone * braveryValue) - expectedDamageTaken; formula.append(" + braveryMod [") return rankedPath; } finally { getOwner().methodEnd(getClass(), METHOD_NAME);
@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); }
@Override protected PhysicalOption calculatePhysicalTurn() { final String METHOD_NAME = "calculatePhysicalTurn()"; methodBegin(getClass(), METHOD_NAME); initialize(); final Entity attacker = game.getFirstEntity(getMyTurn()); if (getForcedWithdrawal() && attacker.isCrippled()) { final StringBuilder msg = new StringBuilder(attacker.getDisplayName()) log(getClass(), METHOD_NAME, LogLevel.INFO, msg); final List<Entity> enemies = getEnemyEntities(); nextEntityId = game.getNextEntityNum(getMyTurn(), hitter.getId()); log(getClass(), METHOD_NAME, LogLevel.DEBUG, "Calculating physical attacks for " + hitter.getDisplayName()); if (getHonorUtil().isEnemyBroken(e.getTargetId(), e.getOwnerId(), getForcedWithdrawal())) { continue; getFireControl(hitter).calculateUtility(right_punch); if (0 < right_punch.getUtility()) {
final List<Entity> myEntities = getEntitiesOwned(); double highestIndex = -Double.MAX_VALUE; final StringBuilder msg = new StringBuilder("Deciding who to move next."); || (null == entity.getPosition()) || entity.isUnloadedThisTurn() || !getGame().getTurn().isValidEntity(entity, getGame())) && !getGame().isPhaseSimultaneous()){ msg.append("cannot be moved."); continue; if (isImmobilized(entity) && !(entity instanceof Infantry)) { msg.append("is immobile."); movingEntity = entity; final double moveIndex = calculateMoveIndex(entity, msg); msg.append("\n\thas index ").append(moveIndex).append(" vs ") .append(highestIndex); log(getClass(), "getEntityToMove()", level, msg.toString());
public Entity findClosestEnemy(Entity me, Coords position, IGame game) { final String METHOD_NAME = "findClosestEnemy(Entity, Coords, IGame)"; getOwner().methodBegin(PathRanker.class, METHOD_NAME); List<Entity> enemies = getOwner().getEnemyEntities(); for (Entity e : enemies) { if (getOwner().getHonorUtil().isEnemyBroken(e.getTargetId(), e.getOwnerId(), getOwner().getForcedWithdrawal())) { continue; getOwner().methodEnd(PathRanker.class, METHOD_NAME);
if (!getForcedWithdrawal()) { msg.append("\n\tForced withdrawal turned off."); return; for (final Entity mine : getEntitiesOwned()) { final Entity entity = getGame().getEntity(id); if (null == entity) { continue; if (getHonorUtil().isEnemyBroken(entity.getTargetId(), entity.getOwnerId(), getForcedWithdrawal()) || !entity.isMilitary()) { msg.append("fleeing."); getHonorUtil().setEnemyDishonored(entity.getOwnerId()); continue; .append(mine.getDisplayName()) .append(")."); getHonorUtil().setEnemyDishonored(entity.getOwnerId()); attackedWhileFleeing.add(mine.getId()); log(getClass(), METHOD_NAME, LogLevel.INFO, msg);
boolean isImmobilized(final Entity mover) { final String METHOD_NAME = "isImmobilized(Entity, MovePath)"; if (mover.isImmobile() && !mover.isShutDown()) { log(getClass(), METHOD_NAME, LogLevel.INFO, "Is truly immobile."); return true; log(getClass(), METHOD_NAME, LogLevel.INFO, "Has 0 movement."); return true; final MovePath movePath = new MovePath(getGame(), mover); switch (getBehaviorSettings().getFallShameIndex()) { case 10: threshold = 7; log(getClass(), METHOD_NAME, LogLevel.INFO, "Cannot stand up."); return true; final MovePath.MoveStepType type = (getBooleanOption(OptionsConstants.ADVGRNDMOV_TACOPS_CAREFUL_STAND) ? MovePath.MoveStepType.CAREFUL_STAND : MovePath.MoveStepType.GET_UP); log(getClass(), METHOD_NAME, LogLevel.INFO, "Need to roll " + target.getValue() + " to stand and our tolerance is " + threshold); final IHex hex = getHex(mech.getPosition()); final PilotingRollData target = mech.checkBogDown(walk,
@Test public void testGetEntityToMove() { Mockito.when(mockPrincess.getEntityToMove()).thenCallRealMethod(); Mockito.when(mockPrincess.isImmobilized(Mockito.any(Entity.class))).thenCallRealMethod(); Mockito.when(mockMech.getPosition()).thenReturn(mockCoords); Mockito.when(mockMech.isSelectableThisTurn()).thenReturn(true); Mockito.when(mockPrincess.calculateMoveIndex(Mockito.eq(mockMech), Mockito.any(StringBuilder.class))) .thenReturn(1.111); Mockito.when(mockBA.getPosition()).thenReturn(mockCoords); Mockito.when(mockBA.isSelectableThisTurn()).thenReturn(true); Mockito.when(mockPrincess.calculateMoveIndex(Mockito.eq(mockBA), Mockito.any(StringBuilder.class))) .thenReturn(6.666); Mockito.when(mockTank.getPosition()).thenReturn(mockCoords); Mockito.when(mockTank.isSelectableThisTurn()).thenReturn(true); Mockito.when(mockPrincess.calculateMoveIndex(Mockito.eq(mockTank), Mockito.any(StringBuilder.class))) .thenReturn(2.5); Mockito.when(mockOffBoardArty.isSelectableThisTurn()).thenReturn(true); Mockito.when(mockOffBoardArty.isOffBoard()).thenReturn(true); Mockito.when(mockPrincess.calculateMoveIndex(Mockito.eq(mockOffBoardArty), Mockito.any(StringBuilder.class))) .thenReturn(10.0); Mockito.when(mockTurn.isValidEntity(Mockito.any(Entity.class), Mockito.any(IGame.class))).thenCallRealMethod(); Mockito.when(mockTurn.isValidEntity(Mockito.any(Entity.class), Mockito.any(IGame.class), Mockito.anyBoolean())).thenCallRealMethod(); Mockito.when(mockPrincess.getGame()).thenReturn(mockGame); testEntityList.add(mockBA);
@Test public void testIsImmobilized() { Mockito.when(mockPrincess.isImmobilized(Mockito.any(Entity.class))).thenCallRealMethod(); Mockito.when(mockPrincess.getBooleanOption(Mockito.eq("tacops_careful_stand"))).thenReturn(false); Mockito.when(mockPrincess.getHex(Mockito.any(Coords.class))).thenReturn(mockHex); Mockito.doReturn(mockGame).when(mockPrincess).getGame(); Mockito.when(mockPrincess.getBehaviorSettings()).thenReturn(mockBehavior); Mockito.anyBoolean())) .thenReturn(mockPilotingRollData); Assert.assertFalse(mockPrincess.isImmobilized(mockMech)); Assert.assertFalse(mockPrincess.isImmobilized(mockMech)); Assert.assertTrue(mockPrincess.isImmobilized(mockMech)); Assert.assertTrue(mockPrincess.isImmobilized(mockMech)); Mockito.when(mockMech.getRunMP()).thenReturn(6); Mockito.when(mockTank.isImmobile()).thenReturn(false); Mockito.when(mockTank.isShutDown()).thenReturn(false); Assert.assertFalse(mockPrincess.isImmobilized(mockTank)); Mockito.when(mockMech.isProne()).thenReturn(true); Mockito.when(mockMech.cannotStandUpFromHullDown()).thenReturn(true); Assert.assertTrue(mockPrincess.isImmobilized(mockMech));
final MMLogger fakeLogger = new FakeLogger(); mockPrincess = Mockito.mock(Princess.class); Mockito.when(mockPrincess.getLogger()).thenReturn(fakeLogger); Mockito.when(mockPrincess.getBehaviorSettings()).thenReturn(mockBehavior); Mockito.when(mockPrincess.getPathRanker(PathRankerType.Basic)).thenReturn(mockPathRanker); Mockito.when(mockPrincess.getHonorUtil()).thenReturn(mockHonorUtil);