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));
}
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"));
}
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);
}
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);
}
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());
}
Aggregations