Search in sources :

Example 91 with IntegerMap

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

Example 92 with IntegerMap

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);
}
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) Route(games.strategy.engine.data.Route) GameDataTestUtil.bidPlaceDelegate(games.strategy.triplea.delegate.GameDataTestUtil.bidPlaceDelegate) IAbstractPlaceDelegate(games.strategy.triplea.delegate.remote.IAbstractPlaceDelegate) Test(org.junit.jupiter.api.Test)

Example 93 with IntegerMap

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);
}
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 94 with IntegerMap

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());
}
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 95 with IntegerMap

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);
}
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)

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