use of games.strategy.engine.data.ITestDelegateBridge in project triplea by triplea-game.
the class RevisedTest method testStratBombCasualties.
@Test
public void testStratBombCasualties() {
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);
final List<Unit> bombers = uk.getUnits().getMatches(Matches.unitIsStrategicBomber());
addTo(germany, bombers);
battle.addAttackChange(gameData.getMap().getRoute(uk, germany), bombers, null);
tracker.getBattleRecords().addBattle(british, battle.getBattleId(), germany, battle.getBattleType());
final ITestDelegateBridge bridge = getDelegateBridge(british);
bridge.setRemote(dummyPlayer);
// aa guns rolls 0 and hits
bridge.setRandomSource(new ScriptedRandomSource(new int[] { 0, ScriptedRandomSource.ERROR }));
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, pusAfterRaid);
assertEquals(0, germany.getUnits().getMatches(Matches.unitIsOwnedBy(british)).size());
}
use of games.strategy.engine.data.ITestDelegateBridge in project triplea by triplea-game.
the class RevisedTest method testTransportAttackSubNonCombat.
@Test
public void testTransportAttackSubNonCombat() {
final Territory sz1 = territory("1 Sea Zone", gameData);
final Territory sz8 = territory("8 Sea Zone", gameData);
final PlayerID british = british(gameData);
// german sub tries to attack a transport in non combat
// should be an error
final MoveDelegate moveDelegate = (MoveDelegate) gameData.getDelegateList().getDelegate("move");
final ITestDelegateBridge bridge = getDelegateBridge(british);
bridge.setStepName("NonCombatMove");
moveDelegate.setDelegateBridgeAndPlayer(bridge);
moveDelegate.start();
final String error = moveDelegate(gameData).move(sz8.getUnits().getUnits(), new Route(sz1, sz8));
assertError(error);
}
use of games.strategy.engine.data.ITestDelegateBridge in project triplea by triplea-game.
the class RevisedTest method testLoadAlliedTransports.
@Test
public void testLoadAlliedTransports() {
final PlayerID british = british(gameData);
final PlayerID americans = americans(gameData);
final Territory uk = territory("United Kingdom", gameData);
final ITestDelegateBridge bridge = getDelegateBridge(british);
bridge.setStepName("CombatMove");
moveDelegate(gameData).setDelegateBridgeAndPlayer(bridge);
moveDelegate(gameData).start();
// create 2 us infantry
addTo(uk, infantry(gameData).create(2, americans));
// try to load them on the british players turn
final Territory sz2 = territory("2 Sea Zone", gameData);
final String error = moveDelegate(gameData).move(uk.getUnits().getMatches(Matches.unitIsOwnedBy(americans)), new Route(uk, sz2), sz2.getUnits().getMatches(Matches.unitIsTransport()));
// should not be able to load on british turn, only on american turn
assertFalse(error == null);
}
use of games.strategy.engine.data.ITestDelegateBridge in project triplea by triplea-game.
the class RevisedTest method testRocketsDontFireInConquered.
@Test
public void testRocketsDontFireInConquered() {
final MoveDelegate move = moveDelegate(gameData);
final ITestDelegateBridge bridge = getDelegateBridge(germans(gameData));
bridge.setStepName("CombatMove");
bridge.setRemote(dummyPlayer);
move.setDelegateBridgeAndPlayer(bridge);
move.start();
// remove the russians units in caucasus so we can blitz
final Territory cauc = territory("Caucasus", gameData);
removeFrom(cauc, cauc.getUnits().getMatches(Matches.unitIsNotAa()));
// blitz
final Territory wr = territory("West Russia", gameData);
move(wr.getUnits().getMatches(Matches.unitCanBlitz()), new Route(wr, cauc));
final Set<Territory> fire = RocketsFireHelper.getTerritoriesWithRockets(gameData, germans(gameData));
// germany, WE, SE, but not caucusus
assertEquals(3, fire.size());
}
use of games.strategy.engine.data.ITestDelegateBridge in project triplea by triplea-game.
the class RevisedTest method testAttackDestroyerAndSubsAgainstSubAndDestroyer.
@Test
public void testAttackDestroyerAndSubsAgainstSubAndDestroyer() {
final String defender = "Germans";
final String attacker = "British";
final Territory attacked = territory("31 Sea Zone", gameData);
final Territory from = territory("32 Sea Zone", gameData);
// 1 sub and 1 destroyer attack 1 sub and 1 destroyer
// defender sneak attacks, not attacker
addTo(from, submarine(gameData).create(1, british(gameData)));
addTo(from, destroyer(gameData).create(1, british(gameData)));
addTo(attacked, submarine(gameData).create(1, germans(gameData)));
addTo(attacked, destroyer(gameData).create(1, germans(gameData)));
final ITestDelegateBridge bridge = getDelegateBridge(british(gameData));
bridge.setStepName("CombatMove");
moveDelegate(gameData).setDelegateBridgeAndPlayer(bridge);
moveDelegate(gameData).start();
move(from.getUnits().getUnits(), new Route(from, attacked));
moveDelegate(gameData).end();
final MustFightBattle battle = (MustFightBattle) AbstractMoveDelegate.getBattleTracker(gameData).getPendingBattle(attacked, false, null);
final List<String> steps = battle.determineStepStrings(true);
assertEquals(Arrays.asList(attacker + SUBS_FIRE, defender + SELECT_SUB_CASUALTIES, defender + SUBS_FIRE, attacker + SELECT_SUB_CASUALTIES, attacker + FIRE, defender + SELECT_CASUALTIES, defender + FIRE, attacker + SELECT_CASUALTIES, REMOVE_CASUALTIES, attacker + SUBS_SUBMERGE, defender + SUBS_SUBMERGE, attacker + ATTACKER_WITHDRAW).toString(), steps.toString());
final List<IExecutable> execs = battle.getBattleExecutables(false);
final int attackSubs = getIndex(execs, MustFightBattle.AttackSubs.class);
final int defendSubs = getIndex(execs, MustFightBattle.DefendSubs.class);
assertTrue(attackSubs < defendSubs);
when(dummyPlayer.selectCasualties(any(), any(), anyInt(), any(), any(), any(), any(), any(), any(), anyBoolean(), any(), any(), any(), any(), anyBoolean())).thenAnswer(invocation -> {
final Collection<Unit> selectFrom = invocation.getArgument(0);
return new CasualtyDetails(Collections.singletonList(selectFrom.iterator().next()), new ArrayList<>(), false);
});
bridge.setRemote(dummyPlayer);
final ScriptedRandomSource randomSource = new ScriptedRandomSource(0, 0, 0, 0, ScriptedRandomSource.ERROR);
bridge.setRandomSource(randomSource);
battle.fight(bridge);
assertEquals(4, randomSource.getTotalRolled());
assertEquals(0, attacked.getUnits().size());
}
Aggregations