/** * Initialize the possible path rankers. * Has a dependency on the fire controls being initialized. */ public void initializePathRankers() { initializeFireControls(); pathRankers = new HashMap<>(); BasicPathRanker basicPathRanker = new BasicPathRanker(this); basicPathRanker.setFireControl(fireControls.get(FireControlType.Basic)); basicPathRanker.setPathEnumerator(precognition.getPathEnumerator()); pathRankers.put(PathRankerType.Basic, basicPathRanker); InfantryPathRanker infantryPathRanker = new InfantryPathRanker(this); infantryPathRanker.setFireControl(fireControls.get(FireControlType.Infantry)); infantryPathRanker.setPathEnumerator(precognition.getPathEnumerator()); pathRankers.put(PathRankerType.Infantry, infantryPathRanker); NewtonianAerospacePathRanker newtonianAerospacePathRanker = new NewtonianAerospacePathRanker(this); newtonianAerospacePathRanker.setFireControl(fireControls.get(FireControlType.Basic)); newtonianAerospacePathRanker.setPathEnumerator(precognition.getPathEnumerator()); pathRankers.put(PathRankerType.NewtonianAerospace, newtonianAerospacePathRanker); }
double theirDamagePotential = calculateDamagePotential(enemy, new EntityState(enemy), path, theirDamagePotential += calculateKickDamagePotential(enemy, path, game); returnResponse.setMyEstimatedDamage(calculateMyDamagePotential(path, enemy, distance, calculateMyKickDamagePotential(path, enemy, game));
"EntityEvaluationResponse evaluateUnmovedEnemy(Entity," + "MovePath,IGame)"; getOwner().methodBegin(getClass(), METHOD_NAME); Coords leftFlank = finalCoords.translated((myFacing + 2) % 6); Coords rightFlank = finalCoords.translated((myFacing + 4) % 6); Coords closest = getClosestCoordsTo(enemy.getId(), finalCoords); if (closest == null) { return returnResponse; if (path.getEntity().canChangeSecondaryFacing()) { leftBounds = new HexLine(behind, (myFacing + 2) % 6, getOwner()); rightBounds = new HexLine(behind, (myFacing + 4) % 6, getOwner()); } else { leftBounds = new HexLine(behind, (myFacing + 1) % 6, getOwner()); rightBounds = new HexLine(behind, (myFacing + 5) % 6, getOwner()); boolean inMyLos = isInMyLoS(enemy, leftBounds, rightBounds); if (inMyLos) { returnResponse.addToMyEstimatedDamage( getMaxDamageAtRange(fireControl, path.getEntity(), range, getMaxDamageAtRange(fireControl,
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 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; }
getOwner().methodBegin(getClass(), METHOD_NAME); double successProbability = getMovePathSuccessProbability(pathCopy, formula); double utility = -calculateFallMod(successProbability, formula); double expectedDamageTaken = checkPathForHazards(pathCopy, movingUnit, game); if (getOwner().getHonorUtil().isEnemyBroken(enemy.getId(), enemy.getOwnerId(), getOwner().getForcedWithdrawal())) { continue; if (evaluateAsMoved(enemy)) { //For units that have already moved eval = evaluateMovedEnemy(enemy, pathCopy, game); } else { //for units that have not moved this round eval = evaluateUnmovedEnemy(enemy, path, extremeRange, losRange); Map<Coords, Double> artyDamage = getOwner().getPathRankerState().getIncomingFriendlyArtilleryDamage(); friendlyArtilleryDamage = ArtilleryTargetingControl.evaluateIncomingArtilleryDamage(path.getFinalCoords(), getOwner()); artyDamage.put(path.getFinalCoords(), friendlyArtilleryDamage); } else { calcDamageToStrategicTargets(pathCopy, game, getOwner().getFireControlState(), damageEstimate); getOwner().getBehaviorSettings().getBraveryValue();
@Test public void testRankPath() { final BasicPathRanker testRanker = Mockito.spy(new BasicPathRanker(mockPrincess)); Mockito.doReturn(1.0) .when(testRanker) .getMovePathSuccessProbability(Mockito.any(MovePath.class), Mockito.any(StringBuilder.class)); Mockito.doReturn(5) .when(testRanker) .distanceToClosestEdge(Mockito.any(Coords.class), Mockito.any(IGame.class)); Mockito.doReturn(20) .when(testRanker) .distanceToHomeEdge(Mockito.any(Coords.class), Mockito.any(CardinalEdge.class), Mockito.any(IGame.class)); Mockito.doReturn(12.0) .when(testRanker) .distanceToClosestEnemy(Mockito.any(Entity.class), Mockito.any(Coords.class), Mockito.any(IGame.class)); Mockito.doReturn(0.0) .when(testRanker) .checkPathForHazards(Mockito.any(MovePath.class), Mockito.any(Entity.class), Mockito.any(IGame.class)); Mockito.when(testRanker.getBestDamageByEnemies()).thenReturn(bestDamageByEnemies); Mockito.doReturn(evalForMockEnemyMech) .when(testRanker) .evaluateMovedEnemy(Mockito.eq(mockEnemyMech1), Mockito.any(MovePath.class), Mockito.any(IGame.class)); testEnemies.add(mockEnemyMech1); Mockito.doReturn(mockEnemyMech1) .when(testRanker) .findClosestEnemy(Mockito.eq(mockMover), Mockito.nullable(Coords.class), Mockito.any(IGame.class));
@Test public void testEvaluateMovedEnemy() { final BasicPathRanker testRanker = Mockito.spy(new BasicPathRanker(mockPrincess)); Mockito.doReturn(mockPrincess).when(testRanker).getOwner(); .calculateDamagePotential(Mockito.eq(mockEnemyMech), Mockito.any(EntityState.class), Mockito.any(MovePath.class), Mockito.any(EntityState.class), Mockito.anyInt(), Mockito.any(IGame.class)); Mockito.doReturn(10.0) .when(testRanker) .calculateKickDamagePotential(Mockito.eq(mockEnemyMech), Mockito.any(MovePath.class), Mockito.any(IGame.class)); Mockito.doReturn(14.5) .when(testRanker) .calculateMyDamagePotential(Mockito.any(MovePath.class), Mockito.eq(mockEnemyMech), Mockito.anyInt(), Mockito.any(IGame.class)); Mockito.doReturn(8.0) .when(testRanker) .calculateMyKickDamagePotential(Mockito.any(MovePath.class), Mockito.eq(mockEnemyMech), Mockito.any(IGame.class)); final Map<Integer, Double> testBestDamageByEnemies = new TreeMap<>(); Mockito.doReturn(testBestDamageByEnemies) .when(testRanker) .getBestDamageByEnemies(); final EntityEvaluationResponse expected = new EntityEvaluationResponse(); expected.setMyEstimatedDamage(14.5); expected.setMyEstimatedPhysicalDamage(8.0); expected.setEstimatedEnemyDamage(25.0); EntityEvaluationResponse actual = testRanker.evaluateMovedEnemy(mockEnemyMech, mockPath, mockGame);
@Test public void testEvaluateUnmovedEnemy() { final BasicPathRanker testRanker = Mockito.spy(new BasicPathRanker(mockPrincess)); Mockito.doReturn(mockPrincess).when(testRanker).getOwner(); Mockito.doReturn(10.0).when(testRanker).getMaxDamageAtRange(Mockito.nullable(FireControl.class), Mockito.eq(mockMyUnit), Mockito.anyInt(), Mockito.anyBoolean(), Mockito.anyBoolean()); Mockito.when(mockAero.isAirborneAeroOnGroundMap()).thenReturn(true); EntityEvaluationResponse expected = new EntityEvaluationResponse(); EntityEvaluationResponse actual = testRanker.evaluateUnmovedEnemy(mockAero, mockPath, false, false); assertEntityEvaluationResponseEquals(expected, actual); Mockito.doReturn(enemyCoords) .when(testRanker) .getClosestCoordsTo(Mockito.eq(enemyMechId), Mockito.eq(testCoords)); Mockito.doReturn(true) .when(testRanker) .isInMyLoS(Mockito.eq(mockEnemyMech), Mockito.any(BotGeometry.HexLine.class), Mockito.any(BotGeometry.HexLine.class)); Mockito.doReturn(8.5) .when(testRanker) .getMaxDamageAtRange(Mockito.nullable(FireControl.class), Mockito.eq(mockEnemyMech), Mockito.anyInt(), Mockito.anyBoolean(), Mockito.anyBoolean()); Mockito.doReturn(false) .when(testRanker) .canFlankAndKick(Mockito.eq(mockEnemyMech), Mockito.any(Coords.class), Mockito.any(Coords.class), Mockito.any(Coords.class), Mockito.anyInt()); expected = new EntityEvaluationResponse();
@Test public void testCalculateMyDamagePotential() { final BasicPathRanker testRanker = Mockito.spy(new BasicPathRanker(mockPrincess)); Mockito.doReturn(mockFireControl).when(testRanker).getFireControl(); double actual = testRanker.calculateMyDamagePotential(mockPath, mockEnemy, testDistance, mockGame); Assert.assertEquals(expected, actual, TOLERANCE); actual = testRanker.calculateMyDamagePotential(mockPath, mockEnemy, testDistance, mockGame); Assert.assertEquals(expected, actual, TOLERANCE); Mockito.when(mockEnemy.getPosition()).thenReturn(null); expected = 0; actual = testRanker.calculateMyDamagePotential(mockPath, mockEnemy, testDistance, mockGame); Assert.assertEquals(expected, actual, TOLERANCE);
@Test public void testCalculateDamagePotential() { final BasicPathRanker testRanker = Mockito.spy(new BasicPathRanker(mockPrincess)); Mockito.doReturn(mockFireControl).when(testRanker).getFireControl(); Assert.assertEquals(0.0, testRanker.calculateDamagePotential(mockEnemy, mockShooterState, mockPath, mockTargetState, testDistance, mockGame), TOLERANCE); testRanker.calculateDamagePotential(mockEnemy, mockShooterState, mockPath, Assert.assertEquals(0.0, testRanker.calculateDamagePotential(mockEnemy, mockShooterState, mockPath, mockTargetState, testDistance, mockGame), TOLERANCE);
testRollList.add(mockTargetRollTwo); final BasicPathRanker testRanker = Mockito.spy(new BasicPathRanker(mockPrincess)); Mockito.doReturn(testRollList).when(testRanker).getPSRList(Mockito.eq(mockPath)); double actual = testRanker.getMovePathSuccessProbability(mockPath, new StringBuilder()); Assert.assertEquals(expected, actual, TOLERANCE); actual = testRanker.getMovePathSuccessProbability(mockPath, new StringBuilder()); Assert.assertEquals(expected, actual, TOLERANCE);
final IGame mockGame = Mockito.mock(IGame.class); final BasicPathRanker testRanker = Mockito.spy(new BasicPathRanker(mockPrincess)); Mockito.doReturn(enemyList).when(mockPrincess).getEnemyEntities(); Entity actual = testRanker.findClosestEnemy(me, position, mockGame); Assert.assertEquals(expected, actual); enemyList.add(unmovedMech); expected = enemyMech; actual = testRanker.findClosestEnemy(me, position, mockGame); Assert.assertEquals(expected, actual); enemyList.add(mockAero); expected = enemyMech; actual = testRanker.findClosestEnemy(me, position, mockGame); Assert.assertEquals(expected, actual);
@Test public void testCheckPathForHazards() { final BasicPathRanker testRanker = Mockito.spy(new BasicPathRanker(mockPrincess)); Mockito.when(mockBA.isFireResistant()).thenReturn(true); Mockito.when(mockHexThree.getTerrainTypes()).thenReturn(new int[]{Terrains.BUILDING, Terrains.FIRE}); Assert.assertEquals(0, testRanker.checkPathForHazards(mockPath, mockBA, mockGame), TOLERANCE); Mockito.when(mockHexThree.getTerrainTypes()).thenReturn(new int[0]); Mockito.when(mockHexThree.getTerrainTypes()).thenReturn(new int[]{Terrains.MAGMA}); Mockito.when(mockHexThree.terrainLevel(Terrains.MAGMA)).thenReturn(1); Assert.assertEquals(166.7, testRanker.checkPathForHazards(mockPath, mockProto, mockGame), TOLERANCE); Mockito.when(mockHexThree.getTerrainTypes()).thenReturn(new int[0]); Mockito.when(mockHexThree.terrainLevel(Terrains.MAGMA)).thenReturn(0); Assert.assertEquals(50.0, testRanker.checkPathForHazards(mockPath, mockProto, mockGame), TOLERANCE); Mockito.when(mockHexThree.getTerrainTypes()).thenReturn(new int[0]); Mockito.when(mockHexThree.getTerrainTypes()).thenReturn(new int[]{Terrains.ICE, Terrains.WATER}); Mockito.when(mockHexThree.depth()).thenReturn(1); Assert.assertEquals(166.7, testRanker.checkPathForHazards(mockPath, mockInfantry, mockGame), TOLERANCE); Mockito.when(mockHexThree.getTerrainTypes()).thenReturn(new int[0]); Mockito.when(mockHexThree.depth()).thenReturn(0); Mockito.when(mockPath.isJumping()).thenReturn(false); Mockito.when(mockHexThree.getTerrainTypes()).thenReturn(new int[]{Terrains.BUILDING, Terrains.FIRE}); Assert.assertEquals(26.2859, testRanker.checkPathForHazards(mockPath, mockTank, mockGame), TOLERANCE); Mockito.when(mockHexThree.getTerrainTypes()).thenReturn(new int[0]); Assert.assertEquals(1.285, testRanker.checkPathForHazards(mockPath, mockUnit, mockGame), TOLERANCE);
@Test public void testCalcAllyCenter() { final BasicPathRanker testRanker = new BasicPathRanker(mockPrincess); Coords actual = testRanker.calcAllyCenter(myId, friends, mockGame); assertCoordsEqual(expected, actual); actual = testRanker.calcAllyCenter(myId, friends, mockGame); assertCoordsEqual(expected, actual); Mockito.when(mockFriend2.isOffBoard()).thenReturn(false); actual = testRanker.calcAllyCenter(myId, friends, mockGame); assertCoordsEqual(expected, actual); Mockito.when(mockFriend3.getPosition()).thenReturn(friendPosition3); actual = testRanker.calcAllyCenter(myId, friends, mockGame); assertCoordsEqual(expected, actual); Mockito.when(mockBoard.contains(Mockito.eq(friendPosition4))).thenReturn(true); actual = testRanker.calcAllyCenter(myId, new ArrayList<>(0), mockGame); Assert.assertNull(actual); actual = testRanker.calcAllyCenter(myId, null, mockGame); Assert.assertNull(actual); final List<Entity> solo = new ArrayList<>(1); solo.add(mockFriend1); actual = testRanker.calcAllyCenter(myId, solo, mockGame); Assert.assertNull(actual);
Mockito.when(mockRanker.distanceToHomeEdge(Mockito.any(Coords.class), Mockito.any(CardinalEdge.class), Mockito.any(IGame.class))).thenReturn(0); Mockito.when(mockPrincess.getPathRanker(Mockito.any(Entity.class))).thenReturn(mockRanker); Mockito.when(mockRanker.distanceToHomeEdge(Mockito.any(Coords.class), Mockito.any(CardinalEdge.class), Mockito.any(IGame.class))).thenReturn(1); Assert.assertFalse(mockPrincess.mustFleeBoard(mockMech));
.distanceToClosestEnemy(Mockito.any(Entity.class), Mockito.nullable(Coords.class), Mockito.nullable(IGame.class))) .thenReturn(10.0);