Search in sources :

Example 26 with ITestDelegateBridge

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

the class WW2V3Year41Test method testCantTransportParatroopersWithBombersThatMovedPreviously.

@Test
public void testCantTransportParatroopersWithBombersThatMovedPreviously() {
    // make sure bombers can't move then pick up paratroopers
    final PlayerID germans = germans(gameData);
    final Territory germany = territory("Germany", gameData);
    final Territory bulgaria = territory("Bulgaria Romania", gameData);
    final Territory poland = territory("Poland", gameData);
    final Territory ukraine = territory("Ukraine", gameData);
    final ITestDelegateBridge bridge = getDelegateBridge(germans);
    bridge.setStepName("CombatMove");
    moveDelegate(gameData).setDelegateBridgeAndPlayer(bridge);
    moveDelegate(gameData).start();
    TechAttachment.get(germans).setParatroopers("true");
    // Move the bomber first
    final List<Unit> bomber = germany.getUnits().getMatches(Matches.unitIsAirTransport());
    move(bomber, new Route(germany, poland));
    // Pick up a paratrooper
    final List<Unit> bomberAndParatroop = new ArrayList<>(bomber);
    bomberAndParatroop.addAll(poland.getUnits().getUnits(GameDataTestUtil.infantry(gameData), 1));
    // move them
    final String error = moveDelegate(gameData).move(bomberAndParatroop, new Route(poland, bulgaria, ukraine));
    assertError(error);
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) ArrayList(java.util.ArrayList) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) TripleAUnit(games.strategy.triplea.TripleAUnit) Unit(games.strategy.engine.data.Unit) Route(games.strategy.engine.data.Route) Test(org.junit.jupiter.api.Test)

Example 27 with ITestDelegateBridge

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

the class WW2V3Year41Test method testDefendingTrasnportsAutoKilled.

@Test
public void testDefendingTrasnportsAutoKilled() {
    final Territory sz13 = gameData.getMap().getTerritory("13 Sea Zone");
    final Territory sz12 = gameData.getMap().getTerritory("12 Sea Zone");
    final PlayerID british = GameDataTestUtil.british(gameData);
    final MoveDelegate moveDelegate = moveDelegate(gameData);
    final ITestDelegateBridge bridge = getDelegateBridge(british);
    bridge.setStepName("CombatMove");
    moveDelegate.setDelegateBridgeAndPlayer(bridge);
    moveDelegate.start();
    final Route sz12To13 = new Route();
    sz12To13.setStart(sz12);
    sz12To13.add(sz13);
    final String error = moveDelegate.move(sz12.getUnits().getUnits(), sz12To13);
    assertEquals(null, error);
    assertEquals(3, sz13.getUnits().size());
    moveDelegate.end();
    // the transport was not removed automatically
    assertEquals(3, sz13.getUnits().size());
    final BattleDelegate bd = battleDelegate(gameData);
    assertFalse(bd.getBattleTracker().getPendingBattleSites(false).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)

Example 28 with ITestDelegateBridge

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

the class WW2V3Year41Test method testParatroopersMoveTwice.

@Test
public void testParatroopersMoveTwice() {
    // After a battle move to put a bomber + infantry (paratroop) in a first enemy
    // territory, you can make a new move (in the same battle move round) to put
    // bomber+ infantry in a more internal enemy territory.
    final PlayerID germans = germans(gameData);
    final Territory germany = territory("Germany", gameData);
    final Territory poland = territory("Poland", gameData);
    final Territory eastPoland = territory("East Poland", gameData);
    final Territory beloRussia = territory("Belorussia", gameData);
    final ITestDelegateBridge bridge = getDelegateBridge(germans);
    bridge.setStepName("CombatMove");
    moveDelegate(gameData).setDelegateBridgeAndPlayer(bridge);
    moveDelegate(gameData).start();
    TechAttachment.get(germans).setParatroopers("true");
    List<Unit> paratroopers = germany.getUnits().getMatches(Matches.unitIsAirTransportable());
    paratroopers = paratroopers.subList(0, 1);
    final List<Unit> bomberAndParatroop = new ArrayList<>(paratroopers);
    bomberAndParatroop.addAll(germany.getUnits().getMatches(Matches.unitIsAirTransport()));
    final Route route = new Route(germany, poland, eastPoland);
    final List<Unit> airTransports = germany.getUnits().getMatches(Matches.unitIsAirTransport());
    for (final Unit airTransport : airTransports) {
        for (final Unit unit : paratroopers) {
            final Change change = TransportTracker.loadTransportChange((TripleAUnit) airTransport, unit);
            bridge.addChange(change);
        }
    }
    // move the units to east poland
    // airTransports
    String error = moveDelegate(gameData).move(bomberAndParatroop, route);
    assertValid(error);
    // try to move them further, this should fail
    error = moveDelegate(gameData).move(bomberAndParatroop, new Route(eastPoland, beloRussia));
    assertError(error);
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) ArrayList(java.util.ArrayList) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) Change(games.strategy.engine.data.Change) TripleAUnit(games.strategy.triplea.TripleAUnit) Unit(games.strategy.engine.data.Unit) Route(games.strategy.engine.data.Route) Test(org.junit.jupiter.api.Test)

Example 29 with ITestDelegateBridge

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

the class WW2V3Year41Test method testMechInfUnitAlreadyMovedSimple.

@Test
public void testMechInfUnitAlreadyMovedSimple() {
    final PlayerID germans = germans(gameData);
    final Territory france = territory("France", gameData);
    final Territory germany = territory("Germany", gameData);
    TechAttachment.get(germans).setMechanizedInfantry("true");
    final ITestDelegateBridge bridge = getDelegateBridge(germans);
    bridge.setStepName("CombatMove");
    moveDelegate(gameData).setDelegateBridgeAndPlayer(bridge);
    moveDelegate(gameData).start();
    // get rid of the infantry in france
    removeFrom(france, france.getUnits().getMatches(Matches.unitIsLandTransportable()));
    // move an infantry from germany to france
    move(germany.getUnits().getMatches(Matches.unitIsLandTransportable()).subList(0, 1), new Route(germany, france));
    // try to move all the units in france, the infantry should not be able to move
    final Route r = new Route(france, germany);
    final String error = moveDelegate(gameData).move(france.getUnits().getUnits(), r);
    assertFalse(error == null);
}
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 30 with ITestDelegateBridge

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

the class WW2V3Year41Test method testLoadThroughSubs.

@Test
public void testLoadThroughSubs() {
    final ITestDelegateBridge bridge = getDelegateBridge(british(gameData));
    bridge.setStepName("britishNonCombatMove");
    final MoveDelegate moveDelegate = moveDelegate(gameData);
    moveDelegate.setDelegateBridgeAndPlayer(bridge);
    moveDelegate.start();
    final Territory sz8 = territory("8 Sea Zone", gameData);
    final Territory sz7 = territory("7 Sea Zone", gameData);
    final Territory sz6 = territory("6 Sea Zone", gameData);
    final Territory uk = territory("United Kingdom", gameData);
    // add a transport
    addTo(sz8, transport(gameData).create(1, british(gameData)));
    // move the transport where to the sub is
    assertValid(moveDelegate.move(sz8.getUnits().getUnits(), new Route(sz8, sz7)));
    // load the transport
    load(uk.getUnits().getMatches(Matches.unitIsLandTransportable()), new Route(uk, sz7));
    // move the transport out
    assertValid(moveDelegate.move(sz7.getUnits().getMatches(Matches.unitOwnedBy(british(gameData))), new Route(sz7, sz6)));
}
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)

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