Search in sources :

Example 11 with TerritoryEffect

use of games.strategy.engine.data.TerritoryEffect in project triplea by triplea-game.

the class DiceRollTest method testSimpleLowLuck.

@Test
public void testSimpleLowLuck() {
    GameDataTestUtil.makeGameLowLuck(gameData);
    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);
    final UnitType infantryType = GameDataTestUtil.infantry(gameData);
    final List<Unit> infantry = infantryType.create(1, russians);
    final Collection<TerritoryEffect> territoryEffects = TerritoryEffectHelper.getEffects(westRussia);
    // infantry defends and hits at 1 (0 based)
    bridge.setRandomSource(new ScriptedRandomSource(new int[] { 1 }));
    final DiceRoll roll = DiceRoll.rollDice(infantry, true, russians, bridge, battle, "", territoryEffects, null);
    assertThat(roll.getHits(), is(1));
    // infantry does not hit at 2 (0 based)
    bridge.setRandomSource(new ScriptedRandomSource(new int[] { 2 }));
    final DiceRoll roll2 = DiceRoll.rollDice(infantry, true, russians, bridge, battle, "", territoryEffects, null);
    assertThat(roll2.getHits(), is(0));
    // infantry attacks and hits at 0 (0 based)
    bridge.setRandomSource(new ScriptedRandomSource(new int[] { 0 }));
    final DiceRoll roll3 = DiceRoll.rollDice(infantry, false, russians, bridge, battle, "", territoryEffects, null);
    assertThat(roll3.getHits(), is(1));
    // infantry attack does not hit at 1 (0 based)
    bridge.setRandomSource(new ScriptedRandomSource(new int[] { 1 }));
    final DiceRoll roll4 = DiceRoll.rollDice(infantry, false, russians, bridge, battle, "", territoryEffects, null);
    assertThat(roll4.getHits(), is(0));
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) TerritoryEffect(games.strategy.engine.data.TerritoryEffect) UnitType(games.strategy.engine.data.UnitType) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) ScriptedRandomSource(games.strategy.engine.random.ScriptedRandomSource) Unit(games.strategy.engine.data.Unit) TripleAUnit(games.strategy.triplea.TripleAUnit) Test(org.junit.jupiter.api.Test)

Aggregations

TerritoryEffect (games.strategy.engine.data.TerritoryEffect)11 Unit (games.strategy.engine.data.Unit)7 Test (org.junit.jupiter.api.Test)6 ScriptedRandomSource (games.strategy.engine.random.ScriptedRandomSource)5 ITestDelegateBridge (games.strategy.engine.data.ITestDelegateBridge)4 PlayerID (games.strategy.engine.data.PlayerID)4 Territory (games.strategy.engine.data.Territory)4 UnitType (games.strategy.engine.data.UnitType)4 TripleAUnit (games.strategy.triplea.TripleAUnit)4 ArrayList (java.util.ArrayList)2 CompositeChange (games.strategy.engine.data.CompositeChange)1 GameParseException (games.strategy.engine.data.GameParseException)1 UnitBattleComparator (games.strategy.triplea.delegate.UnitBattleComparator)1 CasualtyList (games.strategy.triplea.delegate.dataObjects.CasualtyList)1 TerritoryEffectDrawable (games.strategy.triplea.ui.screen.drawable.TerritoryEffectDrawable)1 Point (java.awt.Point)1 List (java.util.List)1