Search in sources :

Example 46 with UnitType

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());
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) UnitType(games.strategy.engine.data.UnitType) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) TripleAUnit(games.strategy.triplea.TripleAUnit) Unit(games.strategy.engine.data.Unit) TripleAUnit(games.strategy.triplea.TripleAUnit) Route(games.strategy.engine.data.Route) Test(org.junit.jupiter.api.Test)

Example 47 with UnitType

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));
}
Also used : UnitAttachment(games.strategy.triplea.attachments.UnitAttachment) PlayerID(games.strategy.engine.data.PlayerID) UnitType(games.strategy.engine.data.UnitType) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) Test(org.junit.jupiter.api.Test)

Example 48 with UnitType

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());
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) UnitType(games.strategy.engine.data.UnitType) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) TripleAUnit(games.strategy.triplea.TripleAUnit) Unit(games.strategy.engine.data.Unit) TripleAUnit(games.strategy.triplea.TripleAUnit) Route(games.strategy.engine.data.Route) Test(org.junit.jupiter.api.Test)

Example 49 with UnitType

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);
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) UnitType(games.strategy.engine.data.UnitType) Change(games.strategy.engine.data.Change) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) TripleAUnit(games.strategy.triplea.TripleAUnit) Unit(games.strategy.engine.data.Unit) TripleAUnit(games.strategy.triplea.TripleAUnit) Route(games.strategy.engine.data.Route) Test(org.junit.jupiter.api.Test)

Example 50 with UnitType

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));
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) UnitType(games.strategy.engine.data.UnitType) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) ScriptedRandomSource(games.strategy.engine.random.ScriptedRandomSource) Unit(games.strategy.engine.data.Unit) TripleAUnit(games.strategy.triplea.TripleAUnit) Test(org.junit.jupiter.api.Test)

Aggregations

UnitType (games.strategy.engine.data.UnitType)211 Test (org.junit.jupiter.api.Test)108 IntegerMap (games.strategy.util.IntegerMap)86 Route (games.strategy.engine.data.Route)76 Unit (games.strategy.engine.data.Unit)76 PlayerID (games.strategy.engine.data.PlayerID)64 Territory (games.strategy.engine.data.Territory)58 TripleAUnit (games.strategy.triplea.TripleAUnit)49 ArrayList (java.util.ArrayList)44 ITestDelegateBridge (games.strategy.engine.data.ITestDelegateBridge)36 GameParseException (games.strategy.engine.data.GameParseException)29 ScriptedRandomSource (games.strategy.engine.random.ScriptedRandomSource)23 UnitAttachment (games.strategy.triplea.attachments.UnitAttachment)21 HashSet (java.util.HashSet)17 GameData (games.strategy.engine.data.GameData)15 Change (games.strategy.engine.data.Change)14 CompositeChange (games.strategy.engine.data.CompositeChange)14 Resource (games.strategy.engine.data.Resource)13 NamedAttachable (games.strategy.engine.data.NamedAttachable)11 ProductionRule (games.strategy.engine.data.ProductionRule)11