use of games.strategy.engine.data.ITestDelegateBridge in project triplea by triplea-game.
the class DiceRollTest method testHeavyBombersLhtr2.
@Test
public void testHeavyBombersLhtr2() {
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[] { 3, 2 }));
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.data.ITestDelegateBridge in project triplea by triplea-game.
the class DiceRollTest method testDiceRollCount.
@Test
public void testDiceRollCount() {
final PlayerID british = GameDataTestUtil.british(gameData);
final Territory location = gameData.getMap().getTerritory("United Kingdom");
final Unit bombers = gameData.getMap().getTerritory("United Kingdom").getUnits().getMatches(Matches.unitIsStrategicBomber()).get(0);
final Collection<TerritoryEffect> territoryEffects = TerritoryEffectHelper.getEffects(location);
// default 1 roll
assertThat(BattleCalculator.getRolls(bombers, british, false, true, territoryEffects), is(1));
assertThat(BattleCalculator.getRolls(bombers, british, true, true, territoryEffects), is(1));
// hb, for revised 2 on attack, 1 on defence
final ITestDelegateBridge testDelegateBridge = getDelegateBridge(british);
TechTracker.addAdvance(british, testDelegateBridge, TechAdvance.findAdvance(TechAdvance.TECH_PROPERTY_HEAVY_BOMBER, gameData, british));
// lhtr hb, 2 for both
gameData.getProperties().set(Constants.LHTR_HEAVY_BOMBERS, Boolean.TRUE);
assertThat(BattleCalculator.getRolls(bombers, british, false, true, territoryEffects), is(2));
assertThat(BattleCalculator.getRolls(bombers, british, true, true, territoryEffects), is(2));
}
use of games.strategy.engine.data.ITestDelegateBridge in project triplea by triplea-game.
the class DiceRollTest method testMarineAttackPlus1.
@Test
public void testMarineAttackPlus1() throws Exception {
gameData = TestMapGameData.IRON_BLITZ.getGameData();
final Territory algeria = gameData.getMap().getTerritory("Algeria");
final PlayerID americans = GameDataTestUtil.americans(gameData);
final UnitType marine = gameData.getUnitTypeList().getUnitType(Constants.UNIT_TYPE_MARINE);
final List<Unit> attackers = marine.create(1, americans);
final ITestDelegateBridge bridge = getDelegateBridge(americans);
bridge.setRandomSource(new ScriptedRandomSource(new int[] { 1 }));
final MockBattle battle = new MockBattle(algeria);
battle.setAmphibiousLandAttackers(attackers);
battle.setIsAmphibious(true);
final DiceRoll roll = DiceRoll.rollDice(attackers, false, americans, bridge, battle, "", TerritoryEffectHelper.getEffects(algeria), null);
assertThat(roll.getHits(), is(1));
}
use of games.strategy.engine.data.ITestDelegateBridge in project triplea by triplea-game.
the class LhtrTest method testSubDefenseBonus.
@Test
public void testSubDefenseBonus() {
final UnitType sub = GameDataTestUtil.submarine(gameData);
final UnitAttachment attachment = UnitAttachment.get(sub);
final PlayerID japanese = GameDataTestUtil.japanese(gameData);
// before the advance, subs defend and attack at 2
assertEquals(2, attachment.getDefense(japanese));
assertEquals(2, attachment.getAttack(japanese));
final ITestDelegateBridge bridge = getDelegateBridge(japanese);
TechTracker.addAdvance(japanese, bridge, TechAdvance.findAdvance(TechAdvance.TECH_PROPERTY_SUPER_SUBS, gameData, japanese));
// after tech advance, this is now 3
assertEquals(3, attachment.getDefense(japanese));
assertEquals(3, attachment.getAttack(japanese));
// make sure this only changes for the player with the tech
final PlayerID americans = GameDataTestUtil.americans(gameData);
assertEquals(2, attachment.getDefense(americans));
assertEquals(2, attachment.getAttack(americans));
}
use of games.strategy.engine.data.ITestDelegateBridge in project triplea by triplea-game.
the class LhtrTest method testFightersDestroyedWhenNoPendingCarriers.
@Test
public void testFightersDestroyedWhenNoPendingCarriers() {
final MoveDelegate delegate = (MoveDelegate) gameData.getDelegateList().getDelegate("move");
delegate.initialize("MoveDelegate", "MoveDelegate");
final PlayerID germans = GameDataTestUtil.germans(gameData);
final ITestDelegateBridge bridge = getDelegateBridge(germans);
bridge.setStepName("germanNonCombatMove");
delegate.setDelegateBridgeAndPlayer(bridge);
delegate.start();
final Territory baltic = gameData.getMap().getTerritory("5 Sea Zone");
final Territory easternEurope = gameData.getMap().getTerritory("Eastern Europe");
// move a fighter to the baltic
final Route route = new Route();
route.setStart(easternEurope);
route.add(baltic);
final UnitType fighterType = GameDataTestUtil.fighter(gameData);
delegate.move(easternEurope.getUnits().getMatches(Matches.unitIsOfType(fighterType)), route);
// end the move phase
delegate.end();
// there is no pending carrier to be placed
// the fighter cannot hover
assertFalse(baltic.getUnits().anyMatch(Matches.unitIsOfType(fighterType)));
}
Aggregations