use of games.strategy.engine.data.Route in project triplea by triplea-game.
the class WW2V3Year41Test 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
// no sneak attacks
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, attacker + FIRE, defender + SELECT_CASUALTIES, defender + SUBS_FIRE, attacker + SELECT_SUB_CASUALTIES, defender + FIRE, attacker + SELECT_CASUALTIES, REMOVE_CASUALTIES, attacker + ATTACKER_WITHDRAW).toString(), steps.toString());
when(dummyPlayer.selectCasualties(any(), any(), anyInt(), any(), any(), any(), any(), any(), any(), anyBoolean(), any(), any(), any(), any(), anyBoolean())).thenAnswer(new Answer<CasualtyDetails>() {
@Override
public CasualtyDetails answer(final InvocationOnMock invocation) {
final Collection<Unit> selectFrom = invocation.getArgument(0);
return new CasualtyDetails(Arrays.asList(selectFrom.iterator().next()), new ArrayList<>(), false);
}
});
bridge.setRemote(dummyPlayer);
// attacking subs sneak attack and hit
// no chance to return fire
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());
}
use of games.strategy.engine.data.Route in project triplea by triplea-game.
the class WW2V3Year41Test method testFighterLandsWhereCarrierCanBePlaced.
@Test
public void testFighterLandsWhereCarrierCanBePlaced() {
final PlayerID germans = germans(gameData);
// germans have 1 carrier to place
addTo(germans, carrier(gameData).create(1, germans), gameData);
// start the move phase
final ITestDelegateBridge bridge = getDelegateBridge(germans);
bridge.setStepName("CombatMove");
moveDelegate(gameData).setDelegateBridgeAndPlayer(bridge);
moveDelegate(gameData).start();
bridge.setRemote(dummyPlayer);
// the fighter should be able to move and hover in the sea zone
// the fighter has no movement left
final Territory neEurope = territory("Northwestern Europe", gameData);
final Route route = new Route(neEurope, territory("Germany", gameData), territory("Poland", gameData), territory("Baltic States", gameData), territory("5 Sea Zone", gameData));
// the fighter should be able to move, and hover in the sea zone until the carrier is placed
move(neEurope.getUnits().getMatches(Matches.unitIsAir()), route);
}
use of games.strategy.engine.data.Route in project triplea by triplea-game.
the class WW2V3Year42Test method testLingeringSeaUnitsJoinBattle.
@Test
public void testLingeringSeaUnitsJoinBattle() {
final Territory sz5 = territory("5 Sea Zone", gameData);
final Territory sz6 = territory("6 Sea Zone", gameData);
final Territory sz7 = territory("7 Sea Zone", gameData);
// add a russian battlship
addTo(sz5, battleship(gameData).create(1, russians(gameData)));
final ITestDelegateBridge bridge = getDelegateBridge(germans(gameData));
bridge.setStepName("CombatMove");
moveDelegate(gameData).setDelegateBridgeAndPlayer(bridge);
moveDelegate(gameData).start();
// attack with a german sub
move(sz7.getUnits().getUnits(), new Route(sz7, sz6, sz5));
moveDelegate(gameData).end();
// adding of lingering units was moved from end of combat-move phase, to start of battle phase
battleDelegate(gameData).setDelegateBridgeAndPlayer(bridge);
BattleDelegate.doInitialize(battleDelegate(gameData).getBattleTracker(), bridge);
// all units in sz5 should be involved in the battle
final MustFightBattle mfb = (MustFightBattle) MoveDelegate.getBattleTracker(gameData).getPendingBattle(sz5, false, null);
assertEquals(5, mfb.getAttackingUnits().size());
}
use of games.strategy.engine.data.Route in project triplea by triplea-game.
the class WW2V3Year42Test method testBombAndAttackEmptyTerritory.
@Test
public void testBombAndAttackEmptyTerritory() {
final Territory karrelia = territory("Karelia S.S.R.", gameData);
final Territory baltic = territory("Baltic States", gameData);
final Territory sz5 = territory("5 Sea Zone", gameData);
final Territory germany = territory("Germany", gameData);
final PlayerID germans = germans(gameData);
final MoveDelegate moveDelegate = (MoveDelegate) gameData.getDelegateList().getDelegate("move");
final ITestDelegateBridge bridge = getDelegateBridge(germans);
bridge.setStepName("CombatMove");
moveDelegate.setDelegateBridgeAndPlayer(bridge);
moveDelegate.start();
final ITripleAPlayer dummyPlayer = mock(ITripleAPlayer.class);
when(dummyPlayer.shouldBomberBomb(any())).thenReturn(true);
bridge.setRemote(dummyPlayer);
// remove the russian units
removeFrom(karrelia, karrelia.getUnits().getMatches(Matches.unitCanBeDamaged().negate()));
// move the bomber to attack
move(germany.getUnits().getMatches(Matches.unitIsStrategicBomber()), new Route(germany, sz5, karrelia));
// move an infantry to invade
move(baltic.getUnits().getMatches(Matches.unitIsLandTransportable()), new Route(baltic, karrelia));
final BattleTracker battleTracker = MoveDelegate.getBattleTracker(gameData);
// we should have a pending land battle, and a pending bombing raid
assertNotNull(battleTracker.getPendingBattle(karrelia, false, null));
assertNotNull(battleTracker.getPendingBattle(karrelia, true, null));
// the territory should not be conquered
assertEquals(karrelia.getOwner(), russians(gameData));
}
use of games.strategy.engine.data.Route in project triplea by triplea-game.
the class WW2V3Year42Test method testLingeringFightersAndALliedUnitsJoinBattle.
@Test
public void testLingeringFightersAndALliedUnitsJoinBattle() {
final Territory sz5 = territory("5 Sea Zone", gameData);
final Territory sz6 = territory("6 Sea Zone", gameData);
final Territory sz7 = territory("7 Sea Zone", gameData);
// add a russian battlship
addTo(sz5, battleship(gameData).create(1, russians(gameData)));
// add an allied carrier and a fighter
addTo(sz5, carrier(gameData).create(1, italians(gameData)));
addTo(sz5, fighter(gameData).create(1, germans(gameData)));
final ITestDelegateBridge bridge = getDelegateBridge(germans(gameData));
bridge.setStepName("CombatMove");
moveDelegate(gameData).setDelegateBridgeAndPlayer(bridge);
moveDelegate(gameData).start();
// attack with a german sub
move(sz7.getUnits().getUnits(), new Route(sz7, sz6, sz5));
moveDelegate(gameData).end();
// adding of lingering units was moved from end of combat-move phase, to start of battle phase
battleDelegate(gameData).setDelegateBridgeAndPlayer(bridge);
BattleDelegate.doInitialize(battleDelegate(gameData).getBattleTracker(), bridge);
// all units in sz5 should be involved in the battle
// except the italian carrier
final MustFightBattle mfb = (MustFightBattle) MoveDelegate.getBattleTracker(gameData).getPendingBattle(sz5, false, null);
assertEquals(6, mfb.getAttackingUnits().size());
}
Aggregations