use of games.strategy.engine.data.PlayerID in project triplea by triplea-game.
the class WW2V3Year41Test method testAaCasualtiesLowLuckMixedRadar.
@Test
public void testAaCasualtiesLowLuckMixedRadar() {
// moved from BattleCalculatorTest because "revised" does not have "radar"
final PlayerID british = GameDataTestUtil.british(gameData);
final ITestDelegateBridge bridge = getDelegateBridge(british);
makeGameLowLuck(gameData);
// setSelectAACasualties(data, false);
givePlayerRadar(germans(gameData));
// 3 bombers and 3 fighters
final Collection<Unit> planes = bomber(gameData).create(3, british(gameData));
planes.addAll(fighter(gameData).create(3, british(gameData)));
final Collection<Unit> defendingAa = territory("Germany", gameData).getUnits().getMatches(Matches.unitIsAaForAnything());
// don't allow rolling, 6 of each is deterministic
bridge.setRandomSource(new ScriptedRandomSource(new int[] { ScriptedRandomSource.ERROR }));
final DiceRoll roll = DiceRoll.rollAa(CollectionUtils.getMatches(planes, Matches.unitIsOfTypes(UnitAttachment.get(defendingAa.iterator().next().getType()).getTargetsAa(gameData))), defendingAa, bridge, territory("Germany", gameData), true);
final Collection<Unit> casualties = BattleCalculator.getAaCasualties(false, planes, planes, defendingAa, defendingAa, roll, bridge, null, null, null, territory("Germany", gameData), null, false, null).getKilled();
assertEquals(2, casualties.size());
// should be 1 fighter and 1 bomber
assertEquals(1, CollectionUtils.countMatches(casualties, Matches.unitIsStrategicBomber()));
assertEquals(1, CollectionUtils.countMatches(casualties, Matches.unitIsStrategicBomber().negate()));
}
use of games.strategy.engine.data.PlayerID in project triplea by triplea-game.
the class WW2V3Year41Test method testAaCasualtiesLowLuckMixedWithRollingRadar.
@Test
public void testAaCasualtiesLowLuckMixedWithRollingRadar() {
// moved from BattleCalculatorTest because "revised" does not have "radar"
final PlayerID british = GameDataTestUtil.british(gameData);
final ITestDelegateBridge bridge = getDelegateBridge(british);
makeGameLowLuck(gameData);
// setSelectAACasualties(data, false);
givePlayerRadar(germans(gameData));
// 4 bombers and 4 fighters
final Collection<Unit> planes = bomber(gameData).create(4, british(gameData));
planes.addAll(fighter(gameData).create(4, british(gameData)));
final Collection<Unit> defendingAa = territory("Germany", gameData).getUnits().getMatches(Matches.unitIsAaForAnything());
// 1 roll, a hit
// then a dice to select the casualty
final ScriptedRandomSource randomSource = new ScriptedRandomSource(new int[] { 0, 1 });
bridge.setRandomSource(randomSource);
final DiceRoll roll = DiceRoll.rollAa(CollectionUtils.getMatches(planes, Matches.unitIsOfTypes(UnitAttachment.get(defendingAa.iterator().next().getType()).getTargetsAa(gameData))), defendingAa, bridge, territory("Germany", gameData), true);
// make sure we rolled once
assertEquals(1, randomSource.getTotalRolled());
final Collection<Unit> casualties = BattleCalculator.getAaCasualties(false, planes, planes, defendingAa, defendingAa, roll, bridge, null, null, null, territory("Germany", gameData), null, false, null).getKilled();
assertEquals(3, casualties.size());
// should be 1 fighter and 2 bombers
assertEquals(2, CollectionUtils.countMatches(casualties, Matches.unitIsStrategicBomber()));
assertEquals(1, CollectionUtils.countMatches(casualties, Matches.unitIsStrategicBomber().negate()));
}
use of games.strategy.engine.data.PlayerID in project triplea by triplea-game.
the class WW2V3Year41Test method testParatroopsWalkOnWater.
@Test
public void testParatroopsWalkOnWater() {
final PlayerID germans = germans(gameData);
final Territory france = territory("France", gameData);
TechAttachment.get(germans).setParatroopers("true");
final Route r = gameData.getMap().getRoute(france, territory("7 Sea Zone", gameData));
final Collection<Unit> paratroopers = france.getUnits().getMatches(Matches.unitIsAirTransportable());
assertFalse(paratroopers.isEmpty());
final MoveValidationResult results = MoveValidator.validateMove(paratroopers, r, germans, Collections.emptyList(), new HashMap<>(), false, null, gameData);
assertFalse(results.isMoveValid());
}
use of games.strategy.engine.data.PlayerID in project triplea by triplea-game.
the class WW2V3Year41Test method testCantTransportParatroopersWithBombersThatMovedPreviously.
@Test
public void testCantTransportParatroopersWithBombersThatMovedPreviously() {
// make sure bombers can't move then pick up paratroopers
final PlayerID germans = germans(gameData);
final Territory germany = territory("Germany", gameData);
final Territory bulgaria = territory("Bulgaria Romania", gameData);
final Territory poland = territory("Poland", gameData);
final Territory ukraine = territory("Ukraine", gameData);
final ITestDelegateBridge bridge = getDelegateBridge(germans);
bridge.setStepName("CombatMove");
moveDelegate(gameData).setDelegateBridgeAndPlayer(bridge);
moveDelegate(gameData).start();
TechAttachment.get(germans).setParatroopers("true");
// Move the bomber first
final List<Unit> bomber = germany.getUnits().getMatches(Matches.unitIsAirTransport());
move(bomber, new Route(germany, poland));
// Pick up a paratrooper
final List<Unit> bomberAndParatroop = new ArrayList<>(bomber);
bomberAndParatroop.addAll(poland.getUnits().getUnits(GameDataTestUtil.infantry(gameData), 1));
// move them
final String error = moveDelegate(gameData).move(bomberAndParatroop, new Route(poland, bulgaria, ukraine));
assertError(error);
}
use of games.strategy.engine.data.PlayerID in project triplea by triplea-game.
the class WW2V3Year41Test method testBomberTankOverWater.
@Test
public void testBomberTankOverWater() {
// can't transport a tank over water using a bomber
final PlayerID germans = germans(gameData);
final Territory sz5 = territory("5 Sea Zone", gameData);
final Territory germany = territory("Germany", gameData);
final Territory karelia = territory("Karelia S.S.R.", gameData);
addTo(germany, armour(gameData).create(1, germans));
final Route r = new Route(germany, sz5, karelia);
final Collection<Unit> toMove = germany.getUnits().getMatches(Matches.unitCanBlitz());
toMove.addAll(germany.getUnits().getMatches(Matches.unitIsStrategicBomber()));
assertEquals(2, toMove.size());
final MoveValidationResult results = MoveValidator.validateMove(toMove, r, germans, Collections.emptyList(), new HashMap<>(), false, null, gameData);
assertFalse(results.isMoveValid());
}
Aggregations