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