Search in sources :

Example 71 with ITestDelegateBridge

use of games.strategy.engine.data.ITestDelegateBridge in project triplea by triplea-game.

the class LhtrTest method testFightersCanLandOnNewPlacedCarrier.

@Test
public void testFightersCanLandOnNewPlacedCarrier() {
    final MoveDelegate delegate = (MoveDelegate) gameData.getDelegateList().getDelegate("move");
    delegate.initialize("MoveDelegate", "MoveDelegate");
    final PlayerID germans = GameDataTestUtil.germans(gameData);
    final ITestDelegateBridge bridge = getDelegateBridge(germans);
    bridge.setStepName("germanNonCombatMove");
    delegate.setDelegateBridgeAndPlayer(bridge);
    delegate.start();
    final Territory baltic = gameData.getMap().getTerritory("5 Sea Zone");
    final Territory easternEurope = gameData.getMap().getTerritory("Eastern Europe");
    final UnitType carrirType = GameDataTestUtil.carrier(gameData);
    // move a fighter to the baltic
    final Route route = new Route();
    route.setStart(easternEurope);
    route.add(baltic);
    final UnitType fighterType = GameDataTestUtil.fighter(gameData);
    delegate.move(easternEurope.getUnits().getMatches(Matches.unitIsOfType(fighterType)), route);
    // add a carrier to be produced in germany
    final TripleAUnit carrier = new TripleAUnit(carrirType, germans, gameData);
    gameData.performChange(ChangeFactory.addUnits(germans, Collections.singleton(carrier)));
    // end the move phase
    delegate.end();
    // make sure the fighter is still there
    // in lhtr fighters can hover, and carriers placed beneath them
    assertTrue(baltic.getUnits().anyMatch(Matches.unitIsOfType(fighterType)));
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) UnitType(games.strategy.engine.data.UnitType) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) TripleAUnit(games.strategy.triplea.TripleAUnit) Route(games.strategy.engine.data.Route) Test(org.junit.jupiter.api.Test)

Example 72 with ITestDelegateBridge

use of games.strategy.engine.data.ITestDelegateBridge in project triplea by triplea-game.

the class PactOfSteel2Test method testDirectOwnershipTerritories.

@Test
public void testDirectOwnershipTerritories() {
    final Territory norway = gameData.getMap().getTerritory("Norway");
    final Territory easternEurope = gameData.getMap().getTerritory("Eastern Europe");
    final Territory eastBalkans = gameData.getMap().getTerritory("East Balkans");
    final Territory ukraineSsr = gameData.getMap().getTerritory("Ukraine S.S.R.");
    final Territory belorussia = gameData.getMap().getTerritory("Belorussia");
    final PlayerID british = GameDataTestUtil.british(gameData);
    final PlayerID germans = GameDataTestUtil.germans(gameData);
    final PlayerID russians = GameDataTestUtil.russians(gameData);
    final ITestDelegateBridge bridge = getDelegateBridge(russians);
    // this National Objective russia has to own at least 3 of the 5 territories by itself
    final RulesAttachment russianEasternEurope = RulesAttachment.get(russians, "objectiveAttachmentRussians1_EasternEurope");
    final Collection<Territory> terrs = new ArrayList<>();
    terrs.add(norway);
    terrs.add(easternEurope);
    terrs.add(eastBalkans);
    terrs.add(ukraineSsr);
    terrs.add(belorussia);
    assertEquals(5, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(germans)));
    assertEquals(0, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(russians)));
    assertEquals(0, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(british)));
    assertFalse(russianEasternEurope.isSatisfied(null, bridge));
    norway.setOwner(british);
    easternEurope.setOwner(russians);
    eastBalkans.setOwner(russians);
    ukraineSsr.setOwner(germans);
    belorussia.setOwner(germans);
    assertEquals(2, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(germans)));
    assertEquals(2, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(russians)));
    assertEquals(1, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(british)));
    assertFalse(russianEasternEurope.isSatisfied(null, bridge));
    ukraineSsr.setOwner(british);
    belorussia.setOwner(british);
    assertEquals(0, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(germans)));
    assertEquals(2, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(russians)));
    assertEquals(3, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(british)));
    assertFalse(russianEasternEurope.isSatisfied(null, bridge));
    norway.setOwner(russians);
    ukraineSsr.setOwner(germans);
    belorussia.setOwner(germans);
    assertEquals(2, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(germans)));
    assertEquals(3, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(russians)));
    assertEquals(0, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(british)));
    assertTrue(russianEasternEurope.isSatisfied(null, bridge));
    ukraineSsr.setOwner(russians);
    assertEquals(1, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(germans)));
    assertEquals(4, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(russians)));
    assertEquals(0, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(british)));
    assertTrue(russianEasternEurope.isSatisfied(null, bridge));
    belorussia.setOwner(russians);
    assertEquals(0, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(germans)));
    assertEquals(5, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(russians)));
    assertEquals(0, CollectionUtils.countMatches(terrs, Matches.isTerritoryOwnedBy(british)));
    assertTrue(russianEasternEurope.isSatisfied(null, bridge));
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) ArrayList(java.util.ArrayList) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) RulesAttachment(games.strategy.triplea.attachments.RulesAttachment) Test(org.junit.jupiter.api.Test)

Example 73 with ITestDelegateBridge

use of games.strategy.engine.data.ITestDelegateBridge in project triplea by triplea-game.

the class RevisedTest method testLoadUndoInWrongOrder.

@Test
public void testLoadUndoInWrongOrder() {
    final Territory sz5 = gameData.getMap().getTerritory("5 Sea Zone");
    final Territory eastEurope = gameData.getMap().getTerritory("Eastern Europe");
    final UnitType infantryType = GameDataTestUtil.infantry(gameData);
    final PlayerID germans = GameDataTestUtil.germans(gameData);
    final MoveDelegate moveDelegate = (MoveDelegate) gameData.getDelegateList().getDelegate("move");
    final ITestDelegateBridge bridge = getDelegateBridge(germans);
    bridge.setStepName("CombatMove");
    moveDelegate.setDelegateBridgeAndPlayer(bridge);
    moveDelegate.start();
    final Route eeToSz5 = new Route();
    eeToSz5.setStart(eastEurope);
    eeToSz5.add(sz5);
    // load the transport in the baltic
    final List<Unit> infantry = eastEurope.getUnits().getMatches(Matches.unitIsOfType(infantryType));
    assertEquals(2, infantry.size());
    final TripleAUnit transport = (TripleAUnit) sz5.getUnits().getMatches(Matches.unitIsTransport()).get(0);
    // load the transports
    // in two moves
    String error = moveDelegate.move(infantry.subList(0, 1), eeToSz5, Collections.singletonList(transport));
    assertNull(error, error);
    error = moveDelegate.move(infantry.subList(1, 2), eeToSz5, Collections.singletonList(transport));
    assertNull(error, error);
    // make sure the transport was loaded
    assertTrue(moveDelegate.getMovesMade().get(0).wasTransportLoaded(transport));
    assertTrue(moveDelegate.getMovesMade().get(1).wasTransportLoaded(transport));
    // udo the moves in reverse order
    moveDelegate.undoMove(0);
    moveDelegate.undoMove(0);
    // make sure that loaded is not set
    assertTrue(transport.getTransporting().isEmpty());
    assertFalse(((TripleAUnit) infantry.get(0)).getWasLoadedThisTurn());
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) UnitType(games.strategy.engine.data.UnitType) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) TripleAUnit(games.strategy.triplea.TripleAUnit) Unit(games.strategy.engine.data.Unit) TripleAUnit(games.strategy.triplea.TripleAUnit) Route(games.strategy.engine.data.Route) Test(org.junit.jupiter.api.Test)

Example 74 with ITestDelegateBridge

use of games.strategy.engine.data.ITestDelegateBridge in project triplea by triplea-game.

the class RevisedTest method testTechRolls.

@Test
public void testTechRolls() {
    // Set up the test
    final PlayerID germans = GameDataTestUtil.germans(gameData);
    final ITestDelegateBridge delegateBridge = getDelegateBridge(germans);
    delegateBridge.setStepName("germanTech");
    final TechnologyDelegate techDelegate = techDelegate(gameData);
    techDelegate.setDelegateBridgeAndPlayer(delegateBridge);
    techDelegate.start();
    final TechAttachment ta = TechAttachment.get(germans);
    // PlayerAttachment pa = PlayerAttachment.get(germans);
    final TechnologyFrontier rockets = new TechnologyFrontier("", gameData);
    rockets.addAdvance(TechAdvance.findAdvance(TechAdvance.TECH_PROPERTY_ROCKETS, gameData, null));
    final TechnologyFrontier jet = new TechnologyFrontier("", gameData);
    jet.addAdvance(TechAdvance.findAdvance(TechAdvance.TECH_PROPERTY_JET_POWER, gameData, null));
    // Check to make sure it was successful
    final int initPUs = germans.getResources().getQuantity("PUs");
    // Fail the roll
    delegateBridge.setRandomSource(new ScriptedRandomSource(new int[] { 3, 4 }));
    final TechResults roll = techDelegate.rollTech(2, rockets, 0, null);
    // Check to make sure it failed
    assertEquals(0, roll.getHits());
    final int midPUs = germans.getResources().getQuantity("PUs");
    assertEquals(initPUs - 10, midPUs);
    // Make a Successful roll
    delegateBridge.setRandomSource(new ScriptedRandomSource(new int[] { 5 }));
    final TechResults roll2 = techDelegate.rollTech(1, rockets, 0, null);
    // Check to make sure it succeeded
    assertEquals(1, roll2.getHits());
    final int finalPUs = germans.getResources().getQuantity("PUs");
    assertEquals(midPUs - 5, finalPUs);
    // Test the variable tech cost
    // Make a Successful roll
    ta.setTechCost("6");
    delegateBridge.setRandomSource(new ScriptedRandomSource(new int[] { 5 }));
    final TechResults roll3 = techDelegate.rollTech(1, jet, 0, null);
    // Check to make sure it succeeded
    assertEquals(1, roll3.getHits());
    final int variablePus = germans.getResources().getQuantity("PUs");
    assertEquals(finalPUs - 6, variablePus);
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) TechAttachment(games.strategy.triplea.attachments.TechAttachment) TechResults(games.strategy.triplea.delegate.dataObjects.TechResults) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) TechnologyFrontier(games.strategy.engine.data.TechnologyFrontier) ScriptedRandomSource(games.strategy.engine.random.ScriptedRandomSource) Test(org.junit.jupiter.api.Test)

Example 75 with ITestDelegateBridge

use of games.strategy.engine.data.ITestDelegateBridge in project triplea by triplea-game.

the class RevisedTest method testStratBombRaidWithHeavyBombers.

@Test
public void testStratBombRaidWithHeavyBombers() {
    final Territory germany = gameData.getMap().getTerritory("Germany");
    final Territory uk = gameData.getMap().getTerritory("United Kingdom");
    final PlayerID germans = GameDataTestUtil.germans(gameData);
    final PlayerID british = GameDataTestUtil.british(gameData);
    final BattleTracker tracker = new BattleTracker();
    final StrategicBombingRaidBattle battle = new StrategicBombingRaidBattle(germany, gameData, british, tracker);
    battle.addAttackChange(gameData.getMap().getRoute(uk, germany), uk.getUnits().getMatches(Matches.unitIsStrategicBomber()), null);
    addTo(germany, uk.getUnits().getMatches(Matches.unitIsStrategicBomber()));
    tracker.getBattleRecords().addBattle(british, battle.getBattleId(), germany, battle.getBattleType());
    final ITestDelegateBridge bridge = getDelegateBridge(british);
    TechTracker.addAdvance(british, bridge, TechAdvance.findAdvance(TechAdvance.TECH_PROPERTY_HEAVY_BOMBER, gameData, british));
    // aa guns rolls 3, misses, bomber rolls 2 dice at 3
    bridge.setRandomSource(new ScriptedRandomSource(new int[] { 3, 2, 2 }));
    // if we try to move aa, then the game will ask us if we want to move
    // fail if we are called
    final InvocationHandler handler = (proxy, method, args) -> null;
    final ITripleAPlayer player = (ITripleAPlayer) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[] { ITripleAPlayer.class }, handler);
    bridge.setRemote(player);
    final int pusBeforeRaid = germans.getResources().getQuantity(gameData.getResourceList().getResource(Constants.PUS));
    battle.fight(bridge);
    final int pusAfterRaid = germans.getResources().getQuantity(gameData.getResourceList().getResource(Constants.PUS));
    assertEquals(pusBeforeRaid - 6, pusAfterRaid);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) GameDataTestUtil.move(games.strategy.triplea.delegate.GameDataTestUtil.move) Arrays(java.util.Arrays) GameDataTestUtil.bomber(games.strategy.triplea.delegate.GameDataTestUtil.bomber) GameDataTestUtil.japanese(games.strategy.triplea.delegate.GameDataTestUtil.japanese) Constants(games.strategy.triplea.Constants) UnitAttachment(games.strategy.triplea.attachments.UnitAttachment) GameDataTestUtil.addTo(games.strategy.triplea.delegate.GameDataTestUtil.addTo) TechAttachment(games.strategy.triplea.attachments.TechAttachment) GameDataTestUtil.aaGun(games.strategy.triplea.delegate.GameDataTestUtil.aaGun) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) GameDataTestUtil.moveDelegate(games.strategy.triplea.delegate.GameDataTestUtil.moveDelegate) GameDataTestUtil.makeGameLowLuck(games.strategy.triplea.delegate.GameDataTestUtil.makeGameLowLuck) GameDataTestUtil.americans(games.strategy.triplea.delegate.GameDataTestUtil.americans) GameDataTestUtil.getIndex(games.strategy.triplea.delegate.GameDataTestUtil.getIndex) TestMapGameData(games.strategy.triplea.xml.TestMapGameData) GameDataTestUtil.techDelegate(games.strategy.triplea.delegate.GameDataTestUtil.techDelegate) GameDataTestUtil.removeFrom(games.strategy.triplea.delegate.GameDataTestUtil.removeFrom) ScriptedRandomSource(games.strategy.engine.random.ScriptedRandomSource) GameDataTestUtil.assertValid(games.strategy.triplea.delegate.GameDataTestUtil.assertValid) Collection(java.util.Collection) GameDataTestUtil.load(games.strategy.triplea.delegate.GameDataTestUtil.load) Set(java.util.Set) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) GameDataTestUtil.territory(games.strategy.triplea.delegate.GameDataTestUtil.territory) SUBS_FIRE(games.strategy.triplea.delegate.BattleStepStrings.SUBS_FIRE) GameDataTestUtil.armour(games.strategy.triplea.delegate.GameDataTestUtil.armour) Test(org.junit.jupiter.api.Test) SUBS_SUBMERGE(games.strategy.triplea.delegate.BattleStepStrings.SUBS_SUBMERGE) GameData(games.strategy.engine.data.GameData) List(java.util.List) PlayerID(games.strategy.engine.data.PlayerID) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ITripleAPlayer(games.strategy.triplea.player.ITripleAPlayer) REMOVE_CASUALTIES(games.strategy.triplea.delegate.BattleStepStrings.REMOVE_CASUALTIES) GameDataTestUtil.destroyer(games.strategy.triplea.delegate.GameDataTestUtil.destroyer) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) GameDataTestUtil.infantry(games.strategy.triplea.delegate.GameDataTestUtil.infantry) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Proxy(java.lang.reflect.Proxy) GameDataTestUtil.battleship(games.strategy.triplea.delegate.GameDataTestUtil.battleship) SELECT_SUB_CASUALTIES(games.strategy.triplea.delegate.BattleStepStrings.SELECT_SUB_CASUALTIES) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) GameDataTestUtil.placeDelegate(games.strategy.triplea.delegate.GameDataTestUtil.placeDelegate) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) ArrayList(java.util.ArrayList) PlaceableUnits(games.strategy.triplea.delegate.dataObjects.PlaceableUnits) Answer(org.mockito.stubbing.Answer) Route(games.strategy.engine.data.Route) GameDataTestUtil.assertError(games.strategy.triplea.delegate.GameDataTestUtil.assertError) InvocationOnMock(org.mockito.invocation.InvocationOnMock) SELECT_CASUALTIES(games.strategy.triplea.delegate.BattleStepStrings.SELECT_CASUALTIES) CasualtyDetails(games.strategy.triplea.delegate.dataObjects.CasualtyDetails) GameDataTestUtil.bidPlaceDelegate(games.strategy.triplea.delegate.GameDataTestUtil.bidPlaceDelegate) CasualtyList(games.strategy.triplea.delegate.dataObjects.CasualtyList) UnitType(games.strategy.engine.data.UnitType) FIRE(games.strategy.triplea.delegate.BattleStepStrings.FIRE) GameDataTestUtil.germans(games.strategy.triplea.delegate.GameDataTestUtil.germans) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TripleAUnit(games.strategy.triplea.TripleAUnit) TechResults(games.strategy.triplea.delegate.dataObjects.TechResults) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) TechnologyFrontier(games.strategy.engine.data.TechnologyFrontier) CollectionUtils(games.strategy.util.CollectionUtils) Unit(games.strategy.engine.data.Unit) GameDataTestUtil.submarine(games.strategy.triplea.delegate.GameDataTestUtil.submarine) GameDataTestUtil.transport(games.strategy.triplea.delegate.GameDataTestUtil.transport) Territory(games.strategy.engine.data.Territory) Mockito.when(org.mockito.Mockito.when) GameDataTestUtil.british(games.strategy.triplea.delegate.GameDataTestUtil.british) ChangeFactory(games.strategy.engine.data.changefactory.ChangeFactory) REMOVE_SNEAK_ATTACK_CASUALTIES(games.strategy.triplea.delegate.BattleStepStrings.REMOVE_SNEAK_ATTACK_CASUALTIES) Change(games.strategy.engine.data.Change) ATTACKER_WITHDRAW(games.strategy.triplea.delegate.BattleStepStrings.ATTACKER_WITHDRAW) GameDataTestUtil.assertMoveError(games.strategy.triplea.delegate.GameDataTestUtil.assertMoveError) InvocationHandler(java.lang.reflect.InvocationHandler) Collections(java.util.Collections) PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) ScriptedRandomSource(games.strategy.engine.random.ScriptedRandomSource) InvocationHandler(java.lang.reflect.InvocationHandler) ITripleAPlayer(games.strategy.triplea.player.ITripleAPlayer) Test(org.junit.jupiter.api.Test)

Aggregations

ITestDelegateBridge (games.strategy.engine.data.ITestDelegateBridge)128 Test (org.junit.jupiter.api.Test)127 Territory (games.strategy.engine.data.Territory)119 PlayerID (games.strategy.engine.data.PlayerID)94 Route (games.strategy.engine.data.Route)80 TripleAUnit (games.strategy.triplea.TripleAUnit)60 Unit (games.strategy.engine.data.Unit)58 ScriptedRandomSource (games.strategy.engine.random.ScriptedRandomSource)56 UnitType (games.strategy.engine.data.UnitType)40 Change (games.strategy.engine.data.Change)12 ArrayList (java.util.ArrayList)11 UnitAttachment (games.strategy.triplea.attachments.UnitAttachment)8 GameData (games.strategy.engine.data.GameData)5 GameDataTestUtil.bidPlaceDelegate (games.strategy.triplea.delegate.GameDataTestUtil.bidPlaceDelegate)5 ITripleAPlayer (games.strategy.triplea.player.ITripleAPlayer)5 TestMapGameData (games.strategy.triplea.xml.TestMapGameData)5 IntegerMap (games.strategy.util.IntegerMap)5 List (java.util.List)5 TerritoryEffect (games.strategy.engine.data.TerritoryEffect)4 ChangeFactory (games.strategy.engine.data.changefactory.ChangeFactory)4