Search in sources :

Example 11 with ITestDelegateBridge

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

the class WW2V3Year41Test method testDefencelessTransportsDie.

@Test
public void testDefencelessTransportsDie() {
    final PlayerID british = british(gameData);
    final ITestDelegateBridge bridge = getDelegateBridge(british);
    bridge.setStepName("CombatMove");
    moveDelegate(gameData).setDelegateBridgeAndPlayer(bridge);
    moveDelegate(gameData).start();
    final Territory uk = territory("United Kingdom", gameData);
    final Territory sz5 = territory("5 Sea Zone", gameData);
    // remove the sub
    removeFrom(sz5, sz5.getUnits().getMatches(Matches.unitIsSub()));
    when(dummyPlayer.retreatQuery(any(), anyBoolean(), any(), any(), any())).thenAnswer(new Answer<Territory>() {

        @Override
        public Territory answer(final InvocationOnMock invocation) throws Throwable {
            throw new IllegalStateException("Should not be asked to retreat:" + invocation.getArgument(4));
        }
    });
    bridge.setRemote(dummyPlayer);
    move(uk.getUnits().getMatches(Matches.unitIsAir()), gameData.getMap().getRoute(uk, sz5));
    // move units for amphib assault
    moveDelegate(gameData).end();
    bridge.setStepName("Combat");
    // cook the dice so that 1 british fighters hits, and nothing else
    // this will leave 1 transport alone in the sea zone
    bridge.setRandomSource(new ScriptedRandomSource(1, 5, 5, 5, 5, 5, 5, 5, 5));
    battleDelegate(gameData).setDelegateBridgeAndPlayer(bridge);
    battleDelegate(gameData).start();
    // make sure the transports died
    assertTrue(sz5.getUnits().getMatches(Matches.unitIsOwnedBy(germans(gameData))).isEmpty());
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) ScriptedRandomSource(games.strategy.engine.random.ScriptedRandomSource) Test(org.junit.jupiter.api.Test)

Example 12 with ITestDelegateBridge

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

the class WW2V3Year41Test method testLoadedTransportAttackKillsLoadedUnits.

@Test
public void testLoadedTransportAttackKillsLoadedUnits() {
    final PlayerID british = british(gameData);
    final MoveDelegate moveDelegate = moveDelegate(gameData);
    final ITestDelegateBridge bridge = getDelegateBridge(british);
    bridge.setStepName("britishCombatMove");
    when(dummyPlayer.selectAttackSubs(any())).thenReturn(true);
    bridge.setRemote(dummyPlayer);
    moveDelegate.setDelegateBridgeAndPlayer(bridge);
    moveDelegate.start();
    final Territory sz9 = territory("9 Sea Zone", gameData);
    final Territory sz7 = territory("7 Sea Zone", gameData);
    final Territory uk = territory("United Kingdom", gameData);
    final Route sz9ToSz7 = new Route(sz9, territory("8 Sea Zone", gameData), sz7);
    // move the transport to attack, this is suicide but valid
    final List<Unit> transports = sz9.getUnits().getMatches(Matches.unitIsTransport());
    move(transports, sz9ToSz7);
    // load the transport
    load(uk.getUnits().getMatches(Matches.unitIsLandTransportable()), new Route(uk, sz7));
    moveDelegate(gameData).end();
    final ScriptedRandomSource randomSource = new ScriptedRandomSource(new int[] { 0, 1 });
    bridge.setRandomSource(randomSource);
    bridge.setStepName("britishBattle");
    final BattleDelegate battleDelegate = battleDelegate(gameData);
    battleDelegate.setDelegateBridgeAndPlayer(bridge);
    assertEquals(2, TransportTracker.transporting(transports.get(0)).size());
    battleDelegate.start();
    // battle already fought
    // make sure the infantry die with the transport
    assertTrue(sz7.getUnits().getMatches(Matches.unitOwnedBy(british)).isEmpty(), sz7.getUnits().toString());
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) ScriptedRandomSource(games.strategy.engine.random.ScriptedRandomSource) TripleAUnit(games.strategy.triplea.TripleAUnit) Unit(games.strategy.engine.data.Unit) Route(games.strategy.engine.data.Route) Test(org.junit.jupiter.api.Test)

Example 13 with ITestDelegateBridge

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

the class WW2V3Year41Test method testMoveUnitsThroughSubs.

@Test
public void testMoveUnitsThroughSubs() {
    final ITestDelegateBridge bridge = getDelegateBridge(british(gameData));
    bridge.setStepName("britishNonCombatMove");
    moveDelegate(gameData).setDelegateBridgeAndPlayer(bridge);
    moveDelegate(gameData).start();
    final Territory sz6 = territory("6 Sea Zone", gameData);
    final Route route = new Route(sz6, territory("7 Sea Zone", gameData), territory("8 Sea Zone", gameData));
    final String error = moveDelegate(gameData).move(sz6.getUnits().getUnits(), route);
    assertNull(error, error);
}
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 14 with ITestDelegateBridge

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

the class WW2V3Year41Test method testFighterCantHoverWithNoCarrierToPlace.

@Test
public void testFighterCantHoverWithNoCarrierToPlace() {
    // start the move phase
    final ITestDelegateBridge bridge = getDelegateBridge(germans(gameData));
    bridge.setStepName("CombatMove");
    moveDelegate(gameData).setDelegateBridgeAndPlayer(bridge);
    moveDelegate(gameData).start();
    bridge.setRemote(dummyPlayer);
    // the fighter should not be able to move and hover in the sea zone
    // since their are no carriers to place
    // 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));
    final String error = moveDelegate(gameData).move(neEurope.getUnits().getMatches(Matches.unitIsAir()), route);
    assertNotNull(error);
}
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 15 with ITestDelegateBridge

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

the class WW2V3Year41Test method testInfantryLoadOnlyTransports.

@Test
public void testInfantryLoadOnlyTransports() {
    final Territory gibraltar = territory("Gibraltar", gameData);
    // add a tank to gibralter
    final PlayerID british = british(gameData);
    addTo(gibraltar, infantry(gameData).create(1, british));
    final MoveDelegate moveDelegate = moveDelegate(gameData);
    final ITestDelegateBridge bridge = getDelegateBridge(british);
    bridge.setStepName("britishCombatMove");
    moveDelegate.setDelegateBridgeAndPlayer(bridge);
    moveDelegate.start();
    bridge.setRemote(dummyPlayer);
    final Territory sz9 = territory("9 Sea Zone", gameData);
    final Territory sz13 = territory("13 Sea Zone", gameData);
    final Route sz9ToSz13 = new Route(sz9, territory("12 Sea Zone", gameData), sz13);
    // move the transport to attack, this is suicide but valid
    move(sz9.getUnits().getMatches(Matches.unitIsTransport()), sz9ToSz13);
    // load the transport
    load(gibraltar.getUnits().getUnits(), new Route(gibraltar, sz13));
    moveDelegate.end();
    bridge.setStepName("britishBattle");
    final BattleDelegate battleDelegate = battleDelegate(gameData);
    battleDelegate.setDelegateBridgeAndPlayer(bridge);
    battleDelegate.start();
    assertTrue(battleDelegate.getBattles().isEmpty());
}
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)

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