Search in sources :

Example 86 with Route

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

the class MoveDelegateTest method testAirCanLandOnLand.

@Test
public void testAirCanLandOnLand() {
    final Route route = new Route();
    route.setStart(egypt);
    route.add(eastMediteranean);
    route.add(blackSea);
    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 87 with Route

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

the class MoveDelegateTest method testLandMoveToWaterWithTransportsFull.

@Test
public void testLandMoveToWaterWithTransportsFull() {
    final IntegerMap<UnitType> map = new IntegerMap<>();
    map.put(armour, 1);
    map.put(infantry, 2);
    final Route route = new Route();
    route.setStart(equatorialAfrica);
    // exast movement to force landing
    route.add(congoSeaZone);
    assertEquals(4, equatorialAfrica.getUnits().size());
    assertEquals(11, congoSeaZone.getUnits().size());
    final String results = delegate.move(GameDataTestUtil.getUnits(map, route.getStart()), route);
    assertError(results);
    assertEquals(4, equatorialAfrica.getUnits().size());
    assertEquals(11, congoSeaZone.getUnits().size());
}
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 88 with Route

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

the class MoveDelegateTest method testUnload.

@Test
public void testUnload() {
    final IntegerMap<UnitType> map = new IntegerMap<>();
    map.put(infantry, 2);
    final Route route = new Route();
    route.setStart(congoSeaZone);
    route.add(equatorialAfrica);
    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 89 with Route

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

the class MoveDelegateTest method testTakeOverAfterOverFlight.

@Test
public void testTakeOverAfterOverFlight() {
    // this was causing an exception
    Route route = new Route();
    route.setStart(egypt);
    route.add(libya);
    IntegerMap<UnitType> map = new IntegerMap<>();
    map.put(bomber, 1);
    String results = delegate.move(GameDataTestUtil.getUnits(map, route.getStart()), route);
    assertValid(results);
    route = new Route();
    route.setStart(libya);
    route.add(algeria);
    // planes cannot leave a battle zone, but the territory was empty so no battle occurred
    map = new IntegerMap<>();
    map.put(bomber, 1);
    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 90 with Route

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

the class MoveDelegateTest method testReloadTransportAfterRetreatAllied.

@Test
public void testReloadTransportAfterRetreatAllied() {
    bridge = super.getDelegateBridge(british);
    bridge.setStepName("britishCombatMove");
    Route route = new Route();
    route.setStart(northSea);
    route.add(balticSeaZone);
    IntegerMap<UnitType> map = new IntegerMap<>();
    map.put(transport, 1);
    map.put(infantry, 2);
    // Move from the NorthSea to the BalticSea and validate the move
    String results = delegate.move(GameDataTestUtil.getUnits(map, route.getStart()), route);
    assertValid(results);
    // Unload transports into Finland and validate
    route = new Route();
    route.setStart(balticSeaZone);
    route.add(karelia);
    map = new IntegerMap<>();
    map.put(infantry, 2);
    results = delegate.move(GameDataTestUtil.getUnits(map, route.getStart()), route);
    assertValid(results);
    // Get the attacking sea units that will retreat
    final List<Unit> retreatingSeaUnits = new ArrayList<>();
    retreatingSeaUnits.addAll(balticSeaZone.getUnits().getMatches(Matches.enemyUnit(germans, gameData)));
    // Get the attacking land units that will retreat and their number
    final List<Unit> retreatingLandUnits = new ArrayList<>();
    retreatingLandUnits.addAll(karelia.getUnits().getMatches(Matches.isUnitAllied(russians, gameData)));
    final int retreatingLandSizeInt = retreatingLandUnits.size();
    // Get the defending land units that and their number
    retreatingLandUnits.addAll(karelia.getUnits().getMatches(Matches.isUnitAllied(british, gameData)));
    final List<Unit> defendingLandUnits = new ArrayList<>();
    final int defendingLandSizeInt = defendingLandUnits.size();
    // Set up the battles and the dependent battles
    final IBattle inBalticSeaZone = DelegateFinder.battleDelegate(gameData).getBattleTracker().getPendingBattle(balticSeaZone, false, null);
    assertNotNull(balticSeaZone);
    // Add some defending units in case there aren't any
    final List<Unit> defendList = transport.create(1, germans);
    final List<Unit> defendSub = submarine.create(1, germans);
    defendList.addAll(defendSub);
    // fire the defending transport then the submarine (both miss)
    bridge.setRandomSource(new ScriptedRandomSource(new int[] { 1, 2 }));
    // Execute the battle and verify no hits
    final DiceRoll roll = DiceRoll.rollDice(defendList, true, germans, bridge, new MockBattle(balticSeaZone), "", TerritoryEffectHelper.getEffects(balticSeaZone), null);
    assertEquals(0, roll.getHits());
    // Get total number of units in Finland before the retreat
    final int preCountInt = karelia.getUnits().size();
    // Retreat from the Baltic
    ((MustFightBattle) inBalticSeaZone).externalRetreat(retreatingSeaUnits, northSea, false, bridge);
    // Get the total number of units that should be left
    final int postCountInt = preCountInt - retreatingLandSizeInt;
    // Compare the number of units in Finland to begin with the number after retreating
    assertEquals(defendingLandSizeInt, postCountInt);
}
Also used : IntegerMap(games.strategy.util.IntegerMap) ArrayList(java.util.ArrayList) ScriptedRandomSource(games.strategy.engine.random.ScriptedRandomSource) Unit(games.strategy.engine.data.Unit) 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