use of games.strategy.engine.random.ScriptedRandomSource in project triplea by triplea-game.
the class BattleCalculatorTest method testAaCasualtiesLowLuckMixed.
@Test
public void testAaCasualtiesLowLuckMixed() {
final GameData data = bridge.getData();
makeGameLowLuck(data);
setSelectAaCasualties(data, false);
// 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());
// 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, null, null, null, territory("Germany", data), null, false, null).getKilled();
assertEquals(2, casualties.size());
// should be 1 fighter and 1 bomber
assertEquals(1, CollectionUtils.countMatches(casualties, Matches.unitIsStrategicBomber()));
assertEquals(1, CollectionUtils.countMatches(casualties, Matches.unitIsStrategicBomber().negate()));
}
use of games.strategy.engine.random.ScriptedRandomSource in project triplea by triplea-game.
the class BattleCalculatorTest method testAaCasualtiesLowLuckMixedWithRolling.
@Test
public void testAaCasualtiesLowLuckMixedWithRolling() {
final GameData data = bridge.getData();
makeGameLowLuck(data);
setSelectAaCasualties(data, false);
// 7 bombers and 7 fighters
// 2 extra units, roll once
final Collection<Unit> planes = bomber(data).create(7, british(data));
planes.addAll(fighter(data).create(7, british(data)));
final Collection<Unit> defendingAa = territory("Germany", data).getUnits().getMatches(Matches.unitIsAaForAnything());
// one roll, a hit
final ScriptedRandomSource randomSource = new ScriptedRandomSource(new int[] { 0 });
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);
// make sure we rolled once
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(3, casualties.size());
// a second roll for choosing which unit
assertEquals(2, randomSource.getTotalRolled());
// should be 2 fighters and 1 bombers
assertEquals(1, CollectionUtils.countMatches(casualties, Matches.unitIsStrategicBomber()));
assertEquals(2, CollectionUtils.countMatches(casualties, Matches.unitIsStrategicBomber().negate()));
}
use of games.strategy.engine.random.ScriptedRandomSource in project triplea by triplea-game.
the class BattleCalculatorTest method testAaCasualtiesLowLuckMixedWithRollingForBombers.
@Test
public void testAaCasualtiesLowLuckMixedWithRollingForBombers() {
final GameData data = bridge.getData();
makeGameLowLuck(data);
setSelectAaCasualties(data, false);
// 6 bombers, 7 fighters
final Collection<Unit> planes = bomber(data).create(6, british(data));
planes.addAll(fighter(data).create(7, british(data)));
final Collection<Unit> defendingAa = territory("Germany", data).getUnits().getMatches(Matches.unitIsAaForAnything());
// 1 roll for the extra fighter
final ScriptedRandomSource randomSource = new ScriptedRandomSource(new int[] { 0, 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);
// make sure we rolled once
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(3, casualties.size());
// should be 2 fighters and 1 bombers
assertEquals(1, CollectionUtils.countMatches(casualties, Matches.unitIsStrategicBomber()));
assertEquals(2, CollectionUtils.countMatches(casualties, Matches.unitIsStrategicBomber().negate()));
}
use of games.strategy.engine.random.ScriptedRandomSource in project triplea by triplea-game.
the class WW2V3Year41Test method testDefencelessTransportsDie.
@Test
public void testDefencelessTransportsDie() {
final PlayerID british = british(gameData);
final ITestDelegateBridge bridge = getDelegateBridge(british);
bridge.setStepName("CombatMove");
moveDelegate(gameData).setDelegateBridgeAndPlayer(bridge);
moveDelegate(gameData).start();
final Territory uk = territory("United Kingdom", gameData);
final Territory sz5 = territory("5 Sea Zone", gameData);
// remove the sub
removeFrom(sz5, sz5.getUnits().getMatches(Matches.unitIsSub()));
when(dummyPlayer.retreatQuery(any(), anyBoolean(), any(), any(), any())).thenAnswer(new Answer<Territory>() {
@Override
public Territory answer(final InvocationOnMock invocation) throws Throwable {
throw new IllegalStateException("Should not be asked to retreat:" + invocation.getArgument(4));
}
});
bridge.setRemote(dummyPlayer);
move(uk.getUnits().getMatches(Matches.unitIsAir()), gameData.getMap().getRoute(uk, sz5));
// move units for amphib assault
moveDelegate(gameData).end();
bridge.setStepName("Combat");
// cook the dice so that 1 british fighters hits, and nothing else
// this will leave 1 transport alone in the sea zone
bridge.setRandomSource(new ScriptedRandomSource(1, 5, 5, 5, 5, 5, 5, 5, 5));
battleDelegate(gameData).setDelegateBridgeAndPlayer(bridge);
battleDelegate(gameData).start();
// make sure the transports died
assertTrue(sz5.getUnits().getMatches(Matches.unitIsOwnedBy(germans(gameData))).isEmpty());
}
use of games.strategy.engine.random.ScriptedRandomSource in project triplea by triplea-game.
the class WW2V3Year41Test method testLoadedTransportAttackKillsLoadedUnits.
@Test
public void testLoadedTransportAttackKillsLoadedUnits() {
final PlayerID british = british(gameData);
final MoveDelegate moveDelegate = moveDelegate(gameData);
final ITestDelegateBridge bridge = getDelegateBridge(british);
bridge.setStepName("britishCombatMove");
when(dummyPlayer.selectAttackSubs(any())).thenReturn(true);
bridge.setRemote(dummyPlayer);
moveDelegate.setDelegateBridgeAndPlayer(bridge);
moveDelegate.start();
final Territory sz9 = territory("9 Sea Zone", gameData);
final Territory sz7 = territory("7 Sea Zone", gameData);
final Territory uk = territory("United Kingdom", gameData);
final Route sz9ToSz7 = new Route(sz9, territory("8 Sea Zone", gameData), sz7);
// move the transport to attack, this is suicide but valid
final List<Unit> transports = sz9.getUnits().getMatches(Matches.unitIsTransport());
move(transports, sz9ToSz7);
// load the transport
load(uk.getUnits().getMatches(Matches.unitIsLandTransportable()), new Route(uk, sz7));
moveDelegate(gameData).end();
final ScriptedRandomSource randomSource = new ScriptedRandomSource(new int[] { 0, 1 });
bridge.setRandomSource(randomSource);
bridge.setStepName("britishBattle");
final BattleDelegate battleDelegate = battleDelegate(gameData);
battleDelegate.setDelegateBridgeAndPlayer(bridge);
assertEquals(2, TransportTracker.transporting(transports.get(0)).size());
battleDelegate.start();
// battle already fought
// make sure the infantry die with the transport
assertTrue(sz7.getUnits().getMatches(Matches.unitOwnedBy(british)).isEmpty(), sz7.getUnits().toString());
}
Aggregations