use of games.strategy.engine.data.ITestDelegateBridge in project triplea by triplea-game.
the class AirThatCantLandUtilTest method testCanLandNeighborLandWithRetreatedBattleV2.
@Test
public void testCanLandNeighborLandWithRetreatedBattleV2() {
final PlayerID japanese = GameDataTestUtil.japanese(gameData);
final PlayerID americans = GameDataTestUtil.americans(gameData);
final ITestDelegateBridge bridge = getDelegateBridge(japanese);
// Get necessary sea zones and unit types for this test
final Territory sz9 = gameData.getMap().getTerritory("9 Sea Zone");
final Territory eastCanada = gameData.getMap().getTerritory("Eastern Canada");
final Territory sz11 = gameData.getMap().getTerritory("11 Sea Zone");
final UnitType subType = GameDataTestUtil.submarine(gameData);
final UnitType carrierType = GameDataTestUtil.carrier(gameData);
final UnitType fighterType = GameDataTestUtil.fighter(gameData);
final UnitType transportType = GameDataTestUtil.transport(gameData);
final UnitType infantryType = GameDataTestUtil.infantry(gameData);
// Add units for the test
gameData.performChange(ChangeFactory.addUnits(sz11, subType.create(1, japanese)));
gameData.performChange(ChangeFactory.addUnits(sz11, transportType.create(1, japanese)));
gameData.performChange(ChangeFactory.addUnits(sz11, infantryType.create(1, japanese)));
gameData.performChange(ChangeFactory.addUnits(sz9, carrierType.create(1, americans)));
gameData.performChange(ChangeFactory.addUnits(sz9, fighterType.create(2, americans)));
// we need to initialize the original owner
final InitializationDelegate initDel = (InitializationDelegate) gameData.getDelegateList().getDelegate("initDelegate");
initDel.setDelegateBridgeAndPlayer(bridge);
initDel.start();
initDel.end();
// Get total number of defending units before the battle
final int preCountCanada = eastCanada.getUnits().size();
final int preCountAirSz9 = sz9.getUnits().getMatches(Matches.unitIsAir()).size();
// now move to attack
final MoveDelegate moveDelegate = (MoveDelegate) gameData.getDelegateList().getDelegate("move");
bridge.setStepName("CombatMove");
moveDelegate.setDelegateBridgeAndPlayer(bridge);
moveDelegate.start();
moveDelegate.move(sz11.getUnits().getUnits(), gameData.getMap().getRoute(sz11, sz9));
moveDelegate.move(sz9.getUnits().getUnits(infantryType, 1), gameData.getMap().getRoute(sz9, eastCanada));
moveDelegate.end();
// fight the battle
final BattleDelegate battle = (BattleDelegate) gameData.getDelegateList().getDelegate("battle");
battle.setDelegateBridgeAndPlayer(bridge);
battle.start();
bridge.setRandomSource(new ScriptedRandomSource(new int[] { 0, 0, 0 }));
bridge.setRemote(getDummyPlayer());
fight(battle, sz9, false);
battle.end();
// Get the total number of units that should be left after the planes retreat
final int expectedCountCanada = eastCanada.getUnits().size();
final int postCountInt = preCountCanada + preCountAirSz9;
// Compare the expected count with the actual number of units in landing zone
assertEquals(expectedCountCanada, postCountInt);
}
use of games.strategy.engine.data.ITestDelegateBridge in project triplea by triplea-game.
the class BigWorldTest method testCanalMovementNotStartingInCanalZone.
@Test
public void testCanalMovementNotStartingInCanalZone() {
final Territory sz28 = territory("SZ 28 Eastern Mediterranean", gameData);
final Territory sz27 = territory("SZ 27 Aegean Sea", gameData);
final Territory sz29 = territory("SZ 29 Black Sea", gameData);
final ITestDelegateBridge bridge = getDelegateBridge(british(gameData), gameData);
bridge.setStepName("CombatMove");
final MoveDelegate moveDelegate = moveDelegate(gameData);
moveDelegate.setDelegateBridgeAndPlayer(bridge);
moveDelegate.start();
final String error = moveDelegate.move(sz28.getUnits().getUnits(), new Route(sz28, sz27, sz29));
assertError(error);
}
use of games.strategy.engine.data.ITestDelegateBridge in project triplea by triplea-game.
the class WW2V3Year41Test method testCanRetreatIntoBlitzedTerritory.
@Test
public void testCanRetreatIntoBlitzedTerritory() {
final Territory eastPoland = territory("East Poland", gameData);
final Territory ukraine = territory("Ukraine", gameData);
final Territory poland = territory("Poland", gameData);
// remove all units from east poland
removeFrom(eastPoland, eastPoland.getUnits().getUnits());
final MoveDelegate moveDelegate = moveDelegate(gameData);
final ITestDelegateBridge delegateBridge = getDelegateBridge(germans(gameData));
delegateBridge.setStepName("CombatMove");
moveDelegate.setDelegateBridgeAndPlayer(delegateBridge);
moveDelegate.start();
final Territory bulgaria = territory("Bulgaria Romania", gameData);
// attack from bulgraia
move(bulgaria.getUnits().getUnits(), new Route(bulgaria, ukraine));
// add a blitz attack
move(poland.getUnits().getMatches(Matches.unitCanBlitz()), new Route(poland, eastPoland, ukraine));
// we should not be able to retreat to east poland!
// that territory was just conquered
final MustFightBattle battle = (MustFightBattle) AbstractMoveDelegate.getBattleTracker(gameData).getPendingBattle(ukraine, false, null);
assertTrue(battle.getAttackerRetreatTerritories().contains(eastPoland));
}
use of games.strategy.engine.data.ITestDelegateBridge in project triplea by triplea-game.
the class WW2V3Year41Test method testMoveParatroopersAsNonPartroops.
@Test
public void testMoveParatroopersAsNonPartroops() {
// move a bomber and a paratrooper
// one step, but as a normal movement
final PlayerID germans = germans(gameData);
final Territory germany = territory("Germany", gameData);
final Territory nwe = territory("Northwestern Europe", gameData);
final ITestDelegateBridge bridge = getDelegateBridge(germans);
bridge.setStepName("CombatMove");
moveDelegate(gameData).setDelegateBridgeAndPlayer(bridge);
moveDelegate(gameData).start();
TechAttachment.get(germans).setParatroopers("true");
List<Unit> paratrooper = germany.getUnits().getMatches(Matches.unitIsAirTransportable());
paratrooper = paratrooper.subList(0, 1);
final List<Unit> bomberAndParatroop = new ArrayList<>(paratrooper);
bomberAndParatroop.addAll(germany.getUnits().getMatches(Matches.unitIsAirTransport()));
// move to nwe, this is a valid move, and it not a partroop move
move(bomberAndParatroop, new Route(germany, nwe));
}
use of games.strategy.engine.data.ITestDelegateBridge in project triplea by triplea-game.
the class WW2V3Year41Test method testAirCanLandWithAlliedFighters.
@Test
public void testAirCanLandWithAlliedFighters() {
// germany owns madagascar, with 2 fighters in it
// also 1 carrier, and 1 allied fighter in sz 40
// the fighters should not be able to move from madagascar
// to sz 40, since with the allied fighter, their is no room
// on the carrier
final Territory madagascar = territory("French Madagascar", gameData);
final PlayerID germans = germans(gameData);
madagascar.setOwner(germans);
final Territory sz40 = territory("40 Sea Zone", gameData);
addTo(sz40, carrier(gameData).create(1, germans));
addTo(sz40, fighter(gameData).create(1, italians(gameData)));
addTo(madagascar, fighter(gameData).create(2, germans));
final Route route = gameData.getMap().getRoute(madagascar, sz40);
final ITestDelegateBridge bridge = getDelegateBridge(germans);
bridge.setStepName("CombatMove");
moveDelegate(gameData).setDelegateBridgeAndPlayer(bridge);
moveDelegate(gameData).start();
// don't allow kamikaze
bridge.setRemote(dummyPlayer);
final String error = moveDelegate(gameData).move(madagascar.getUnits().getUnits(), route);
assertError(error);
}
Aggregations