use of games.strategy.engine.data.UnitType in project triplea by triplea-game.
the class RevisedTest method testLoadDependencies.
@Test
public void testLoadDependencies() {
final Territory sz5 = gameData.getMap().getTerritory("5 Sea Zone");
final Territory eastEurope = gameData.getMap().getTerritory("Eastern Europe");
final Territory norway = gameData.getMap().getTerritory("Norway");
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);
// load the transport
String error = moveDelegate.move(infantry, eeToSz5, Collections.singletonList(transport));
assertNull(error, error);
final Route sz5ToNorway = new Route();
sz5ToNorway.setStart(sz5);
sz5ToNorway.add(norway);
// move the infantry in two steps
error = moveDelegate.move(infantry.subList(0, 1), sz5ToNorway);
assertNull(error);
error = moveDelegate.move(infantry.subList(1, 2), sz5ToNorway);
assertNull(error);
assertEquals(3, moveDelegate.getMovesMade().size());
// the load
final UndoableMove move1 = moveDelegate.getMovesMade().get(0);
// the first unload
// AbstractUndoableMove move2 = moveDelegate.getMovesMade().get(0);
// the second unload must be done first
assertFalse(move1.getcanUndo());
error = moveDelegate.undoMove(2);
assertNull(error);
// the second unload must be done first
assertFalse(move1.getcanUndo());
error = moveDelegate.undoMove(1);
assertNull(error);
// we can now be undone
assertTrue(move1.getcanUndo());
}
use of games.strategy.engine.data.UnitType 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.UnitType 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.UnitType 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.UnitType 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