Search in sources :

Example 31 with ITestDelegateBridge

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

the class WW2V3Year41Test method testAttackDestroyerAndSubsAgainstSubAndDestroyer.

@Test
public void testAttackDestroyerAndSubsAgainstSubAndDestroyer() {
    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 and 1 destroyer attack 1 sub and 1 destroyer
    // no sneak attacks
    addTo(from, submarine(gameData).create(1, british(gameData)));
    addTo(from, destroyer(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(attacker + SUBS_FIRE, defender + SELECT_SUB_CASUALTIES, attacker + FIRE, defender + SELECT_CASUALTIES, defender + SUBS_FIRE, attacker + SELECT_SUB_CASUALTIES, defender + FIRE, attacker + SELECT_CASUALTIES, REMOVE_CASUALTIES, attacker + ATTACKER_WITHDRAW).toString(), steps.toString());
    when(dummyPlayer.selectCasualties(any(), any(), anyInt(), any(), any(), any(), any(), any(), any(), anyBoolean(), any(), any(), any(), any(), anyBoolean())).thenAnswer(new Answer<CasualtyDetails>() {

        @Override
        public CasualtyDetails answer(final InvocationOnMock invocation) {
            final Collection<Unit> selectFrom = invocation.getArgument(0);
            return new CasualtyDetails(Arrays.asList(selectFrom.iterator().next()), new ArrayList<>(), false);
        }
    });
    bridge.setRemote(dummyPlayer);
    // attacking subs sneak attack and hit
    // no chance to return fire
    final ScriptedRandomSource randomSource = new ScriptedRandomSource(0, 0, 0, 0, ScriptedRandomSource.ERROR);
    bridge.setRandomSource(randomSource);
    battle.fight(bridge);
    assertEquals(4, randomSource.getTotalRolled());
    assertEquals(0, attacked.getUnits().size());
}
Also used : Territory(games.strategy.engine.data.Territory) ArrayList(java.util.ArrayList) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) ScriptedRandomSource(games.strategy.engine.random.ScriptedRandomSource) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Collection(java.util.Collection) CasualtyDetails(games.strategy.triplea.delegate.dataObjects.CasualtyDetails) Route(games.strategy.engine.data.Route) Test(org.junit.jupiter.api.Test)

Example 32 with ITestDelegateBridge

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

the class WW2V3Year41Test method testTechTokens.

@Test
public void testTechTokens() {
    // 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 TechnologyFrontier mech = new TechnologyFrontier("", gameData);
    mech.addAdvance(TechAdvance.findAdvance(TechAdvance.TECH_PROPERTY_MECHANIZED_INFANTRY, gameData, null));
    // Add tech token
    gameData.performChange(ChangeFactory.changeResourcesChange(germans, gameData.getResourceList().getResource(Constants.TECH_TOKENS), 1));
    // Check to make sure it was successful
    final int initTokens = germans.getResources().getQuantity("techTokens");
    assertEquals(1, initTokens);
    // Fail the roll
    delegateBridge.setRandomSource(new ScriptedRandomSource(new int[] { 3 }));
    final TechResults roll = techDelegate.rollTech(1, mech, 0, null);
    // Check to make sure it failed
    assertEquals(0, roll.getHits());
    final int midTokens = germans.getResources().getQuantity("techTokens");
    assertEquals(1, midTokens);
    // Make a Successful roll
    delegateBridge.setRandomSource(new ScriptedRandomSource(new int[] { 5 }));
    final TechResults roll2 = techDelegate.rollTech(1, mech, 0, null);
    // Check to make sure it succeeded and all tokens were removed
    assertEquals(1, roll2.getHits());
    final int finalTokens = germans.getResources().getQuantity("techTokens");
    assertEquals(0, finalTokens);
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) 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)

Example 33 with ITestDelegateBridge

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

the class WW2V3Year41Test method testFighterLandsWhereCarrierCanBePlaced.

@Test
public void testFighterLandsWhereCarrierCanBePlaced() {
    final PlayerID germans = germans(gameData);
    // germans have 1 carrier to place
    addTo(germans, carrier(gameData).create(1, germans), gameData);
    // start the move phase
    final ITestDelegateBridge bridge = getDelegateBridge(germans);
    bridge.setStepName("CombatMove");
    moveDelegate(gameData).setDelegateBridgeAndPlayer(bridge);
    moveDelegate(gameData).start();
    bridge.setRemote(dummyPlayer);
    // the fighter should be able to move and hover in the sea zone
    // the fighter has no movement left
    final Territory neEurope = territory("Northwestern Europe", gameData);
    final Route route = new Route(neEurope, territory("Germany", gameData), territory("Poland", gameData), territory("Baltic States", gameData), territory("5 Sea Zone", gameData));
    // the fighter should be able to move, and hover in the sea zone until the carrier is placed
    move(neEurope.getUnits().getMatches(Matches.unitIsAir()), route);
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) Route(games.strategy.engine.data.Route) Test(org.junit.jupiter.api.Test)

Example 34 with ITestDelegateBridge

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

the class WW2V3Year42Test method testLingeringSeaUnitsJoinBattle.

@Test
public void testLingeringSeaUnitsJoinBattle() {
    final Territory sz5 = territory("5 Sea Zone", gameData);
    final Territory sz6 = territory("6 Sea Zone", gameData);
    final Territory sz7 = territory("7 Sea Zone", gameData);
    // add a russian battlship
    addTo(sz5, battleship(gameData).create(1, russians(gameData)));
    final ITestDelegateBridge bridge = getDelegateBridge(germans(gameData));
    bridge.setStepName("CombatMove");
    moveDelegate(gameData).setDelegateBridgeAndPlayer(bridge);
    moveDelegate(gameData).start();
    // attack with a german sub
    move(sz7.getUnits().getUnits(), new Route(sz7, sz6, sz5));
    moveDelegate(gameData).end();
    // adding of lingering units was moved from end of combat-move phase, to start of battle phase
    battleDelegate(gameData).setDelegateBridgeAndPlayer(bridge);
    BattleDelegate.doInitialize(battleDelegate(gameData).getBattleTracker(), bridge);
    // all units in sz5 should be involved in the battle
    final MustFightBattle mfb = (MustFightBattle) MoveDelegate.getBattleTracker(gameData).getPendingBattle(sz5, false, null);
    assertEquals(5, mfb.getAttackingUnits().size());
}
Also used : Territory(games.strategy.engine.data.Territory) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) Route(games.strategy.engine.data.Route) Test(org.junit.jupiter.api.Test)

Example 35 with ITestDelegateBridge

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

the class WW2V3Year42Test method testBombAndAttackEmptyTerritory.

@Test
public void testBombAndAttackEmptyTerritory() {
    final Territory karrelia = territory("Karelia S.S.R.", gameData);
    final Territory baltic = territory("Baltic States", gameData);
    final Territory sz5 = territory("5 Sea Zone", gameData);
    final Territory germany = territory("Germany", gameData);
    final PlayerID germans = germans(gameData);
    final MoveDelegate moveDelegate = (MoveDelegate) gameData.getDelegateList().getDelegate("move");
    final ITestDelegateBridge bridge = getDelegateBridge(germans);
    bridge.setStepName("CombatMove");
    moveDelegate.setDelegateBridgeAndPlayer(bridge);
    moveDelegate.start();
    final ITripleAPlayer dummyPlayer = mock(ITripleAPlayer.class);
    when(dummyPlayer.shouldBomberBomb(any())).thenReturn(true);
    bridge.setRemote(dummyPlayer);
    // remove the russian units
    removeFrom(karrelia, karrelia.getUnits().getMatches(Matches.unitCanBeDamaged().negate()));
    // move the bomber to attack
    move(germany.getUnits().getMatches(Matches.unitIsStrategicBomber()), new Route(germany, sz5, karrelia));
    // move an infantry to invade
    move(baltic.getUnits().getMatches(Matches.unitIsLandTransportable()), new Route(baltic, karrelia));
    final BattleTracker battleTracker = MoveDelegate.getBattleTracker(gameData);
    // we should have a pending land battle, and a pending bombing raid
    assertNotNull(battleTracker.getPendingBattle(karrelia, false, null));
    assertNotNull(battleTracker.getPendingBattle(karrelia, true, null));
    // the territory should not be conquered
    assertEquals(karrelia.getOwner(), russians(gameData));
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) ITripleAPlayer(games.strategy.triplea.player.ITripleAPlayer) Route(games.strategy.engine.data.Route) Test(org.junit.jupiter.api.Test)

Aggregations

ITestDelegateBridge (games.strategy.engine.data.ITestDelegateBridge)128 Test (org.junit.jupiter.api.Test)127 Territory (games.strategy.engine.data.Territory)119 PlayerID (games.strategy.engine.data.PlayerID)94 Route (games.strategy.engine.data.Route)80 TripleAUnit (games.strategy.triplea.TripleAUnit)60 Unit (games.strategy.engine.data.Unit)58 ScriptedRandomSource (games.strategy.engine.random.ScriptedRandomSource)56 UnitType (games.strategy.engine.data.UnitType)40 Change (games.strategy.engine.data.Change)12 ArrayList (java.util.ArrayList)11 UnitAttachment (games.strategy.triplea.attachments.UnitAttachment)8 GameData (games.strategy.engine.data.GameData)5 GameDataTestUtil.bidPlaceDelegate (games.strategy.triplea.delegate.GameDataTestUtil.bidPlaceDelegate)5 ITripleAPlayer (games.strategy.triplea.player.ITripleAPlayer)5 TestMapGameData (games.strategy.triplea.xml.TestMapGameData)5 IntegerMap (games.strategy.util.IntegerMap)5 List (java.util.List)5 TerritoryEffect (games.strategy.engine.data.TerritoryEffect)4 ChangeFactory (games.strategy.engine.data.changefactory.ChangeFactory)4