Search in sources :

Example 36 with ScriptedRandomSource

use of games.strategy.engine.random.ScriptedRandomSource 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));
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) 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)

Example 37 with ScriptedRandomSource

use of games.strategy.engine.random.ScriptedRandomSource in project triplea by triplea-game.

the class MoveDelegateTest method testReloadTransportAfterRetreatAllied.

@Test
public void testReloadTransportAfterRetreatAllied() {
    bridge = super.getDelegateBridge(british);
    bridge.setStepName("britishCombatMove");
    Route route = new Route();
    route.setStart(northSea);
    route.add(balticSeaZone);
    IntegerMap<UnitType> map = new IntegerMap<>();
    map.put(transport, 1);
    map.put(infantry, 2);
    // Move from the NorthSea to the BalticSea and validate the move
    String results = delegate.move(GameDataTestUtil.getUnits(map, route.getStart()), route);
    assertValid(results);
    // Unload transports into Finland and validate
    route = new Route();
    route.setStart(balticSeaZone);
    route.add(karelia);
    map = new IntegerMap<>();
    map.put(infantry, 2);
    results = delegate.move(GameDataTestUtil.getUnits(map, route.getStart()), route);
    assertValid(results);
    // Get the attacking sea units that will retreat
    final List<Unit> retreatingSeaUnits = new ArrayList<>();
    retreatingSeaUnits.addAll(balticSeaZone.getUnits().getMatches(Matches.enemyUnit(germans, gameData)));
    // Get the attacking land units that will retreat and their number
    final List<Unit> retreatingLandUnits = new ArrayList<>();
    retreatingLandUnits.addAll(karelia.getUnits().getMatches(Matches.isUnitAllied(russians, gameData)));
    final int retreatingLandSizeInt = retreatingLandUnits.size();
    // Get the defending land units that and their number
    retreatingLandUnits.addAll(karelia.getUnits().getMatches(Matches.isUnitAllied(british, gameData)));
    final List<Unit> defendingLandUnits = new ArrayList<>();
    final int defendingLandSizeInt = defendingLandUnits.size();
    // Set up the battles and the dependent battles
    final IBattle inBalticSeaZone = DelegateFinder.battleDelegate(gameData).getBattleTracker().getPendingBattle(balticSeaZone, false, null);
    assertNotNull(balticSeaZone);
    // Add some defending units in case there aren't any
    final List<Unit> defendList = transport.create(1, germans);
    final List<Unit> defendSub = submarine.create(1, germans);
    defendList.addAll(defendSub);
    // fire the defending transport then the submarine (both miss)
    bridge.setRandomSource(new ScriptedRandomSource(new int[] { 1, 2 }));
    // Execute the battle and verify no hits
    final DiceRoll roll = DiceRoll.rollDice(defendList, true, germans, bridge, new MockBattle(balticSeaZone), "", TerritoryEffectHelper.getEffects(balticSeaZone), null);
    assertEquals(0, roll.getHits());
    // Get total number of units in Finland before the retreat
    final int preCountInt = karelia.getUnits().size();
    // Retreat from the Baltic
    ((MustFightBattle) inBalticSeaZone).externalRetreat(retreatingSeaUnits, northSea, false, bridge);
    // Get the total number of units that should be left
    final int postCountInt = preCountInt - retreatingLandSizeInt;
    // Compare the number of units in Finland to begin with the number after retreating
    assertEquals(defendingLandSizeInt, postCountInt);
}
Also used : IntegerMap(games.strategy.util.IntegerMap) ArrayList(java.util.ArrayList) ScriptedRandomSource(games.strategy.engine.random.ScriptedRandomSource) Unit(games.strategy.engine.data.Unit) UnitType(games.strategy.engine.data.UnitType) Route(games.strategy.engine.data.Route) Test(org.junit.jupiter.api.Test)

Example 38 with ScriptedRandomSource

use of games.strategy.engine.random.ScriptedRandomSource in project triplea by triplea-game.

the class MoveDelegateTest method testTransportCantLoadUnloadAfterBattle.

@Test
public void testTransportCantLoadUnloadAfterBattle() {
    bridge = super.getDelegateBridge(russians);
    bridge.setStepName("russianCombatMove");
    westEurope.setOwner(russians);
    // Attacking force
    final List<Unit> attackTrns = transport.create(1, russians);
    final List<Unit> attackList = bomber.create(2, russians);
    attackList.addAll(attackTrns);
    bridge.setRandomSource(new ScriptedRandomSource(new int[] { 1 }));
    final DiceRoll roll = DiceRoll.rollDice(attackList, false, russians, bridge, new MockBattle(balticSeaZone), "", TerritoryEffectHelper.getEffects(balticSeaZone), null);
    assertEquals(2, roll.getHits());
    bridge.setStepName("russianNonCombatMove");
    // Test the move
    final Collection<Unit> moveInf = infantry.create(2, russians);
    final Route route = new Route();
    route.setStart(karelia);
    route.add(balticSeaZone);
    route.add(westEurope);
    // Once loaded, shouldnt be able to unload
    final String results = delegate.move(moveInf, route);
    assertError(results);
}
Also used : ScriptedRandomSource(games.strategy.engine.random.ScriptedRandomSource) Unit(games.strategy.engine.data.Unit) Route(games.strategy.engine.data.Route) Test(org.junit.jupiter.api.Test)

Example 39 with ScriptedRandomSource

use of games.strategy.engine.random.ScriptedRandomSource in project triplea by triplea-game.

the class PacificTest method testNonJapanAttack.

@Test
public void testNonJapanAttack() {
    // this will get us to round 2
    bridge.setStepName("japaneseEndTurn");
    bridge.setStepName("japaneseBattle");
    // Defending US infantry hit on a 2 (0 base)
    final List<Unit> infantryUs = infantry.create(1, americans);
    final Collection<TerritoryEffect> territoryEffects = TerritoryEffectHelper.getEffects(queensland);
    bridge.setRandomSource(new ScriptedRandomSource(new int[] { 1 }));
    DiceRoll roll = DiceRoll.rollDice(infantryUs, true, americans, bridge, new MockBattle(queensland), "", territoryEffects, null);
    assertEquals(1, roll.getHits());
    // Defending US marines hit on a 2 (0 base)
    final List<Unit> marineUs = marine.create(1, americans);
    bridge.setRandomSource(new ScriptedRandomSource(new int[] { 1 }));
    roll = DiceRoll.rollDice(marineUs, true, americans, bridge, new MockBattle(queensland), "", territoryEffects, null);
    assertEquals(1, roll.getHits());
    // Chinese units
    // Defending Chinese infantry hit on a 2 (0 base)
    final List<Unit> infantryChina = infantry.create(1, chinese);
    bridge.setRandomSource(new ScriptedRandomSource(new int[] { 1 }));
    roll = DiceRoll.rollDice(infantryChina, true, chinese, bridge, new MockBattle(queensland), "", territoryEffects, null);
    assertEquals(1, roll.getHits());
}
Also used : TerritoryEffect(games.strategy.engine.data.TerritoryEffect) ScriptedRandomSource(games.strategy.engine.random.ScriptedRandomSource) Unit(games.strategy.engine.data.Unit) Test(org.junit.jupiter.api.Test)

Example 40 with ScriptedRandomSource

use of games.strategy.engine.random.ScriptedRandomSource in project triplea by triplea-game.

the class RevisedTest method testTechRolls.

@Test
public void testTechRolls() {
    // Set up the test
    final PlayerID germans = GameDataTestUtil.germans(gameData);
    final ITestDelegateBridge delegateBridge = getDelegateBridge(germans);
    delegateBridge.setStepName("germanTech");
    final TechnologyDelegate techDelegate = techDelegate(gameData);
    techDelegate.setDelegateBridgeAndPlayer(delegateBridge);
    techDelegate.start();
    final TechAttachment ta = TechAttachment.get(germans);
    // PlayerAttachment pa = PlayerAttachment.get(germans);
    final TechnologyFrontier rockets = new TechnologyFrontier("", gameData);
    rockets.addAdvance(TechAdvance.findAdvance(TechAdvance.TECH_PROPERTY_ROCKETS, gameData, null));
    final TechnologyFrontier jet = new TechnologyFrontier("", gameData);
    jet.addAdvance(TechAdvance.findAdvance(TechAdvance.TECH_PROPERTY_JET_POWER, gameData, null));
    // Check to make sure it was successful
    final int initPUs = germans.getResources().getQuantity("PUs");
    // Fail the roll
    delegateBridge.setRandomSource(new ScriptedRandomSource(new int[] { 3, 4 }));
    final TechResults roll = techDelegate.rollTech(2, rockets, 0, null);
    // Check to make sure it failed
    assertEquals(0, roll.getHits());
    final int midPUs = germans.getResources().getQuantity("PUs");
    assertEquals(initPUs - 10, midPUs);
    // Make a Successful roll
    delegateBridge.setRandomSource(new ScriptedRandomSource(new int[] { 5 }));
    final TechResults roll2 = techDelegate.rollTech(1, rockets, 0, null);
    // Check to make sure it succeeded
    assertEquals(1, roll2.getHits());
    final int finalPUs = germans.getResources().getQuantity("PUs");
    assertEquals(midPUs - 5, finalPUs);
    // Test the variable tech cost
    // Make a Successful roll
    ta.setTechCost("6");
    delegateBridge.setRandomSource(new ScriptedRandomSource(new int[] { 5 }));
    final TechResults roll3 = techDelegate.rollTech(1, jet, 0, null);
    // Check to make sure it succeeded
    assertEquals(1, roll3.getHits());
    final int variablePus = germans.getResources().getQuantity("PUs");
    assertEquals(finalPUs - 6, variablePus);
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) TechAttachment(games.strategy.triplea.attachments.TechAttachment) TechResults(games.strategy.triplea.delegate.dataObjects.TechResults) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) TechnologyFrontier(games.strategy.engine.data.TechnologyFrontier) ScriptedRandomSource(games.strategy.engine.random.ScriptedRandomSource) Test(org.junit.jupiter.api.Test)

Aggregations

ScriptedRandomSource (games.strategy.engine.random.ScriptedRandomSource)72 Test (org.junit.jupiter.api.Test)71 ITestDelegateBridge (games.strategy.engine.data.ITestDelegateBridge)55 Territory (games.strategy.engine.data.Territory)50 Unit (games.strategy.engine.data.Unit)48 PlayerID (games.strategy.engine.data.PlayerID)45 TripleAUnit (games.strategy.triplea.TripleAUnit)41 Route (games.strategy.engine.data.Route)28 UnitType (games.strategy.engine.data.UnitType)26 GameData (games.strategy.engine.data.GameData)13 TestMapGameData (games.strategy.triplea.xml.TestMapGameData)13 ArrayList (java.util.ArrayList)9 List (java.util.List)6 TerritoryEffect (games.strategy.engine.data.TerritoryEffect)5 UnitAttachment (games.strategy.triplea.attachments.UnitAttachment)5 CasualtyDetails (games.strategy.triplea.delegate.dataObjects.CasualtyDetails)5 InvocationOnMock (org.mockito.invocation.InvocationOnMock)5 IntegerMap (games.strategy.util.IntegerMap)4 Collection (java.util.Collection)4 Change (games.strategy.engine.data.Change)3