Search in sources :

Example 36 with ITestDelegateBridge

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

the class WW2V3Year42Test method testLingeringFightersAndALliedUnitsJoinBattle.

@Test
public void testLingeringFightersAndALliedUnitsJoinBattle() {
    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)));
    // add an allied carrier and a fighter
    addTo(sz5, carrier(gameData).create(1, italians(gameData)));
    addTo(sz5, fighter(gameData).create(1, germans(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
    // except the italian carrier
    final MustFightBattle mfb = (MustFightBattle) MoveDelegate.getBattleTracker(gameData).getPendingBattle(sz5, false, null);
    assertEquals(6, 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 37 with ITestDelegateBridge

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

the class WW2V3Year42Test method testLingeringSeaUnitsCanMoveAwayFromBattle.

@Test
public void testLingeringSeaUnitsCanMoveAwayFromBattle() {
    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));
    // move the transport away
    move(sz5.getUnits().getMatches(Matches.unitIsTransport()), new Route(sz5, sz6));
    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(4, 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 38 with ITestDelegateBridge

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

the class MustFightBattleTest method testFightWithIsSuicideOnHit.

@Test
public void testFightWithIsSuicideOnHit() throws Exception {
    final GameData twwGameData = TestMapGameData.TWW.getGameData();
    // Create battle with 1 cruiser attacking 1 mine
    final PlayerID usa = GameDataTestUtil.usa(twwGameData);
    final PlayerID germany = GameDataTestUtil.germany(twwGameData);
    final Territory sz33 = territory("33 Sea Zone", twwGameData);
    addTo(sz33, GameDataTestUtil.americanCruiser(twwGameData).create(1, usa));
    final Territory sz40 = territory("40 Sea Zone", twwGameData);
    addTo(sz40, GameDataTestUtil.germanMine(twwGameData).create(1, germany));
    final ITestDelegateBridge bridge = GameDataTestUtil.getDelegateBridge(usa, twwGameData);
    bridge.setStepName("CombatMove");
    moveDelegate(twwGameData).setDelegateBridgeAndPlayer(bridge);
    moveDelegate(twwGameData).start();
    move(sz33.getUnits().getUnits(), new Route(sz33, sz40));
    moveDelegate(twwGameData).end();
    final MustFightBattle battle = (MustFightBattle) AbstractMoveDelegate.getBattleTracker(twwGameData).getPendingBattle(sz40, false, null);
    bridge.setRemote(dummyPlayer);
    // Set first roll to hit (mine AA) and check that both units are killed
    final ScriptedRandomSource randomSource = new ScriptedRandomSource(0, ScriptedRandomSource.ERROR);
    bridge.setRandomSource(randomSource);
    battle.fight(bridge);
    assertEquals(1, randomSource.getTotalRolled());
    assertEquals(0, sz40.getUnits().size());
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) GameData(games.strategy.engine.data.GameData) TestMapGameData(games.strategy.triplea.xml.TestMapGameData) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) ScriptedRandomSource(games.strategy.engine.random.ScriptedRandomSource) Route(games.strategy.engine.data.Route) Test(org.junit.jupiter.api.Test)

Example 39 with ITestDelegateBridge

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

the class RevisedTest method testTransportsUnloadingToMultipleTerritoriesDie.

@Test
public void testTransportsUnloadingToMultipleTerritoriesDie() {
    // two transports enter a battle, but drop off
    // their units to two allied territories before
    // the begin the battle
    // the units they drop off should die with the transports
    final PlayerID germans = germans(gameData);
    final PlayerID british = british(gameData);
    final Territory sz6 = territory("6 Sea Zone", gameData);
    final Territory sz5 = territory("5 Sea Zone", gameData);
    final Territory germany = territory("Germany", gameData);
    final Territory norway = territory("Norway", gameData);
    final Territory we = territory("Western Europe", gameData);
    final Territory uk = territory("United Kingdom", gameData);
    addTo(sz6, destroyer(gameData).create(2, british));
    addTo(sz5, transport(gameData).create(3, germans));
    addTo(germany, armour(gameData).create(3, germans));
    final ITestDelegateBridge bridge = getDelegateBridge(germans(gameData));
    bridge.setStepName("CombatMove");
    bridge.setRemote(dummyPlayer);
    moveDelegate(gameData).setDelegateBridgeAndPlayer(bridge);
    moveDelegate(gameData).start();
    // load two transports, 1 tank each
    load(germany.getUnits().getMatches(Matches.unitCanBlitz()).subList(0, 1), new Route(germany, sz5));
    load(germany.getUnits().getMatches(Matches.unitCanBlitz()).subList(0, 1), new Route(germany, sz5));
    load(germany.getUnits().getMatches(Matches.unitCanBlitz()).subList(0, 1), new Route(germany, sz5));
    // attack sz 6
    move(sz5.getUnits().getMatches(Matches.unitCanBlitz().or(Matches.unitIsTransport())), new Route(sz5, sz6));
    // unload transports, 1 each to a different country
    // this move is illegal now
    assertMoveError(sz6.getUnits().getMatches(Matches.unitCanBlitz()).subList(0, 1), new Route(sz6, norway));
    // this move is illegal now
    assertMoveError(sz6.getUnits().getMatches(Matches.unitCanBlitz()).subList(0, 1), new Route(sz6, we));
    move(sz6.getUnits().getMatches(Matches.unitCanBlitz()).subList(0, 1), new Route(sz6, uk));
    // fight the battle
    moveDelegate(gameData).end();
    final MustFightBattle battle = (MustFightBattle) AbstractMoveDelegate.getBattleTracker(gameData).getPendingBattle(sz6, false, null);
    // everything hits, this will kill both transports
    bridge.setRandomSource(new ScriptedRandomSource(0));
    battle.fight(bridge);
    // the armour should have died
    assertEquals(0, norway.getUnits().countMatches(Matches.unitCanBlitz()));
    assertEquals(2, we.getUnits().countMatches(Matches.unitCanBlitz()));
    assertEquals(0, uk.getUnits().countMatches(Matches.unitIsOwnedBy(germans)));
}
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) Route(games.strategy.engine.data.Route) Test(org.junit.jupiter.api.Test)

Example 40 with ITestDelegateBridge

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

the class RevisedTest method testTransportAttack.

@Test
public void testTransportAttack() {
    final Territory sz14 = gameData.getMap().getTerritory("14 Sea Zone");
    final Territory sz13 = gameData.getMap().getTerritory("13 Sea Zone");
    final PlayerID germans = GameDataTestUtil.germans(gameData);
    final MoveDelegate moveDelegate = (MoveDelegate) gameData.getDelegateList().getDelegate("move");
    final ITestDelegateBridge bridge = getDelegateBridge(germans);
    bridge.setStepName("CombatMove");
    moveDelegate.setDelegateBridgeAndPlayer(bridge);
    moveDelegate.start();
    final Route sz14To13 = new Route();
    sz14To13.setStart(sz14);
    sz14To13.add(sz13);
    final List<Unit> transports = sz14.getUnits().getMatches(Matches.unitIsTransport());
    assertEquals(1, transports.size());
    final String error = moveDelegate.move(transports, sz14To13);
    assertNull(error, error);
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) 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)

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