Search in sources :

Example 86 with IntegerMap

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());
}
Also used : IntegerMap(games.strategy.util.IntegerMap) ProductionRule(games.strategy.engine.data.ProductionRule) Test(org.junit.jupiter.api.Test)

Example 87 with IntegerMap

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());
}
Also used : IntegerMap(games.strategy.util.IntegerMap) PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) UnitType(games.strategy.engine.data.UnitType) TerritoryAttachment(games.strategy.triplea.attachments.TerritoryAttachment) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) GameDataTestUtil.bidPlaceDelegate(games.strategy.triplea.delegate.GameDataTestUtil.bidPlaceDelegate) IAbstractPlaceDelegate(games.strategy.triplea.delegate.remote.IAbstractPlaceDelegate) Test(org.junit.jupiter.api.Test)

Example 88 with IntegerMap

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);
}
Also used : IntegerMap(games.strategy.util.IntegerMap) PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) UnitType(games.strategy.engine.data.UnitType) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) GameDataTestUtil.bidPlaceDelegate(games.strategy.triplea.delegate.GameDataTestUtil.bidPlaceDelegate) IAbstractPlaceDelegate(games.strategy.triplea.delegate.remote.IAbstractPlaceDelegate) Test(org.junit.jupiter.api.Test)

Example 89 with IntegerMap

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);
}
Also used : IntegerMap(games.strategy.util.IntegerMap) PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) TripleAUnit(games.strategy.triplea.TripleAUnit) Unit(games.strategy.engine.data.Unit) GameDataTestUtil.bidPlaceDelegate(games.strategy.triplea.delegate.GameDataTestUtil.bidPlaceDelegate) IAbstractPlaceDelegate(games.strategy.triplea.delegate.remote.IAbstractPlaceDelegate) UnitType(games.strategy.engine.data.UnitType) Route(games.strategy.engine.data.Route) Test(org.junit.jupiter.api.Test)

Example 90 with IntegerMap

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());
}
Also used : IntegerMap(games.strategy.util.IntegerMap) Territory(games.strategy.engine.data.Territory) RepairRule(games.strategy.engine.data.RepairRule) TripleAUnit(games.strategy.triplea.TripleAUnit) Unit(games.strategy.engine.data.Unit) Test(org.junit.jupiter.api.Test)

Aggregations

IntegerMap (games.strategy.util.IntegerMap)132 UnitType (games.strategy.engine.data.UnitType)87 Test (org.junit.jupiter.api.Test)73 Route (games.strategy.engine.data.Route)66 Unit (games.strategy.engine.data.Unit)53 Territory (games.strategy.engine.data.Territory)39 ArrayList (java.util.ArrayList)35 PlayerID (games.strategy.engine.data.PlayerID)26 TripleAUnit (games.strategy.triplea.TripleAUnit)24 HashMap (java.util.HashMap)23 HashSet (java.util.HashSet)19 Resource (games.strategy.engine.data.Resource)16 GameData (games.strategy.engine.data.GameData)15 ProductionRule (games.strategy.engine.data.ProductionRule)14 Collection (java.util.Collection)12 List (java.util.List)12 UnitAttachment (games.strategy.triplea.attachments.UnitAttachment)10 Set (java.util.Set)10 RepairRule (games.strategy.engine.data.RepairRule)9 NamedAttachable (games.strategy.engine.data.NamedAttachable)7