use of games.strategy.engine.random.ScriptedRandomSource in project triplea by triplea-game.
the class WW2V3Year41Test method testAttackSubsOnDestroyer.
@Test
public void testAttackSubsOnDestroyer() {
final String defender = "Germans";
final String attacker = "British";
final Territory attacked = territory("31 Sea Zone", gameData);
final Territory from = territory("32 Sea Zone", gameData);
// 1 sub attacks 1 sub and 1 destroyer
// defender sneak attacks, not attacker
addTo(from, submarine(gameData).create(1, british(gameData)));
addTo(attacked, submarine(gameData).create(1, germans(gameData)));
addTo(attacked, destroyer(gameData).create(1, germans(gameData)));
final ITestDelegateBridge bridge = getDelegateBridge(british(gameData));
bridge.setStepName("CombatMove");
moveDelegate(gameData).setDelegateBridgeAndPlayer(bridge);
moveDelegate(gameData).start();
move(from.getUnits().getUnits(), new Route(from, attacked));
moveDelegate(gameData).end();
final MustFightBattle battle = (MustFightBattle) AbstractMoveDelegate.getBattleTracker(gameData).getPendingBattle(attacked, false, null);
final List<String> steps = battle.determineStepStrings(true);
assertEquals(Arrays.asList(defender + SUBS_SUBMERGE, defender + SUBS_FIRE, attacker + SELECT_SUB_CASUALTIES, REMOVE_SNEAK_ATTACK_CASUALTIES, attacker + SUBS_FIRE, defender + SELECT_SUB_CASUALTIES, defender + FIRE, attacker + SELECT_CASUALTIES, REMOVE_CASUALTIES, attacker + ATTACKER_WITHDRAW).toString(), steps.toString());
bridge.setRemote(dummyPlayer);
// defending subs sneak attack and hit
// no chance to return fire
final ScriptedRandomSource randomSource = new ScriptedRandomSource(0, ScriptedRandomSource.ERROR);
bridge.setRandomSource(randomSource);
battle.fight(bridge);
assertEquals(1, randomSource.getTotalRolled());
assertTrue(attacked.getUnits().getMatches(Matches.unitIsOwnedBy(british(gameData))).isEmpty());
assertEquals(2, attacked.getUnits().size());
}
use of games.strategy.engine.random.ScriptedRandomSource in project triplea by triplea-game.
the class DiceRollTest method testHeavyBombersLhtr.
@Test
public void testHeavyBombersLhtr() {
gameData.getProperties().set(Constants.LHTR_HEAVY_BOMBERS, Boolean.TRUE);
final PlayerID british = GameDataTestUtil.british(gameData);
final ITestDelegateBridge testDelegateBridge = getDelegateBridge(british);
TechTracker.addAdvance(british, testDelegateBridge, TechAdvance.findAdvance(TechAdvance.TECH_PROPERTY_HEAVY_BOMBER, gameData, british));
final List<Unit> bombers = gameData.getMap().getTerritory("United Kingdom").getUnits().getMatches(Matches.unitIsStrategicBomber());
testDelegateBridge.setRandomSource(new ScriptedRandomSource(new int[] { 2, 3 }));
final Territory germany = gameData.getMap().getTerritory("Germany");
final DiceRoll dice = DiceRoll.rollDice(bombers, false, british, testDelegateBridge, new MockBattle(germany), "", TerritoryEffectHelper.getEffects(germany), null);
assertThat(dice.getRolls(4).get(0).getType(), is(Die.DieType.HIT));
assertThat(dice.getRolls(4).get(1).getType(), is(Die.DieType.IGNORED));
assertThat(dice.getHits(), is(1));
}
use of games.strategy.engine.random.ScriptedRandomSource in project triplea by triplea-game.
the class DiceRollTest method testHeavyBombers.
@Test
public void testHeavyBombers() throws Exception {
gameData = TestMapGameData.IRON_BLITZ.getGameData();
final PlayerID british = GameDataTestUtil.british(gameData);
final ITestDelegateBridge testDelegateBridge = getDelegateBridge(british);
TechTracker.addAdvance(british, testDelegateBridge, TechAdvance.findAdvance(TechAdvance.TECH_PROPERTY_HEAVY_BOMBER, gameData, british));
final List<Unit> bombers = gameData.getMap().getTerritory("United Kingdom").getUnits().getMatches(Matches.unitIsStrategicBomber());
testDelegateBridge.setRandomSource(new ScriptedRandomSource(new int[] { 2, 3 }));
final Territory germany = gameData.getMap().getTerritory("Germany");
final DiceRoll dice = DiceRoll.rollDice(bombers, false, british, testDelegateBridge, new MockBattle(germany), "", TerritoryEffectHelper.getEffects(germany), null);
assertThat(dice.getRolls(4).get(0).getType(), is(Die.DieType.HIT));
assertThat(dice.getRolls(4).get(1).getType(), is(Die.DieType.HIT));
}
use of games.strategy.engine.random.ScriptedRandomSource in project triplea by triplea-game.
the class DiceRollTest method testVariableArtillerySupport.
@Test
public void testVariableArtillerySupport() {
final Territory westRussia = gameData.getMap().getTerritory("West Russia");
final MockBattle battle = new MockBattle(westRussia);
final PlayerID russians = GameDataTestUtil.russians(gameData);
final ITestDelegateBridge bridge = getDelegateBridge(russians);
// Add 1 artillery
final UnitType artillery = gameData.getUnitTypeList().getUnitType(Constants.UNIT_TYPE_ARTILLERY);
final List<Unit> units = artillery.create(1, russians);
// Set the supported unit count
for (final Unit unit : units) {
final UnitAttachment ua = UnitAttachment.get(unit.getType());
ua.setUnitSupportCount("2");
}
// Now add the infantry
final UnitType infantryType = GameDataTestUtil.infantry(gameData);
units.addAll(infantryType.create(2, russians));
// artillery supported infantry and art attack at 1 (0 based)
bridge.setRandomSource(new ScriptedRandomSource(new int[] { 1, 1, 1 }));
final DiceRoll roll = DiceRoll.rollDice(units, false, russians, bridge, battle, "", TerritoryEffectHelper.getEffects(westRussia), null);
assertThat(roll.getHits(), is(3));
}
use of games.strategy.engine.random.ScriptedRandomSource in project triplea by triplea-game.
the class DiceRollTest method testLhtrBomberDefend.
@Test
public void testLhtrBomberDefend() {
final PlayerID british = GameDataTestUtil.british(gameData);
gameData.getProperties().set(Constants.LHTR_HEAVY_BOMBERS, true);
final ITestDelegateBridge testDelegateBridge = getDelegateBridge(british);
final List<Unit> bombers = gameData.getMap().getTerritory("United Kingdom").getUnits().getMatches(Matches.unitIsStrategicBomber());
testDelegateBridge.setRandomSource(new ScriptedRandomSource(new int[] { 0, 1 }));
final Territory germany = gameData.getMap().getTerritory("Germany");
final DiceRoll dice = DiceRoll.rollDice(bombers, true, british, testDelegateBridge, new MockBattle(germany), "", TerritoryEffectHelper.getEffects(germany), null);
assertThat(dice.getRolls(1).size(), is(1));
assertThat(dice.getRolls(1).get(0).getType(), is(Die.DieType.HIT));
}
Aggregations