String getDebugDescription(boolean detailed) { if (size() == 0) { return "Empty FiringPlan!"; } StringBuilder description = new StringBuilder("Firing Plan for ").append(get(0).getShooter().getChassis()) .append(" at ") .append(getTarget().getDisplayName()) .append("; ").append(Integer.toString(size())) .append(" weapons fired "); if (detailed) { for (WeaponFireInfo weaponFireInfo : this) { description.append("\n\t\t").append(weaponFireInfo.getDebugDescription()); } } DecimalFormat decimalFormat = new DecimalFormat("0.00000"); description.append("\n\tTotal Expected Damage=").append(decimalFormat.format(getExpectedDamage())); description.append("\n\tTotal Expected Criticals=").append(decimalFormat.format(getExpectedCriticals())); description.append("\n\tKill Probability=").append(decimalFormat.format(getKillProbability())); description.append("\n\tUtility=").append(decimalFormat.format(getUtility())); return description.toString(); }
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof FiringPlan)) return false; if (!super.equals(o)) return false; FiringPlan that = (FiringPlan) o; final double TOLERANCE = 0.00001; if (twist != that.twist) return false; if (Math.abs(utility - that.utility) > TOLERANCE) return false; if (!target.equals(that.target)) return false; if (getHeat() != that.getHeat()) return false; if (Math.abs(getKillProbability() - that.getKillProbability()) > TOLERANCE) return false; if (Math.abs(getExpectedCriticals() - that.getExpectedCriticals()) > TOLERANCE) return false; //noinspection RedundantIfStatement if (Math.abs(getExpectedDamage() - that.getExpectedDamage()) > TOLERANCE) return false; return true; }
@Test public void testGetKillProbability() { Mockito.when(mockWeaponFireInfoMG.getKillProbability()).thenReturn(0.0); Mockito.when(mockWeaponFireInfoPPC.getKillProbability()).thenReturn(0.0024); Mockito.when(mockWeaponFireInfoERML.getKillProbability()).thenReturn(0.0); //noinspection PointlessArithmeticExpression double expected = 1 - ((1 - 0) * (1 - 0.0024) * (1 - 0)); Assert.assertEquals(expected, testFiringPlan.getKillProbability(), TOLERANCE); Mockito.when(mockWeaponFireInfoMG.getKillProbability()).thenReturn(1.0); Mockito.when(mockWeaponFireInfoPPC.getKillProbability()).thenReturn(0.0024); Mockito.when(mockWeaponFireInfoERML.getKillProbability()).thenReturn(0.0); //noinspection PointlessArithmeticExpression expected = 1 - ((1 - 1) * (1 - 0.0024) * (1 - 0)); Assert.assertEquals(expected, testFiringPlan.getKillProbability(), TOLERANCE); Mockito.when(mockWeaponFireInfoMG.getKillProbability()).thenReturn(0.5); Mockito.when(mockWeaponFireInfoPPC.getKillProbability()).thenReturn(0.5); Mockito.when(mockWeaponFireInfoERML.getKillProbability()).thenReturn(0.5); expected = 1 - ((1 - 0.5) * (1 - 0.5) * (1 - 0.5)); Assert.assertEquals(expected, testFiringPlan.getKillProbability(), TOLERANCE); }
Mockito.doReturn(15.0).when(testFiringPlan).getExpectedDamage(); Mockito.doReturn(0.46129).when(testFiringPlan).getExpectedCriticals(); Mockito.doReturn(0.02005).when(testFiringPlan).getKillProbability(); Mockito.doReturn(0).when(testFiringPlan).getHeat(); Mockito.doReturn(0.0).when(testFireControl).calcDamageAllocationUtility(Mockito.any(Targetable.class), Mockito.anyDouble()); Mockito.doReturn(15.0).when(testFiringPlan).getExpectedDamage(); Mockito.doReturn(0.46129).when(testFiringPlan).getExpectedCriticals(); Mockito.doReturn(0.02005).when(testFiringPlan).getKillProbability(); Mockito.doReturn(0).when(testFiringPlan).getHeat(); Mockito.doReturn(0.0).when(testFireControl).calcDamageAllocationUtility(Mockito.any(Targetable.class), Mockito.anyDouble()); Mockito.doReturn(15.0).when(testFiringPlan).getExpectedDamage(); Mockito.doReturn(0.46129).when(testFiringPlan).getExpectedCriticals(); Mockito.doReturn(0.02005).when(testFiringPlan).getKillProbability(); Mockito.doReturn(0).when(testFiringPlan).getHeat(); Mockito.doReturn(0.0).when(testFireControl).calcDamageAllocationUtility(Mockito.any(Targetable.class), Mockito.anyDouble()); Mockito.doReturn(15.0).when(testFiringPlan).getExpectedDamage(); Mockito.doReturn(0.46129).when(testFiringPlan).getExpectedCriticals(); Mockito.doReturn(0.02005).when(testFiringPlan).getKillProbability(); Mockito.doReturn(0).when(testFiringPlan).getHeat(); Mockito.doReturn(0.0).when(testFireControl).calcDamageAllocationUtility(Mockito.any(Targetable.class), Mockito.anyDouble()); Mockito.doReturn(15.0).when(testFiringPlan).getExpectedDamage(); Mockito.doReturn(0.46129).when(testFiringPlan).getExpectedCriticals(); Mockito.doReturn(0.02005).when(testFiringPlan).getKillProbability(); Mockito.doReturn(0).when(testFiringPlan).getHeat(); Mockito.doReturn(0.0).when(testFireControl).calcDamageAllocationUtility(Mockito.any(Targetable.class), Mockito.anyDouble());
utility += DAMAGE_UTILITY * expectedDamage; utility += CRITICAL_UTILITY * firingPlan.getExpectedCriticals(); utility += KILL_UTILITY * firingPlan.getKillProbability();