use of games.strategy.engine.data.Route in project triplea by triplea-game.
the class WW2V3Year41Test method testOccupiedTerrOfAttachmentWithCapital.
@Test
public void testOccupiedTerrOfAttachmentWithCapital() throws GameParseException {
// Set up test
final PlayerID british = GameDataTestUtil.british(gameData);
final ITestDelegateBridge delegateBridge = getDelegateBridge(british(gameData));
// Set up the move delegate
final MoveDelegate moveDelegate = moveDelegate(gameData);
delegateBridge.setStepName("CombatMove");
moveDelegate(gameData).setDelegateBridgeAndPlayer(delegateBridge);
moveDelegate(gameData).start();
// Set up the territories
final Territory hupeh = territory("Hupeh", gameData);
final Territory kiangsu = territory("Kiangsu", gameData);
final Territory mongolia = territory("Mongolia", gameData);
// Remove original capital
final TerritoryAttachment taMongolia = TerritoryAttachment.get(mongolia);
final TerritoryAttachment taKiangsu = TerritoryAttachment.get(kiangsu);
taMongolia.setCapital(null);
// Set as NEW capital
taKiangsu.setCapital(Constants.PLAYER_NAME_CHINESE);
// Remove all units
removeFrom(kiangsu, kiangsu.getUnits().getUnits());
removeFrom(hupeh, hupeh.getUnits().getUnits());
// Set up the unit types
addTo(hupeh, infantry(gameData).create(1, british));
// Get units
final Collection<Unit> moveUnits = hupeh.getUnits().getUnits();
// Get Owner prior to battle
final String preOwner = kiangsu.getOwner().getName();
assertEquals(Constants.PLAYER_NAME_JAPANESE, preOwner);
// add a VALID attack
final String validResults = moveDelegate.move(moveUnits, new Route(hupeh, kiangsu));
assertValid(validResults);
// Ensure owner after attack doesn't match attacker
final String postOwner = kiangsu.getOwner().getName();
assertNotSame(Constants.PLAYER_NAME_BRITISH, postOwner);
// Check that original owner is now owner
assertEquals(Constants.PLAYER_NAME_CHINESE, postOwner);
}
use of games.strategy.engine.data.Route in project triplea by triplea-game.
the class WW2V3Year41Test method testAttackSubsOnSubs.
@Test
public void testAttackSubsOnSubs() {
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 attacks 1 sub
addTo(from, submarine(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_SUBMERGE, defender + SUBS_SUBMERGE, attacker + SUBS_FIRE, defender + SELECT_SUB_CASUALTIES, defender + SUBS_FIRE, attacker + SELECT_SUB_CASUALTIES, REMOVE_SNEAK_ATTACK_CASUALTIES, REMOVE_CASUALTIES, attacker + ATTACKER_WITHDRAW).toString(), steps.toString());
bridge.setRemote(dummyPlayer);
// fight, each sub should fire
// and hit
final ScriptedRandomSource randomSource = new ScriptedRandomSource(0, 0, ScriptedRandomSource.ERROR);
bridge.setRandomSource(randomSource);
battle.fight(bridge);
assertEquals(2, randomSource.getTotalRolled());
assertTrue(attacked.getUnits().isEmpty());
}
use of games.strategy.engine.data.Route in project triplea by triplea-game.
the class WW2V3Year41Test method testCarrierWithAlliedPlanes.
@Test
public void testCarrierWithAlliedPlanes() {
final Territory sz8 = territory("8 Sea Zone", gameData);
final Territory sz1 = territory("1 Sea Zone", gameData);
addTo(sz8, carrier(gameData).create(1, british(gameData)));
addTo(sz8, fighter(gameData).create(1, americans(gameData)));
final Route route = new Route(sz8, sz1);
final ITestDelegateBridge bridge = getDelegateBridge(british(gameData));
bridge.setStepName("CombatMove");
moveDelegate(gameData).setDelegateBridgeAndPlayer(bridge);
moveDelegate(gameData).start();
move(sz8.getUnits().getUnits(), route);
// make sure the fighter moved
assertTrue(sz8.getUnits().getUnits().isEmpty());
assertFalse(sz1.getUnits().getMatches(Matches.unitIsAir()).isEmpty());
}
use of games.strategy.engine.data.Route in project triplea by triplea-game.
the class WW2V3Year41Test method testParatroopsWalkOnWater.
@Test
public void testParatroopsWalkOnWater() {
final PlayerID germans = germans(gameData);
final Territory france = territory("France", gameData);
TechAttachment.get(germans).setParatroopers("true");
final Route r = gameData.getMap().getRoute(france, territory("7 Sea Zone", gameData));
final Collection<Unit> paratroopers = france.getUnits().getMatches(Matches.unitIsAirTransportable());
assertFalse(paratroopers.isEmpty());
final MoveValidationResult results = MoveValidator.validateMove(paratroopers, r, germans, Collections.emptyList(), new HashMap<>(), false, null, gameData);
assertFalse(results.isMoveValid());
}
use of games.strategy.engine.data.Route in project triplea by triplea-game.
the class WW2V3Year41Test method testCantTransportParatroopersWithBombersThatMovedPreviously.
@Test
public void testCantTransportParatroopersWithBombersThatMovedPreviously() {
// make sure bombers can't move then pick up paratroopers
final PlayerID germans = germans(gameData);
final Territory germany = territory("Germany", gameData);
final Territory bulgaria = territory("Bulgaria Romania", gameData);
final Territory poland = territory("Poland", gameData);
final Territory ukraine = territory("Ukraine", gameData);
final ITestDelegateBridge bridge = getDelegateBridge(germans);
bridge.setStepName("CombatMove");
moveDelegate(gameData).setDelegateBridgeAndPlayer(bridge);
moveDelegate(gameData).start();
TechAttachment.get(germans).setParatroopers("true");
// Move the bomber first
final List<Unit> bomber = germany.getUnits().getMatches(Matches.unitIsAirTransport());
move(bomber, new Route(germany, poland));
// Pick up a paratrooper
final List<Unit> bomberAndParatroop = new ArrayList<>(bomber);
bomberAndParatroop.addAll(poland.getUnits().getUnits(GameDataTestUtil.infantry(gameData), 1));
// move them
final String error = moveDelegate(gameData).move(bomberAndParatroop, new Route(poland, bulgaria, ukraine));
assertError(error);
}
Aggregations