use of games.strategy.engine.data.ITestDelegateBridge in project triplea by triplea-game.
the class RevisedTest method testStratBombCasualtiesLowLuckManyBombers.
@Test
public void testStratBombCasualtiesLowLuckManyBombers() {
makeGameLowLuck(gameData);
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 = bomber(gameData).create(7, british);
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, next 5 dice are for the bombing raid cost for the
// surviving bombers
bridge.setRandomSource(new ScriptedRandomSource(new int[] { 0, 0, 0, 0, 0, 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 - 5, pusAfterRaid);
// 2 bombers get hit
assertEquals(5, germany.getUnits().getMatches(Matches.unitIsOwnedBy(british)).size());
}
use of games.strategy.engine.data.ITestDelegateBridge in project triplea by triplea-game.
the class RevisedTest method testMoveBadRoute.
@Test
public void testMoveBadRoute() {
final PlayerID british = british(gameData);
final Territory sz1 = gameData.getMap().getTerritory("1 Sea Zone");
final Territory sz11 = gameData.getMap().getTerritory("11 Sea Zone");
final Territory sz9 = gameData.getMap().getTerritory("9 Sea Zone");
final ITestDelegateBridge bridge = getDelegateBridge(british);
bridge.setStepName("NonCombatMove");
moveDelegate(gameData).setDelegateBridgeAndPlayer(bridge);
moveDelegate(gameData).start();
final String error = moveDelegate(gameData).move(sz1.getUnits().getUnits(), new Route(sz1, sz11, sz9));
assertTrue(error != null);
}
use of games.strategy.engine.data.ITestDelegateBridge in project triplea by triplea-game.
the class RevisedTest method testSubAdvance.
@Test
public void testSubAdvance() {
final UnitType sub = submarine(gameData);
final UnitAttachment attachment = UnitAttachment.get(sub);
final PlayerID japanese = japanese(gameData);
// before the advance, subs defend and attack at 2
assertEquals(2, attachment.getDefense(japanese));
assertEquals(2, attachment.getAttack(japanese));
final ITestDelegateBridge bridge = getDelegateBridge(japanese);
TechTracker.addAdvance(japanese, bridge, TechAdvance.findAdvance(TechAdvance.TECH_PROPERTY_SUPER_SUBS, gameData, japanese));
// after tech advance, this is now 3
assertEquals(2, attachment.getDefense(japanese));
assertEquals(3, attachment.getAttack(japanese));
}
use of games.strategy.engine.data.ITestDelegateBridge in project triplea by triplea-game.
the class RevisedTest method testSeaBattleNoSneakAttack.
@Test
public void testSeaBattleNoSneakAttack() {
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 destroyer attacks 1 destroyer
addTo(from, destroyer(gameData).create(1, british(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 + FIRE, defender + SELECT_CASUALTIES, defender + FIRE, attacker + SELECT_CASUALTIES, REMOVE_CASUALTIES, attacker + ATTACKER_WITHDRAW).toString(), steps.toString());
}
use of games.strategy.engine.data.ITestDelegateBridge in project triplea by triplea-game.
the class RevisedTest method testAttackDestroyerAndSubsAgainstSub.
@Test
public void testAttackDestroyerAndSubsAgainstSub() {
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
// 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)));
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, REMOVE_SNEAK_ATTACK_CASUALTIES, attacker + FIRE, defender + 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);
bridge.setRemote(dummyPlayer);
// attacking sub hits with sneak attack, but defending sub gets to return fire because it is a sub and this is
// revised rules
final ScriptedRandomSource randomSource = new ScriptedRandomSource(0, 0, ScriptedRandomSource.ERROR);
bridge.setRandomSource(randomSource);
battle.fight(bridge);
assertEquals(2, randomSource.getTotalRolled());
assertTrue(attacked.getUnits().getMatches(Matches.unitIsOwnedBy(germans(gameData))).isEmpty());
assertEquals(1, attacked.getUnits().size());
}
Aggregations