use of games.strategy.engine.data.ITestDelegateBridge in project triplea by triplea-game.
the class WW2V3Year41Test method testOccupiedTerrOfAttachmentWithCapital.
@Test
public void testOccupiedTerrOfAttachmentWithCapital() throws GameParseException {
// Set up test
final PlayerID british = GameDataTestUtil.british(gameData);
final ITestDelegateBridge delegateBridge = getDelegateBridge(british(gameData));
// Set up the move delegate
final MoveDelegate moveDelegate = moveDelegate(gameData);
delegateBridge.setStepName("CombatMove");
moveDelegate(gameData).setDelegateBridgeAndPlayer(delegateBridge);
moveDelegate(gameData).start();
// Set up the territories
final Territory hupeh = territory("Hupeh", gameData);
final Territory kiangsu = territory("Kiangsu", gameData);
final Territory mongolia = territory("Mongolia", gameData);
// Remove original capital
final TerritoryAttachment taMongolia = TerritoryAttachment.get(mongolia);
final TerritoryAttachment taKiangsu = TerritoryAttachment.get(kiangsu);
taMongolia.setCapital(null);
// Set as NEW capital
taKiangsu.setCapital(Constants.PLAYER_NAME_CHINESE);
// Remove all units
removeFrom(kiangsu, kiangsu.getUnits().getUnits());
removeFrom(hupeh, hupeh.getUnits().getUnits());
// Set up the unit types
addTo(hupeh, infantry(gameData).create(1, british));
// Get units
final Collection<Unit> moveUnits = hupeh.getUnits().getUnits();
// Get Owner prior to battle
final String preOwner = kiangsu.getOwner().getName();
assertEquals(Constants.PLAYER_NAME_JAPANESE, preOwner);
// add a VALID attack
final String validResults = moveDelegate.move(moveUnits, new Route(hupeh, kiangsu));
assertValid(validResults);
// Ensure owner after attack doesn't match attacker
final String postOwner = kiangsu.getOwner().getName();
assertNotSame(Constants.PLAYER_NAME_BRITISH, postOwner);
// Check that original owner is now owner
assertEquals(Constants.PLAYER_NAME_CHINESE, postOwner);
}
use of games.strategy.engine.data.ITestDelegateBridge 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.ITestDelegateBridge in project triplea by triplea-game.
the class WW2V3Year41Test method testAttackSubsOnSubs.
@Test
public void testAttackSubsOnSubs() {
final String defender = "Germans";
final String attacker = "British";
final Territory attacked = territory("31 Sea Zone", gameData);
final Territory from = territory("32 Sea Zone", gameData);
// 1 sub attacks 1 sub
addTo(from, submarine(gameData).create(1, british(gameData)));
addTo(attacked, submarine(gameData).create(1, germans(gameData)));
final ITestDelegateBridge bridge = getDelegateBridge(british(gameData));
bridge.setStepName("CombatMove");
moveDelegate(gameData).setDelegateBridgeAndPlayer(bridge);
moveDelegate(gameData).start();
move(from.getUnits().getUnits(), new Route(from, attacked));
moveDelegate(gameData).end();
final MustFightBattle battle = (MustFightBattle) AbstractMoveDelegate.getBattleTracker(gameData).getPendingBattle(attacked, false, null);
final List<String> steps = battle.determineStepStrings(true);
assertEquals(Arrays.asList(attacker + SUBS_SUBMERGE, defender + SUBS_SUBMERGE, attacker + SUBS_FIRE, defender + SELECT_SUB_CASUALTIES, defender + SUBS_FIRE, attacker + SELECT_SUB_CASUALTIES, REMOVE_SNEAK_ATTACK_CASUALTIES, REMOVE_CASUALTIES, attacker + ATTACKER_WITHDRAW).toString(), steps.toString());
bridge.setRemote(dummyPlayer);
// fight, each sub should fire
// and hit
final ScriptedRandomSource randomSource = new ScriptedRandomSource(0, 0, ScriptedRandomSource.ERROR);
bridge.setRandomSource(randomSource);
battle.fight(bridge);
assertEquals(2, randomSource.getTotalRolled());
assertTrue(attacked.getUnits().isEmpty());
}
use of games.strategy.engine.data.ITestDelegateBridge 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.ITestDelegateBridge in project triplea by triplea-game.
the class WW2V3Year41Test method testCarrierWithAlliedPlanes.
@Test
public void testCarrierWithAlliedPlanes() {
final Territory sz8 = territory("8 Sea Zone", gameData);
final Territory sz1 = territory("1 Sea Zone", gameData);
addTo(sz8, carrier(gameData).create(1, british(gameData)));
addTo(sz8, fighter(gameData).create(1, americans(gameData)));
final Route route = new Route(sz8, sz1);
final ITestDelegateBridge bridge = getDelegateBridge(british(gameData));
bridge.setStepName("CombatMove");
moveDelegate(gameData).setDelegateBridgeAndPlayer(bridge);
moveDelegate(gameData).start();
move(sz8.getUnits().getUnits(), route);
// make sure the fighter moved
assertTrue(sz8.getUnits().getUnits().isEmpty());
assertFalse(sz1.getUnits().getMatches(Matches.unitIsAir()).isEmpty());
}
Aggregations