Search in sources :

Example 96 with PlayerID

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

the class WW2V3Year42Test method testBombAndAttackEmptyTerritory.

@Test
public void testBombAndAttackEmptyTerritory() {
    final Territory karrelia = territory("Karelia S.S.R.", gameData);
    final Territory baltic = territory("Baltic States", gameData);
    final Territory sz5 = territory("5 Sea Zone", gameData);
    final Territory germany = territory("Germany", gameData);
    final PlayerID germans = germans(gameData);
    final MoveDelegate moveDelegate = (MoveDelegate) gameData.getDelegateList().getDelegate("move");
    final ITestDelegateBridge bridge = getDelegateBridge(germans);
    bridge.setStepName("CombatMove");
    moveDelegate.setDelegateBridgeAndPlayer(bridge);
    moveDelegate.start();
    final ITripleAPlayer dummyPlayer = mock(ITripleAPlayer.class);
    when(dummyPlayer.shouldBomberBomb(any())).thenReturn(true);
    bridge.setRemote(dummyPlayer);
    // remove the russian units
    removeFrom(karrelia, karrelia.getUnits().getMatches(Matches.unitCanBeDamaged().negate()));
    // move the bomber to attack
    move(germany.getUnits().getMatches(Matches.unitIsStrategicBomber()), new Route(germany, sz5, karrelia));
    // move an infantry to invade
    move(baltic.getUnits().getMatches(Matches.unitIsLandTransportable()), new Route(baltic, karrelia));
    final BattleTracker battleTracker = MoveDelegate.getBattleTracker(gameData);
    // we should have a pending land battle, and a pending bombing raid
    assertNotNull(battleTracker.getPendingBattle(karrelia, false, null));
    assertNotNull(battleTracker.getPendingBattle(karrelia, true, null));
    // the territory should not be conquered
    assertEquals(karrelia.getOwner(), russians(gameData));
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) ITripleAPlayer(games.strategy.triplea.player.ITripleAPlayer) Route(games.strategy.engine.data.Route) Test(org.junit.jupiter.api.Test)

Example 97 with PlayerID

use of games.strategy.engine.data.PlayerID 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)

Example 98 with PlayerID

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

the class OddsCalculatorTest method testUnbalancedFight.

@Test
public void testUnbalancedFight() {
    final Territory germany = gameData.getMap().getTerritory("Germany");
    final Collection<Unit> defendingUnits = new ArrayList<>(germany.getUnits().getUnits());
    final PlayerID russians = GameDataTestUtil.russians(gameData);
    final PlayerID germans = GameDataTestUtil.germans(gameData);
    final List<Unit> attackingUnits = GameDataTestUtil.infantry(gameData).create(100, russians);
    final List<Unit> bombardingUnits = Collections.emptyList();
    final IOddsCalculator calculator = new OddsCalculator(gameData);
    final AggregateResults results = calculator.setCalculateDataAndCalculate(russians, germans, germany, attackingUnits, defendingUnits, bombardingUnits, TerritoryEffectHelper.getEffects(germany), 200);
    calculator.shutdown();
    assertTrue(results.getAttackerWinPercent() > 0.99);
    assertTrue(results.getDefenderWinPercent() < 0.1);
    assertTrue(results.getDrawPercent() < 0.1);
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) ArrayList(java.util.ArrayList) Unit(games.strategy.engine.data.Unit) Test(org.junit.jupiter.api.Test)

Example 99 with PlayerID

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

the class OddsCalculatorTest method testKeepOneAttackingLand.

@Test
public void testKeepOneAttackingLand() {
    // 1 bomber and 1 infantry attacking
    // 1 fighter
    // if one attacking inf must live, the odds
    // much worse
    final PlayerID germans = GameDataTestUtil.germans(gameData);
    final PlayerID british = GameDataTestUtil.british(gameData);
    final Territory eastCanada = gameData.getMap().getTerritory("Eastern Canada");
    final List<Unit> defendingUnits = GameDataTestUtil.fighter(gameData).create(1, british, false);
    final List<Unit> attackingUnits = GameDataTestUtil.infantry(gameData).create(1, germans, false);
    attackingUnits.addAll(GameDataTestUtil.bomber(gameData).create(1, germans, false));
    final List<Unit> bombardingUnits = Collections.emptyList();
    final IOddsCalculator calculator = new OddsCalculator(gameData);
    calculator.setKeepOneAttackingLandUnit(true);
    final AggregateResults results = calculator.setCalculateDataAndCalculate(germans, british, eastCanada, attackingUnits, defendingUnits, bombardingUnits, TerritoryEffectHelper.getEffects(eastCanada), 1000);
    calculator.shutdown();
    assertEquals(0.8, results.getAttackerWinPercent(), 0.10);
    assertEquals(0.16, results.getDefenderWinPercent(), 0.10);
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) Unit(games.strategy.engine.data.Unit) Test(org.junit.jupiter.api.Test)

Example 100 with PlayerID

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

the class MustFightBattleTest method testFightWithIsSuicideOnHit.

@Test
public void testFightWithIsSuicideOnHit() throws Exception {
    final GameData twwGameData = TestMapGameData.TWW.getGameData();
    // Create battle with 1 cruiser attacking 1 mine
    final PlayerID usa = GameDataTestUtil.usa(twwGameData);
    final PlayerID germany = GameDataTestUtil.germany(twwGameData);
    final Territory sz33 = territory("33 Sea Zone", twwGameData);
    addTo(sz33, GameDataTestUtil.americanCruiser(twwGameData).create(1, usa));
    final Territory sz40 = territory("40 Sea Zone", twwGameData);
    addTo(sz40, GameDataTestUtil.germanMine(twwGameData).create(1, germany));
    final ITestDelegateBridge bridge = GameDataTestUtil.getDelegateBridge(usa, twwGameData);
    bridge.setStepName("CombatMove");
    moveDelegate(twwGameData).setDelegateBridgeAndPlayer(bridge);
    moveDelegate(twwGameData).start();
    move(sz33.getUnits().getUnits(), new Route(sz33, sz40));
    moveDelegate(twwGameData).end();
    final MustFightBattle battle = (MustFightBattle) AbstractMoveDelegate.getBattleTracker(twwGameData).getPendingBattle(sz40, false, null);
    bridge.setRemote(dummyPlayer);
    // Set first roll to hit (mine AA) and check that both units are killed
    final ScriptedRandomSource randomSource = new ScriptedRandomSource(0, ScriptedRandomSource.ERROR);
    bridge.setRandomSource(randomSource);
    battle.fight(bridge);
    assertEquals(1, randomSource.getTotalRolled());
    assertEquals(0, sz40.getUnits().size());
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) GameData(games.strategy.engine.data.GameData) TestMapGameData(games.strategy.triplea.xml.TestMapGameData) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) ScriptedRandomSource(games.strategy.engine.random.ScriptedRandomSource) Route(games.strategy.engine.data.Route) Test(org.junit.jupiter.api.Test)

Aggregations

PlayerID (games.strategy.engine.data.PlayerID)323 Territory (games.strategy.engine.data.Territory)163 Unit (games.strategy.engine.data.Unit)133 Test (org.junit.jupiter.api.Test)122 TripleAUnit (games.strategy.triplea.TripleAUnit)104 ITestDelegateBridge (games.strategy.engine.data.ITestDelegateBridge)94 GameData (games.strategy.engine.data.GameData)90 ArrayList (java.util.ArrayList)79 UnitType (games.strategy.engine.data.UnitType)74 Route (games.strategy.engine.data.Route)67 ScriptedRandomSource (games.strategy.engine.random.ScriptedRandomSource)46 HashSet (java.util.HashSet)44 Change (games.strategy.engine.data.Change)29 CompositeChange (games.strategy.engine.data.CompositeChange)29 IntegerMap (games.strategy.util.IntegerMap)29 List (java.util.List)29 HashMap (java.util.HashMap)28 Collection (java.util.Collection)27 Resource (games.strategy.engine.data.Resource)25 UnitAttachment (games.strategy.triplea.attachments.UnitAttachment)23