use of games.strategy.util.IntegerMap in project triplea by triplea-game.
the class WW2V3Year41Test method testRepair.
@Test
public void testRepair() {
final Territory germany = territory("Germany", gameData);
final Unit factory = germany.getUnits().getMatches(Matches.unitCanBeDamaged()).get(0);
final PurchaseDelegate del = purchaseDelegate(gameData);
del.setDelegateBridgeAndPlayer(getDelegateBridge(germans(gameData)));
del.start();
// Set up player
final PlayerID germans = GameDataTestUtil.germans(gameData);
final int initPUs = germans.getResources().getQuantity("PUs");
// damage a factory
IntegerMap<Unit> startHits = new IntegerMap<>();
startHits.put(factory, 1);
gameData.performChange(ChangeFactory.bombingUnitDamage(startHits));
assertEquals(1, ((TripleAUnit) factory).getUnitDamage());
RepairRule repair = germans(gameData).getRepairFrontier().getRules().get(0);
IntegerMap<RepairRule> repairs = new IntegerMap<>();
repairs.put(repair, 1);
String error = del.purchaseRepair(Collections.singletonMap(CollectionUtils.getMatches(germany.getUnits().getUnits(), Matches.unitCanBeDamaged()).iterator().next(), repairs));
assertValid(error);
assertEquals(0, ((TripleAUnit) factory).getUnitDamage());
// Find cost
final int midPUs = germans.getResources().getQuantity("PUs");
assertEquals(initPUs, midPUs + 1);
/*
* INCREASED_FACTORY_PRODUCTION repairs
*/
// Set up INCREASED_FACTORY_PRODUCTION
final ITestDelegateBridge delegateBridge = getDelegateBridge(germans(gameData));
TechTracker.addAdvance(germans, delegateBridge, TechAdvance.findAdvance(TechAdvance.TECH_PROPERTY_INCREASED_FACTORY_PRODUCTION, gameData, germans));
// damage a factory
startHits = new IntegerMap<>();
startHits.put(factory, 2);
gameData.performChange(ChangeFactory.bombingUnitDamage(startHits));
assertEquals(2, ((TripleAUnit) factory).getUnitDamage());
repair = germans(gameData).getRepairFrontier().getRules().get(0);
repairs = new IntegerMap<>();
repairs.put(repair, 2);
error = del.purchaseRepair(Collections.singletonMap(CollectionUtils.getMatches(germany.getUnits().getUnits(), Matches.unitCanBeDamaged()).iterator().next(), repairs));
assertValid(error);
assertEquals(0, ((TripleAUnit) factory).getUnitDamage());
// Find cost
final int finalPUs = germans.getResources().getQuantity("PUs");
assertEquals(midPUs, finalPUs + 1);
}
use of games.strategy.util.IntegerMap in project triplea by triplea-game.
the class WW2V3Year41Test method testMultipleAaInTerritory.
@Test
public void testMultipleAaInTerritory() {
// Set up territories
final Territory poland = territory("Poland", gameData);
// Add a russian factory
final Territory germany = territory("Germany", gameData);
addTo(poland, aaGun(gameData).create(1, germans(gameData)));
MoveDelegate moveDelegate = moveDelegate(gameData);
ITestDelegateBridge delegateBridge = getDelegateBridge(germans(gameData));
delegateBridge.setStepName("NonCombatMove");
moveDelegate.setDelegateBridgeAndPlayer(delegateBridge);
moveDelegate.start();
final int preCount = germany.getUnits().getUnitCount();
/*
* Move one
*/
String errorResults = moveDelegate.move(poland.getUnits().getMatches(Matches.unitIsAaForAnything()), new Route(poland, germany));
assertValid(errorResults);
assertEquals(germany.getUnits().getUnitCount(), preCount + 1);
/*
* Test unloading TRN
*/
final Territory finland = territory("Finland", gameData);
final Territory sz5 = territory("5 Sea Zone", gameData);
addTo(finland, aaGun(gameData).create(1, germans(gameData)));
moveDelegate = moveDelegate(gameData);
delegateBridge = getDelegateBridge(germans(gameData));
delegateBridge.setStepName("NonCombatMove");
moveDelegate.setDelegateBridgeAndPlayer(delegateBridge);
moveDelegate.start();
// load the trn
errorResults = moveDelegate.move(finland.getUnits().getMatches(Matches.unitIsAaForAnything()), new Route(finland, sz5), sz5.getUnits().getMatches(Matches.unitIsTransport()));
assertValid(errorResults);
// unload the trn
errorResults = moveDelegate.move(sz5.getUnits().getMatches(Matches.unitIsAaForAnything()), new Route(sz5, germany));
assertValid(errorResults);
assertEquals(germany.getUnits().getUnitCount(), preCount + 2);
/*
* Test Building one
*/
final UnitType aaGun = GameDataTestUtil.aaGun(gameData);
final IntegerMap<UnitType> map = new IntegerMap<>();
map.add(aaGun, 1);
// Set up the test
final PlayerID germans = GameDataTestUtil.germans(gameData);
final PlaceDelegate placeDelegate = placeDelegate(gameData);
delegateBridge.setStepName("Place");
delegateBridge.setPlayerId(germans);
placeDelegate.setDelegateBridgeAndPlayer(getDelegateBridge(germans(gameData)));
placeDelegate.start();
addTo(germans(gameData), aaGun(gameData).create(1, germans(gameData)), gameData);
errorResults = placeDelegate.placeUnits(GameDataTestUtil.getUnits(map, germans), germany, IAbstractPlaceDelegate.BidMode.NOT_BID);
assertValid(errorResults);
assertEquals(germany.getUnits().getUnitCount(), preCount + 3);
}
use of games.strategy.util.IntegerMap in project triplea by triplea-game.
the class MoveDelegateTest method testCanBlitzThroughConqueredEnemy.
@Test
public void testCanBlitzThroughConqueredEnemy() {
// take over empty enemy
Route route = new Route();
route.setStart(equatorialAfrica);
route.add(libya);
IntegerMap<UnitType> map = new IntegerMap<>();
map.put(infantry, 1);
String results = delegate.move(GameDataTestUtil.getUnits(map, route.getStart()), route);
assertValid(results);
// make sure we can still blitz through it
route = new Route();
route.setStart(equatorialAfrica);
route.add(libya);
route.add(algeria);
map = new IntegerMap<>();
map.put(armour, 1);
results = delegate.move(GameDataTestUtil.getUnits(map, route.getStart()), route);
assertValid(results);
}
use of games.strategy.util.IntegerMap in project triplea by triplea-game.
the class MoveDelegateTest method testSeaCantMoveToLand.
@Test
public void testSeaCantMoveToLand() {
final IntegerMap<UnitType> map = new IntegerMap<>();
map.put(carrier, 2);
final Route route = new Route();
route.setStart(redSea);
// exast movement to force landing
route.add(egypt);
assertEquals(4, redSea.getUnits().size());
assertEquals(18, egypt.getUnits().size());
final String results = delegate.move(GameDataTestUtil.getUnits(map, route.getStart()), route);
assertError(results);
assertEquals(4, redSea.getUnits().size());
assertEquals(18, egypt.getUnits().size());
}
use of games.strategy.util.IntegerMap in project triplea by triplea-game.
the class MoveDelegateTest method testUseTransportsWithLowestMovement.
@Test
public void testUseTransportsWithLowestMovement() {
// move transport south
Route route = new Route();
route.setStart(congoSeaZone);
route.add(angolaSeaZone);
IntegerMap<UnitType> map = new IntegerMap<>();
map.put(transport, 1);
map.put(infantry, 2);
String results = delegate.move(GameDataTestUtil.getUnits(map, route.getStart()), route);
assertValid(results);
// move transport back
route = new Route();
route.setStart(angolaSeaZone);
route.add(congoSeaZone);
map = new IntegerMap<>();
map.put(transport, 1);
map.put(infantry, 2);
results = delegate.move(GameDataTestUtil.getUnits(map, route.getStart()), route);
assertValid(results);
// move the other transport south, should
// figure out that only 1 can move
// and will choose that one
route = new Route();
route.setStart(congoSeaZone);
route.add(angolaSeaZone);
map = new IntegerMap<>();
map.put(infantry, 2);
map.put(transport, 1);
results = delegate.move(GameDataTestUtil.getUnits(map, route.getStart()), route);
assertValid(results);
}
Aggregations