use of games.strategy.util.IntegerMap in project triplea by triplea-game.
the class MoveDelegateTest method testNotEnoughCarrierCapacity.
@Test
public void testNotEnoughCarrierCapacity() {
final IntegerMap<UnitType> map = new IntegerMap<>();
map.put(fighter, 5);
final Route route = new Route();
route.setStart(egypt);
// exast movement to force landing
route.add(eastAfrica);
route.add(kenya);
route.add(mozambiqueSeaZone);
route.add(redSea);
assertEquals(18, egypt.getUnits().size());
assertEquals(4, redSea.getUnits().size());
final String results = delegate.move(GameDataTestUtil.getUnits(map, route.getStart()), route);
assertError(results);
assertEquals(18, egypt.getUnits().size());
assertEquals(4, redSea.getUnits().size());
}
use of games.strategy.util.IntegerMap in project triplea by triplea-game.
the class MoveDelegateTest method testAaCantMoveToConquered.
@Test
public void testAaCantMoveToConquered() {
bridge.setStepName("japaneseCombatMove");
bridge.setPlayerId(japanese);
delegate.setDelegateBridgeAndPlayer(bridge);
delegate.start();
final Route route = new Route();
route.setStart(congo);
route.add(kenya);
final IntegerMap<UnitType> map = new IntegerMap<>();
map.put(armour, 2);
String results = delegate.move(GameDataTestUtil.getUnits(map, route.getStart()), route);
assertValid(results);
final BattleTracker tracker = DelegateFinder.battleDelegate(gameData).getBattleTracker();
assertTrue(tracker.wasBlitzed(kenya));
assertTrue(tracker.wasConquered(kenya));
map.clear();
map.put(aaGun, 1);
results = delegate.move(GameDataTestUtil.getUnits(map, route.getStart()), route);
assertError(results);
}
use of games.strategy.util.IntegerMap in project triplea by triplea-game.
the class MoveDelegateTest method testCantMoveEnemy.
@Test
public void testCantMoveEnemy() {
final IntegerMap<UnitType> map = new IntegerMap<>();
map.put(infantry, 1);
final Route route = new Route();
route.setStart(algeria);
route.add(libya);
assertEquals(1, algeria.getUnits().size());
assertEquals(0, libya.getUnits().size());
final String results = delegate.move(GameDataTestUtil.getUnits(map, route.getStart()), route);
assertError(results);
assertEquals(1, algeria.getUnits().size());
assertEquals(0, libya.getUnits().size());
}
use of games.strategy.util.IntegerMap in project triplea by triplea-game.
the class MoveDelegateTest method testReloadTransportAfterDyingAmphibious.
@Test
public void testReloadTransportAfterDyingAmphibious() {
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(finlandNorway);
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(finlandNorway.getUnits().getMatches(Matches.enemyUnit(germans, gameData)));
final int retreatingLandSizeInt = retreatingLandUnits.size();
// Get the defending land units that and their number
final List<Unit> defendingLandUnits = new ArrayList<>();
defendingLandUnits.addAll(finlandNorway.getUnits().getMatches(Matches.enemyUnit(british, gameData)));
final int defendingLandSizeInt = defendingLandUnits.size();
// Set up the battles and the dependent battles
final IBattle inFinlandNorway = DelegateFinder.battleDelegate(gameData).getBattleTracker().getPendingBattle(finlandNorway, false, null);
final IBattle inBalticSeaZone = DelegateFinder.battleDelegate(gameData).getBattleTracker().getPendingBattle(balticSeaZone, false, null);
assertNotNull(balticSeaZone);
assertNotNull(finlandNorway);
assertEquals(DelegateFinder.battleDelegate(gameData).getBattleTracker().getDependentOn(inFinlandNorway).iterator().next(), inBalticSeaZone);
// 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 (One hit)
bridge.setRandomSource(new ScriptedRandomSource(new int[] { 0, 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(1, roll.getHits());
// Get total number of units in Finland before the retreat
final int preCountInt = finlandNorway.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);
}
use of games.strategy.util.IntegerMap in project triplea by triplea-game.
the class MoveDelegateTest method testUnloadedCantMove.
@Test
public void testUnloadedCantMove() {
IntegerMap<UnitType> map = new IntegerMap<>();
map.put(infantry, 2);
Route route = new Route();
route.setStart(congoSeaZone);
route.add(equatorialAfrica);
String results = delegate.move(GameDataTestUtil.getUnits(map, route.getStart()), route);
assertValid(results);
map = new IntegerMap<>();
// only 2 originially, would have to move the 2 we just unloaded
// as well
map.put(infantry, 4);
route = new Route();
route.setStart(equatorialAfrica);
route.add(egypt);
// units were unloaded, shouldnt be able to move any more
results = delegate.move(GameDataTestUtil.getUnits(map, route.getStart()), route);
assertError(results);
}
Aggregations