Search in sources :

Example 51 with Route

use of games.strategy.engine.data.Route 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 52 with Route

use of games.strategy.engine.data.Route 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 53 with Route

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

the class PacificTest method testCanLand1AirfieldStart.

@Test
public void testCanLand1AirfieldStart() {
    bridge.setStepName("americanCombatMove");
    final Route route = new Route();
    route.setStart(unitedStates);
    route.add(sz5);
    route.add(sz7);
    route.add(sz8);
    route.add(sz20);
    route.add(midway);
    final IntegerMap<UnitType> map = new IntegerMap<>();
    map.put(fighter, 1);
    final String results = delegate.move(GameDataTestUtil.getUnits(map, route.getStart()), route);
    assertValid(results);
// assertError( results);
}
Also used : IntegerMap(games.strategy.util.IntegerMap) UnitType(games.strategy.engine.data.UnitType) Route(games.strategy.engine.data.Route) Test(org.junit.jupiter.api.Test)

Example 54 with Route

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

the class PacificTest method testCanLand1AirfieldEnd.

@Test
public void testCanLand1AirfieldEnd() {
    bridge.setStepName("americanCombatMove");
    final Route route = new Route();
    route.setStart(unitedStates);
    route.add(sz5);
    route.add(sz7);
    route.add(sz8);
    route.add(sz20);
    route.add(midway);
    final IntegerMap<UnitType> map = new IntegerMap<>();
    map.put(fighter, 1);
    final String results = delegate.move(GameDataTestUtil.getUnits(map, route.getStart()), route);
    assertValid(results);
}
Also used : IntegerMap(games.strategy.util.IntegerMap) UnitType(games.strategy.engine.data.UnitType) Route(games.strategy.engine.data.Route) Test(org.junit.jupiter.api.Test)

Example 55 with Route

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

the class PacificTest method testCanLand2Airfields.

@Test
public void testCanLand2Airfields() {
    bridge.setStepName("americanCombatMove");
    final Route route = new Route();
    route.setStart(unitedStates);
    route.add(sz5);
    route.add(sz4);
    route.add(sz10);
    route.add(sz16);
    route.add(sz27);
    route.add(newBritain);
    final IntegerMap<UnitType> map = new IntegerMap<>();
    map.put(fighter, 1);
    final String results = delegate.move(GameDataTestUtil.getUnits(map, route.getStart()), route);
    assertValid(results);
}
Also used : IntegerMap(games.strategy.util.IntegerMap) UnitType(games.strategy.engine.data.UnitType) Route(games.strategy.engine.data.Route) Test(org.junit.jupiter.api.Test)

Aggregations

Route (games.strategy.engine.data.Route)200 Test (org.junit.jupiter.api.Test)148 Territory (games.strategy.engine.data.Territory)132 Unit (games.strategy.engine.data.Unit)84 UnitType (games.strategy.engine.data.UnitType)83 ITestDelegateBridge (games.strategy.engine.data.ITestDelegateBridge)77 TripleAUnit (games.strategy.triplea.TripleAUnit)70 IntegerMap (games.strategy.util.IntegerMap)69 PlayerID (games.strategy.engine.data.PlayerID)64 ArrayList (java.util.ArrayList)44 GameData (games.strategy.engine.data.GameData)29 ScriptedRandomSource (games.strategy.engine.random.ScriptedRandomSource)26 HashSet (java.util.HashSet)21 HashMap (java.util.HashMap)20 Collection (java.util.Collection)15 List (java.util.List)12 Set (java.util.Set)12 UnitAttachment (games.strategy.triplea.attachments.UnitAttachment)11 Change (games.strategy.engine.data.Change)10 MoveValidationResult (games.strategy.triplea.delegate.dataObjects.MoveValidationResult)10