use of games.strategy.engine.random.ScriptedRandomSource in project triplea by triplea-game.
the class BattleCalculatorTest method testAaCasualtiesLowLuckMixedWithChooseAaCasualties.
@Test
public void testAaCasualtiesLowLuckMixedWithChooseAaCasualties() {
final GameData data = bridge.getData();
makeGameLowLuck(data);
setSelectAaCasualties(data, true);
// 6 bombers and 6 fighters
final Collection<Unit> planes = bomber(data).create(6, british(data));
planes.addAll(fighter(data).create(6, british(data)));
final Collection<Unit> defendingAa = territory("Germany", data).getUnits().getMatches(Matches.unitIsAaForAnything());
when(dummyPlayer.selectCasualties(any(), any(), anyInt(), any(), any(), any(), any(), any(), any(), anyBoolean(), any(), any(), any(), any(), anyBoolean())).thenAnswer(new Answer<CasualtyDetails>() {
@Override
public CasualtyDetails answer(final InvocationOnMock invocation) {
final Collection<Unit> selectFrom = invocation.getArgument(0);
final int count = invocation.getArgument(2);
final List<Unit> selected = CollectionUtils.getNMatches(selectFrom, count, Matches.unitIsStrategicBomber());
return new CasualtyDetails(selected, new ArrayList<>(), false);
}
});
bridge.setRemote(dummyPlayer);
// don't allow rolling, 6 of each is deterministic
bridge.setRandomSource(new ScriptedRandomSource(new int[] { ScriptedRandomSource.ERROR }));
final DiceRoll roll = DiceRoll.rollAa(CollectionUtils.getMatches(planes, Matches.unitIsOfTypes(UnitAttachment.get(defendingAa.iterator().next().getType()).getTargetsAa(data))), defendingAa, bridge, territory("Germany", data), true);
final Collection<Unit> casualties = BattleCalculator.getAaCasualties(false, planes, planes, defendingAa, defendingAa, roll, bridge, germans(data), british(data), null, territory("Germany", data), null, false, null).getKilled();
assertEquals(2, casualties.size());
// we selected all bombers
assertEquals(2, CollectionUtils.countMatches(casualties, Matches.unitIsStrategicBomber()));
assertEquals(0, CollectionUtils.countMatches(casualties, Matches.unitIsStrategicBomber().negate()));
}
use of games.strategy.engine.random.ScriptedRandomSource in project triplea by triplea-game.
the class BattleCalculatorTest method testAaCasualtiesLowLuckMixedMultipleDiceRolled.
@Test
public void testAaCasualtiesLowLuckMixedMultipleDiceRolled() {
final GameData data = bridge.getData();
makeGameLowLuck(data);
setSelectAaCasualties(data, false);
// 5 bombers and 5 fighters
final Collection<Unit> planes = bomber(data).create(5, british(data));
planes.addAll(fighter(data).create(5, british(data)));
final Collection<Unit> defendingAa = territory("Germany", data).getUnits().getMatches(Matches.unitIsAaForAnything());
// should roll once, a hit
final ScriptedRandomSource randomSource = new ScriptedRandomSource(new int[] { 0, 1, 1, ScriptedRandomSource.ERROR });
bridge.setRandomSource(randomSource);
final DiceRoll roll = DiceRoll.rollAa(CollectionUtils.getMatches(planes, Matches.unitIsOfTypes(UnitAttachment.get(defendingAa.iterator().next().getType()).getTargetsAa(data))), defendingAa, bridge, territory("Germany", data), true);
assertEquals(1, randomSource.getTotalRolled());
final Collection<Unit> casualties = BattleCalculator.getAaCasualties(false, planes, planes, defendingAa, defendingAa, roll, bridge, null, null, null, territory("Germany", data), null, false, null).getKilled();
assertEquals(2, casualties.size());
// two extra rolls to pick which units are hit
assertEquals(3, randomSource.getTotalRolled());
// should be 1 fighter and 1 bomber
assertEquals(0, CollectionUtils.countMatches(casualties, Matches.unitIsStrategicBomber()));
assertEquals(2, CollectionUtils.countMatches(casualties, Matches.unitIsStrategicBomber().negate()));
}
Aggregations