use of games.strategy.util.IntegerMap in project triplea by triplea-game.
the class VictoryTest method testMultipleResourcesToPurchase.
@Test
public void testMultipleResourcesToPurchase() {
testBridge.setStepName("italianPurchase");
purchaseDelegate.setDelegateBridgeAndPlayer(testBridge);
purchaseDelegate.start();
final IntegerMap<ProductionRule> purchaseList = new IntegerMap<>();
final ProductionRule armourtest = gameData.getProductionRuleList().getProductionRule("buyArmourtest");
assertNotNull(armourtest);
italianResources.subtract(armourtest.getCosts());
purchaseList.add(armourtest, 1);
final String error = purchaseDelegate.purchase(purchaseList);
assertEquals(null, error);
assertEquals(italianResources, italians.getResources().getResourcesCopy());
}
use of games.strategy.util.IntegerMap in project triplea by triplea-game.
the class WW2V3Year41Test method testFactoryPlace.
@Test
public void testFactoryPlace() {
// Set up game
final PlayerID british = GameDataTestUtil.british(gameData);
final ITestDelegateBridge delegateBridge = getDelegateBridge(british(gameData));
// Set up the territories
final Territory egypt = territory("Union of South Africa", gameData);
// Set up the unit types
final UnitType factoryType = GameDataTestUtil.factory(gameData);
// Set up the move delegate
final PlaceDelegate placeDelegate = placeDelegate(gameData);
delegateBridge.setStepName("Place");
delegateBridge.setPlayerId(british);
placeDelegate.setDelegateBridgeAndPlayer(delegateBridge);
placeDelegate.start();
// Add the factory
final IntegerMap<UnitType> map = new IntegerMap<>();
map.add(factoryType, 1);
addTo(british(gameData), factory(gameData).create(1, british(gameData)), gameData);
// Place the factory
final String response = placeDelegate.placeUnits(GameDataTestUtil.getUnits(map, british), egypt);
assertValid(response);
// placeUnits performPlace
// get production and unit production values
final TerritoryAttachment ta = TerritoryAttachment.get(egypt);
assertEquals(ta.getUnitProduction(), ta.getProduction());
}
use of games.strategy.util.IntegerMap in project triplea by triplea-game.
the class WW2V3Year41Test method testPlaceInOccupiedSeaZone.
@Test
public void testPlaceInOccupiedSeaZone() {
// Set up game
final PlayerID germans = GameDataTestUtil.germans(gameData);
final ITestDelegateBridge delegateBridge = getDelegateBridge(british(gameData));
// Clear all units from the SZ and add an enemy unit
final Territory sz5 = territory("5 Sea Zone", gameData);
removeFrom(sz5, sz5.getUnits().getUnits());
addTo(sz5, destroyer(gameData).create(1, british(gameData)));
// Set up the unit types
final UnitType transportType = GameDataTestUtil.transport(gameData);
// Set up the move delegate
final PlaceDelegate placeDelegate = placeDelegate(gameData);
delegateBridge.setStepName("Place");
delegateBridge.setPlayerId(germans);
placeDelegate.setDelegateBridgeAndPlayer(delegateBridge);
placeDelegate.start();
// Add the transport
final IntegerMap<UnitType> map = new IntegerMap<>();
map.add(transportType, 1);
addTo(germans(gameData), transport(gameData).create(1, germans(gameData)), gameData);
// Place it
final String response = placeDelegate.placeUnits(GameDataTestUtil.getUnits(map, germans), sz5);
assertValid(response);
}
use of games.strategy.util.IntegerMap in project triplea by triplea-game.
the class WW2V3Year41Test method testChinesePlacement.
@Test
public void testChinesePlacement() {
/*
* This tests that Chinese can place units in any territory, that they can
* place in just conquered territories, and that they can place in territories
* with up to 3 Chinese units in them.
*/
// Set up game
final PlayerID chinese = GameDataTestUtil.chinese(gameData);
final ITestDelegateBridge delegateBridge = getDelegateBridge(chinese(gameData));
delegateBridge.setPlayerId(chinese);
delegateBridge.setStepName("CombatMove");
final MoveDelegate moveDelegate = moveDelegate(gameData);
moveDelegate.setDelegateBridgeAndPlayer(delegateBridge);
moveDelegate.start();
// Set up the territories
final Territory yunnan = territory("Yunnan", gameData);
final Territory kiangsu = territory("Kiangsu", gameData);
final Territory hupeh = territory("Hupeh", gameData);
// Set up the unit types
final UnitType infantryType = GameDataTestUtil.infantry(gameData);
// Remove all units
removeFrom(kiangsu, kiangsu.getUnits().getUnits());
// add a VALID attack
final Collection<Unit> moveUnits = hupeh.getUnits().getUnits();
final String validResults = moveDelegate.move(moveUnits, new Route(hupeh, kiangsu));
assertValid(validResults);
/*
* Place units in just captured territory
*/
final PlaceDelegate placeDelegate = placeDelegate(gameData);
delegateBridge.setStepName("Place");
placeDelegate.setDelegateBridgeAndPlayer(delegateBridge);
placeDelegate.start();
// Add the infantry
IntegerMap<UnitType> map = new IntegerMap<>();
map.add(infantryType, 3);
addTo(chinese(gameData), infantry(gameData).create(1, chinese(gameData)), gameData);
// Get the number of units before placing
int preCount = kiangsu.getUnits().getUnitCount();
// Place the infantry
String response = placeDelegate.placeUnits(GameDataTestUtil.getUnits(map, chinese), kiangsu, IAbstractPlaceDelegate.BidMode.NOT_BID);
assertValid(response);
assertEquals(preCount + 1, kiangsu.getUnits().getUnitCount());
/*
* Place units in a territory with up to 3 Chinese units
*/
// Add the infantry
map = new IntegerMap<>();
map.add(infantryType, 3);
addTo(chinese(gameData), infantry(gameData).create(3, chinese(gameData)), gameData);
// Get the number of units before placing
preCount = yunnan.getUnits().getUnitCount();
// Place the infantry
response = placeDelegate.placeUnits(GameDataTestUtil.getUnits(map, chinese), yunnan, IAbstractPlaceDelegate.BidMode.NOT_BID);
assertValid(response);
final int midCount = yunnan.getUnits().getUnitCount();
// Make sure they were all placed
assertEquals(preCount, midCount - 3);
/*
* Place units in a territory with 3 or more Chinese units
*/
map = new IntegerMap<>();
map.add(infantryType, 1);
addTo(chinese(gameData), infantry(gameData).create(1, chinese(gameData)), gameData);
response = placeDelegate.placeUnits(GameDataTestUtil.getUnits(map, chinese), yunnan, IAbstractPlaceDelegate.BidMode.NOT_BID);
assertError(response);
// Make sure none were placed
final int postCount = yunnan.getUnits().getUnitCount();
assertEquals(midCount, postCount);
}
use of games.strategy.util.IntegerMap in project triplea by triplea-game.
the class WW2V3Year41Test method testRepairMoreThanDamaged.
@Test
public void testRepairMoreThanDamaged() {
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();
// dame a factory
final IntegerMap<Unit> startHits = new IntegerMap<>();
startHits.put(factory, 1);
gameData.performChange(ChangeFactory.bombingUnitDamage(startHits));
assertEquals(1, ((TripleAUnit) factory).getUnitDamage());
final RepairRule repair = germans(gameData).getRepairFrontier().getRules().get(0);
final IntegerMap<RepairRule> repairs = new IntegerMap<>();
// we have 1 damaged marker, but trying to repair 2
repairs.put(repair, 2);
final String error = del.purchaseRepair(Collections.singletonMap(CollectionUtils.getMatches(germany.getUnits().getUnits(), Matches.unitCanBeDamaged()).iterator().next(), repairs));
// it is no longer an error, we just math max 0 it
assertValid(error);
assertEquals(0, ((TripleAUnit) factory).getUnitDamage());
}
Aggregations