use of games.strategy.engine.data.ITestDelegateBridge in project triplea by triplea-game.
the class RevisedTest method testLoadUndo.
@Test
public void testLoadUndo() {
final Territory sz5 = gameData.getMap().getTerritory("5 Sea Zone");
final Territory eastEurope = gameData.getMap().getTerritory("Eastern Europe");
final UnitType infantryType = GameDataTestUtil.infantry(gameData);
final PlayerID germans = GameDataTestUtil.germans(gameData);
final MoveDelegate moveDelegate = (MoveDelegate) gameData.getDelegateList().getDelegate("move");
final ITestDelegateBridge bridge = getDelegateBridge(germans);
bridge.setStepName("CombatMove");
moveDelegate.setDelegateBridgeAndPlayer(bridge);
moveDelegate.start();
final Route eeToSz5 = new Route();
eeToSz5.setStart(eastEurope);
eeToSz5.add(sz5);
// load the transport in the baltic
final List<Unit> infantry = eastEurope.getUnits().getMatches(Matches.unitIsOfType(infantryType));
assertEquals(2, infantry.size());
final TripleAUnit transport = (TripleAUnit) sz5.getUnits().getMatches(Matches.unitIsTransport()).get(0);
final String error = moveDelegate.move(infantry, eeToSz5, Collections.singletonList(transport));
assertNull(error, error);
// make sure the transport was loaded
assertTrue(moveDelegate.getMovesMade().get(0).wasTransportLoaded(transport));
// make sure it was laoded
assertTrue(transport.getTransporting().containsAll(infantry));
assertTrue(((TripleAUnit) infantry.get(0)).getWasLoadedThisTurn());
// udo the move
moveDelegate.undoMove(0);
// make sure that loaded is not set
assertTrue(transport.getTransporting().isEmpty());
assertFalse(((TripleAUnit) infantry.get(0)).getWasLoadedThisTurn());
}
use of games.strategy.engine.data.ITestDelegateBridge in project triplea by triplea-game.
the class RevisedTest method testBidPlace.
@Test
public void testBidPlace() {
final ITestDelegateBridge bridge = getDelegateBridge(british(gameData));
bridge.setStepName("BidPlace");
bidPlaceDelegate(gameData).setDelegateBridgeAndPlayer(bridge);
bidPlaceDelegate(gameData).start();
// create 20 british infantry
addTo(british(gameData), infantry(gameData).create(20, british(gameData)), gameData);
final Territory uk = territory("United Kingdom", gameData);
final Collection<Unit> units = british(gameData).getUnits().getUnits();
final PlaceableUnits placeable = bidPlaceDelegate(gameData).getPlaceableUnits(units, uk);
assertEquals(20, placeable.getMaxUnits());
assertNull(placeable.getErrorMessage());
final String error = bidPlaceDelegate(gameData).placeUnits(units, uk);
assertNull(error);
}
use of games.strategy.engine.data.ITestDelegateBridge in project triplea by triplea-game.
the class RevisedTest method testLoadUnloadAlliedTransport.
@Test
public void testLoadUnloadAlliedTransport() {
// you cant load and unload an allied transport the same turn
final UnitType infantryType = GameDataTestUtil.infantry(gameData);
final Territory eastEurope = gameData.getMap().getTerritory("Eastern Europe");
// add japanese infantry to eastern europe
final PlayerID japanese = GameDataTestUtil.japanese(gameData);
final Change change = ChangeFactory.addUnits(eastEurope, infantryType.create(1, japanese));
gameData.performChange(change);
final Territory sz5 = gameData.getMap().getTerritory("5 Sea Zone");
final MoveDelegate moveDelegate = (MoveDelegate) gameData.getDelegateList().getDelegate("move");
final ITestDelegateBridge bridge = getDelegateBridge(japanese);
bridge.setStepName("CombatMove");
moveDelegate.setDelegateBridgeAndPlayer(bridge);
moveDelegate.start();
final Route eeToSz5 = new Route();
eeToSz5.setStart(eastEurope);
eeToSz5.add(sz5);
// load the transport in the baltic
final List<Unit> infantry = eastEurope.getUnits().getMatches(Matches.unitIsOfType(infantryType).and(Matches.unitIsOwnedBy(japanese)));
assertEquals(1, infantry.size());
final TripleAUnit transport = (TripleAUnit) sz5.getUnits().getMatches(Matches.unitIsTransport()).get(0);
String error = moveDelegate.move(infantry, eeToSz5, Collections.singletonList(transport));
assertNull(error, error);
// try to unload
final Route sz5ToEee = new Route();
sz5ToEee.setStart(sz5);
sz5ToEee.add(eastEurope);
error = moveDelegate.move(infantry, sz5ToEee);
assertEquals(MoveValidator.CANNOT_LOAD_AND_UNLOAD_AN_ALLIED_TRANSPORT_IN_THE_SAME_ROUND, error);
}
use of games.strategy.engine.data.ITestDelegateBridge in project triplea by triplea-game.
the class UnitComparatorTest method startCombatMoveFor.
private static void startCombatMoveFor(final PlayerID playerId, final GameData gameData) {
final MoveDelegate moveDelegate = moveDelegate(gameData);
final ITestDelegateBridge bridge = getDelegateBridge(playerId, gameData);
bridge.setStepName("CombatMove");
moveDelegate.setDelegateBridgeAndPlayer(bridge);
moveDelegate.start();
}
use of games.strategy.engine.data.ITestDelegateBridge in project triplea by triplea-game.
the class DiceRollTest method testAaLowLuckDifferentMovement.
@Test
public void testAaLowLuckDifferentMovement() {
GameDataTestUtil.makeGameLowLuck(gameData);
final Territory westRussia = gameData.getMap().getTerritory("West Russia");
final PlayerID russians = GameDataTestUtil.russians(gameData);
final PlayerID germans = GameDataTestUtil.germans(gameData);
final UnitType aaGunType = GameDataTestUtil.aaGun(gameData);
final List<Unit> aaGunList = aaGunType.create(1, germans);
GameDataTestUtil.addTo(westRussia, aaGunList);
final UnitType fighterType = GameDataTestUtil.fighter(gameData);
final List<Unit> fighterList = fighterType.create(6, russians);
TripleAUnit.get(fighterList.get(0)).setAlreadyMoved(1);
final ITestDelegateBridge bridge = getDelegateBridge(russians);
// aa hits at 0 (0 based)
bridge.setRandomSource(new ScriptedRandomSource(new int[] { ScriptedRandomSource.ERROR }));
final DiceRoll hit = DiceRoll.rollAa(CollectionUtils.getMatches(fighterList, Matches.unitIsOfTypes(UnitAttachment.get(aaGunList.iterator().next().getType()).getTargetsAa(gameData))), aaGunList, bridge, westRussia, true);
assertThat(hit.getHits(), is(1));
}
Aggregations