Search in sources :

Example 36 with UnitType

use of games.strategy.engine.data.UnitType in project triplea by triplea-game.

the class AirThatCantLandUtilTest method testCanLandNeighborLandV2.

@Test
public void testCanLandNeighborLandV2() {
    final PlayerID japanese = GameDataTestUtil.japanese(gameData);
    final PlayerID americans = GameDataTestUtil.americans(gameData);
    final ITestDelegateBridge bridge = getDelegateBridge(japanese);
    // we need to initialize the original owner
    final InitializationDelegate initDel = (InitializationDelegate) gameData.getDelegateList().getDelegate("initDelegate");
    initDel.setDelegateBridgeAndPlayer(bridge);
    initDel.start();
    initDel.end();
    // 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);
    // Add units for the test
    gameData.performChange(ChangeFactory.addUnits(sz11, subType.create(1, japanese)));
    gameData.performChange(ChangeFactory.addUnits(sz9, carrierType.create(1, americans)));
    gameData.performChange(ChangeFactory.addUnits(sz9, fighterType.create(1, americans)));
    // 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.end();
    // fight the battle
    final BattleDelegate battle = (BattleDelegate) gameData.getDelegateList().getDelegate("battle");
    battle.setDelegateBridgeAndPlayer(bridge);
    bridge.setRandomSource(new ScriptedRandomSource(new int[] { 0 }));
    bridge.setRemote(getDummyPlayer());
    battle.start();
    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);
}
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) Test(org.junit.jupiter.api.Test)

Example 37 with UnitType

use of games.strategy.engine.data.UnitType 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);
}
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) Test(org.junit.jupiter.api.Test)

Example 38 with UnitType

use of games.strategy.engine.data.UnitType in project triplea by triplea-game.

the class AiUtilsTest method testCost.

@Test
public void testCost() {
    final UnitType infantry = GameDataTestUtil.infantry(gameData);
    final PlayerID british = GameDataTestUtil.british(gameData);
    assertEquals(3, AiUtils.getCost(infantry, british, gameData));
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) UnitType(games.strategy.engine.data.UnitType) Test(org.junit.jupiter.api.Test)

Example 39 with UnitType

use of games.strategy.engine.data.UnitType in project triplea by triplea-game.

the class SimpleUnitPanel method addUnits.

private void addUnits(final PlayerID player, final int quantity, final NamedAttachable unit, final boolean damaged, final boolean disabled) {
    final JLabel label = new JLabel();
    label.setText(" x " + quantity);
    if (unit instanceof UnitType) {
        final Optional<ImageIcon> icon = uiContext.getUnitImageFactory().getIcon((UnitType) unit, player, damaged, disabled);
        icon.ifPresent(label::setIcon);
    } else if (unit instanceof Resource) {
        label.setIcon(uiContext.getResourceImageFactory().getIcon(unit, true));
    }
    add(label);
}
Also used : ImageIcon(javax.swing.ImageIcon) UnitType(games.strategy.engine.data.UnitType) Resource(games.strategy.engine.data.Resource) JLabel(javax.swing.JLabel)

Example 40 with UnitType

use of games.strategy.engine.data.UnitType in project triplea by triplea-game.

the class MyFormatterTest method unitsToText_ShouldPluralizeTextWhenMultipleUnitsOwnedBySamePlayer.

@Test
public void unitsToText_ShouldPluralizeTextWhenMultipleUnitsOwnedBySamePlayer() {
    final PlayerID playerId = newPlayerId("playerId");
    final UnitType unitType = newUnitType("unitType");
    final Collection<Unit> units = Arrays.asList(newUnit(unitType, playerId), newUnit(unitType, playerId));
    assertThat(MyFormatter.unitsToText(units), is("2 unitTypes owned by the playerId"));
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) UnitType(games.strategy.engine.data.UnitType) Unit(games.strategy.engine.data.Unit) 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