double calculateKickDamagePotential(Entity enemy, MovePath path, IGame game) { if (!(enemy instanceof Mech)) { return 0.0; } // if they can kick me, and probably hit, they probably will. PhysicalInfo theirKick = new PhysicalInfo(enemy, null, path.getEntity(), new EntityState(path), PhysicalAttackType.RIGHT_KICK, game, getOwner(), true); if (theirKick.getProbabilityToHit() <= 0.5) { return 0.0; } return theirKick.getExpectedDamageOnHit() * theirKick.getProbabilityToHit(); }
String getDebugDescription() { return getAttackType().toString() + " P. Hit: " + LOG_PER.format(getProbabilityToHit()) + ", Max Dam: " + LOG_DEC.format(getMaxDamage()) + ", Exp. Dam: " + LOG_DEC.format(getExpectedDamageOnHit()) + ", Num Crits: " + LOG_DEC.format(getExpectedCriticals()) + ", Kill Prob: " + LOG_PER.format(getKillProbability()); } }
/** * calculates the 'utility' of a physical action. * * @param physicalInfo The {@link PhysicalInfo} to be calculated. */ void calculateUtility(final PhysicalInfo physicalInfo) { // If we can't hit, there's no point. if (0.0 >= physicalInfo.getProbabilityToHit()) { physicalInfo.setUtility(-10000); return; } double utility = DAMAGE_UTILITY * physicalInfo.getExpectedDamage(); utility += CRITICAL_UTILITY * physicalInfo.getExpectedCriticals(); utility += KILL_UTILITY * physicalInfo.getKillProbability(); utility *= calcTargetPotentialDamageMultiplier(physicalInfo.getTarget()); utility -= (physicalInfo.getTarget() instanceof MechWarrior) ? EJECTED_PILOT_DISUTILITY : 0; utility += calcCommandUtility(physicalInfo.getTarget()); utility += calcStrategicBuildingTargetUtility(physicalInfo.getTarget()); utility += calcPriorityUnitTargetUtility(physicalInfo.getTarget()); utility -= calcCivilianTargetDisutility(physicalInfo.getTarget()); physicalInfo.setUtility(utility); }
public double getExpectedDamage() { return getProbabilityToHit() * getExpectedDamageOnHit(); }
/** * Current bot code requires physical attacks to be given as 'physical option'. This does the necessary conversion */ public PhysicalOption getAsPhysicalOption() { int optionInteger = 0; if (getAttackType() == PhysicalAttackType.RIGHT_PUNCH) { optionInteger = PhysicalOption.PUNCH_RIGHT; } if (getAttackType() == PhysicalAttackType.LEFT_PUNCH) { optionInteger = PhysicalOption.PUNCH_LEFT; } if (getAttackType() == PhysicalAttackType.RIGHT_KICK) { optionInteger = PhysicalOption.KICK_RIGHT; } if (getAttackType() == PhysicalAttackType.LEFT_KICK) { optionInteger = PhysicalOption.KICK_LEFT; } return new PhysicalOption(getShooter(), getTarget(), 0, optionInteger, null); }
new StringBuilder("Initializing Damage for ").append(getShooter().getDisplayName()) .append(" ").append(physicalAttackType.toString()) .append(" at ").append(getTarget().getDisplayName()) .append(":"); if (!(getShooter() instanceof Mech)) { owner.log(getClass(), METHOD_NAME, LogLevel.WARNING, msg.append("\n\tNot a mech!").toString()); setProbabilityToHit(0); setMaxDamage(0); setExpectedCriticals(0); setKillProbability(0); setExpectedDamageOnHit(0); return; shooterState = new EntityState(getShooter()); targetState = new EntityState(getTarget()); setHitData(owner.getFireControl(getShooter()).guessToHitModifierPhysical(getShooter(), shooterState, getTarget(), targetState, getAttackType(), game)); } else { PhysicalAttackAction action = buildAction(physicalAttackType, getShooter().getId(), getTarget()); setAction(action); setHitData(physicalAttackType.isPunch() ? ((PunchAttackAction) action).toHit(game) : ((KickAttackAction) action).toHit(game)); setDamageDirection(targetState, shooterState.getPosition());
PhysicalInfo testPhysicalInfo = Mockito.spy(new PhysicalInfo(mockPrincess)); testPhysicalInfo.setShooter(mockShooter); testPhysicalInfo.setTarget(mockTarget); Mockito.doNothing().when(testPhysicalInfo).setDamageDirection(Mockito.any(EntityState.class), Mockito.nullable(Coords.class)); Mockito.doReturn(1).when(testPhysicalInfo).getDamageDirection(); Mockito.doReturn(punchAction).when(testPhysicalInfo).buildAction(Mockito.eq(punch), Mockito.anyInt(), Mockito.any(Targetable.class)); Mockito.when(punchAction.toHit(Mockito.any(IGame.class))).thenReturn(mockToHit); Mockito.doReturn(kickAction).when(testPhysicalInfo).buildAction(Mockito.eq(kick), Mockito.anyInt(), Mockito.any(Targetable.class)); Mockito.when(kickAction.toHit(Mockito.any(IGame.class))).thenReturn(mockToHit); testPhysicalInfo.setShooter(mockShooter); testPhysicalInfo.setAttackType(punch); testPhysicalInfo.initDamage(punch, mockShooterState, mockTargetState, true, mockGame); Assert.assertEquals(0.583, testPhysicalInfo.getProbabilityToHit(), TOLERANCE); Assert.assertEquals(5.0, testPhysicalInfo.getMaxDamage(), TOLERANCE); Assert.assertEquals(0.0099, testPhysicalInfo.getExpectedCriticals(), TOLERANCE); Assert.assertEquals(0.0, testPhysicalInfo.getKillProbability(), TOLERANCE); Assert.assertEquals(5.0, testPhysicalInfo.getExpectedDamageOnHit(), TOLERANCE); testPhysicalInfo.setShooter(mockShooter); testPhysicalInfo.setAttackType(kick); testPhysicalInfo.initDamage(kick, mockShooterState, mockTargetState, true, mockGame); Assert.assertEquals(0.583, testPhysicalInfo.getProbabilityToHit(), TOLERANCE); Assert.assertEquals(10.0, testPhysicalInfo.getMaxDamage(), TOLERANCE);
PhysicalInfo testPhysicalInfo = Mockito.spy(new PhysicalInfo(mockPrincess)); Mockito.doReturn(15.0).when(testPhysicalInfo).getExpectedDamage(); Mockito.doReturn(0.46129).when(testPhysicalInfo).getExpectedCriticals(); Mockito.doReturn(0.02005).when(testPhysicalInfo).getKillProbability(); Mockito.doReturn(0.5).when(testPhysicalInfo).getProbabilityToHit(); testFireControl.calculateUtility(testPhysicalInfo); Assert.assertEquals(baseUtility, testPhysicalInfo.getUtility(), TOLERANCE); testPhysicalInfo = Mockito.spy(new PhysicalInfo(mockPrincess)); Mockito.doReturn(15.0).when(testPhysicalInfo).getExpectedDamage(); Mockito.doReturn(0.46129).when(testPhysicalInfo).getExpectedCriticals(); Mockito.doReturn(0.02005).when(testPhysicalInfo).getKillProbability(); Mockito.doReturn(0.0).when(testPhysicalInfo).getProbabilityToHit(); testFireControl.calculateUtility(testPhysicalInfo); Assert.assertEquals(-10000, testPhysicalInfo.getUtility(), TOLERANCE); testPhysicalInfo = Mockito.spy(new PhysicalInfo(mockPrincess)); Mockito.doReturn(15.0).when(testPhysicalInfo).getExpectedDamage(); Mockito.doReturn(0.46129).when(testPhysicalInfo).getExpectedCriticals(); Mockito.doReturn(0.02005).when(testPhysicalInfo).getKillProbability(); Mockito.doReturn(0.5).when(testPhysicalInfo).getProbabilityToHit(); Mockito.doReturn(mockPilot).when(testPhysicalInfo).getTarget(); testFireControl.calculateUtility(testPhysicalInfo); Assert.assertEquals(-979.3846, testPhysicalInfo.getUtility(), TOLERANCE); Assert.assertTrue(baseUtility > testPhysicalInfo.getUtility()); testPhysicalInfo = Mockito.spy(new PhysicalInfo(mockPrincess)); Mockito.doReturn(15.0).when(testPhysicalInfo).getExpectedDamage(); Mockito.doReturn(0.46129).when(testPhysicalInfo).getExpectedCriticals();
new PhysicalInfo(hitter, e, PhysicalAttackType.RIGHT_PUNCH, if (0 < right_punch.getUtility()) { if ((null == best_attack) || (right_punch.getUtility() > best_attack.getUtility())) { best_attack = right_punch; final PhysicalInfo left_punch = new PhysicalInfo( hitter, e, false); getFireControl(hitter).calculateUtility(left_punch); if (0 < left_punch.getUtility()) { if ((null == best_attack) || (left_punch.getUtility() > best_attack.getUtility())) { best_attack = left_punch; final PhysicalInfo right_kick = new PhysicalInfo( hitter, e, false); getFireControl(hitter).calculateUtility(right_kick); if (0 < right_kick.getUtility()) { if ((null == best_attack)
final PhysicalInfo guessInfo = new PhysicalInfo(shooter, null, target, null, attackType, game, owner, true); final PhysicalInfo accurateInfo = new PhysicalInfo(shooter, target, attackType, game, owner, false); if (guessInfo.getHitData().getValue() != accurateInfo.getHitData().getValue()) { ret += "Incorrect To Hit prediction, physical attack " + attackType.name() + ":\n"; ret += " Guess: " + Integer.toString(guessInfo.getHitData().getValue()) + " " + guessInfo.getHitData() .getDesc() + "\n"; ret += " Real: " + Integer.toString(accurateInfo.getHitData().getValue()) + " " + accurateInfo.getHitData().getDesc() + "\n";
double calculateMyKickDamagePotential(MovePath path, Entity enemy, IGame game) { if (!(path.getEntity() instanceof Mech)) { return 0.0; } PhysicalInfo myKick = new PhysicalInfo(path.getEntity(), new EntityState(path), enemy, null, PhysicalAttackType.RIGHT_KICK, game, getOwner(), true); if (myKick.getProbabilityToHit() <= 0.5) { return 0; } return myKick.getExpectedDamageOnHit() * myKick.getProbabilityToHit(); }
PhysicalInfo myKick = new PhysicalInfo( path.getEntity(), new EntityState(path), target, null, true); double expectedKickDamage = myKick.getExpectedDamageOnHit() * myKick.getProbabilityToHit(); if (expectedKickDamage > damageStructure.physicalDamage) { damageStructure.physicalDamage = expectedKickDamage;