use of games.strategy.engine.data.ITestDelegateBridge in project triplea by triplea-game.
the class WW2V3Year41Test method testPlaceInOccupiedSeaZone.
@Test
public void testPlaceInOccupiedSeaZone() {
// Set up game
final PlayerID germans = GameDataTestUtil.germans(gameData);
final ITestDelegateBridge delegateBridge = getDelegateBridge(british(gameData));
// Clear all units from the SZ and add an enemy unit
final Territory sz5 = territory("5 Sea Zone", gameData);
removeFrom(sz5, sz5.getUnits().getUnits());
addTo(sz5, destroyer(gameData).create(1, british(gameData)));
// Set up the unit types
final UnitType transportType = GameDataTestUtil.transport(gameData);
// Set up the move delegate
final PlaceDelegate placeDelegate = placeDelegate(gameData);
delegateBridge.setStepName("Place");
delegateBridge.setPlayerId(germans);
placeDelegate.setDelegateBridgeAndPlayer(delegateBridge);
placeDelegate.start();
// Add the transport
final IntegerMap<UnitType> map = new IntegerMap<>();
map.add(transportType, 1);
addTo(germans(gameData), transport(gameData).create(1, germans(gameData)), gameData);
// Place it
final String response = placeDelegate.placeUnits(GameDataTestUtil.getUnits(map, germans), sz5);
assertValid(response);
}
use of games.strategy.engine.data.ITestDelegateBridge in project triplea by triplea-game.
the class WW2V3Year41Test method testChinesePlacement.
@Test
public void testChinesePlacement() {
/*
* This tests that Chinese can place units in any territory, that they can
* place in just conquered territories, and that they can place in territories
* with up to 3 Chinese units in them.
*/
// Set up game
final PlayerID chinese = GameDataTestUtil.chinese(gameData);
final ITestDelegateBridge delegateBridge = getDelegateBridge(chinese(gameData));
delegateBridge.setPlayerId(chinese);
delegateBridge.setStepName("CombatMove");
final MoveDelegate moveDelegate = moveDelegate(gameData);
moveDelegate.setDelegateBridgeAndPlayer(delegateBridge);
moveDelegate.start();
// Set up the territories
final Territory yunnan = territory("Yunnan", gameData);
final Territory kiangsu = territory("Kiangsu", gameData);
final Territory hupeh = territory("Hupeh", gameData);
// Set up the unit types
final UnitType infantryType = GameDataTestUtil.infantry(gameData);
// Remove all units
removeFrom(kiangsu, kiangsu.getUnits().getUnits());
// add a VALID attack
final Collection<Unit> moveUnits = hupeh.getUnits().getUnits();
final String validResults = moveDelegate.move(moveUnits, new Route(hupeh, kiangsu));
assertValid(validResults);
/*
* Place units in just captured territory
*/
final PlaceDelegate placeDelegate = placeDelegate(gameData);
delegateBridge.setStepName("Place");
placeDelegate.setDelegateBridgeAndPlayer(delegateBridge);
placeDelegate.start();
// Add the infantry
IntegerMap<UnitType> map = new IntegerMap<>();
map.add(infantryType, 3);
addTo(chinese(gameData), infantry(gameData).create(1, chinese(gameData)), gameData);
// Get the number of units before placing
int preCount = kiangsu.getUnits().getUnitCount();
// Place the infantry
String response = placeDelegate.placeUnits(GameDataTestUtil.getUnits(map, chinese), kiangsu, IAbstractPlaceDelegate.BidMode.NOT_BID);
assertValid(response);
assertEquals(preCount + 1, kiangsu.getUnits().getUnitCount());
/*
* Place units in a territory with up to 3 Chinese units
*/
// Add the infantry
map = new IntegerMap<>();
map.add(infantryType, 3);
addTo(chinese(gameData), infantry(gameData).create(3, chinese(gameData)), gameData);
// Get the number of units before placing
preCount = yunnan.getUnits().getUnitCount();
// Place the infantry
response = placeDelegate.placeUnits(GameDataTestUtil.getUnits(map, chinese), yunnan, IAbstractPlaceDelegate.BidMode.NOT_BID);
assertValid(response);
final int midCount = yunnan.getUnits().getUnitCount();
// Make sure they were all placed
assertEquals(preCount, midCount - 3);
/*
* Place units in a territory with 3 or more Chinese units
*/
map = new IntegerMap<>();
map.add(infantryType, 1);
addTo(chinese(gameData), infantry(gameData).create(1, chinese(gameData)), gameData);
response = placeDelegate.placeUnits(GameDataTestUtil.getUnits(map, chinese), yunnan, IAbstractPlaceDelegate.BidMode.NOT_BID);
assertError(response);
// Make sure none were placed
final int postCount = yunnan.getUnits().getUnitCount();
assertEquals(midCount, postCount);
}
use of games.strategy.engine.data.ITestDelegateBridge in project triplea by triplea-game.
the class WW2V3Year41Test method testJetPower.
@Test
public void testJetPower() {
// Set up tech
final PlayerID germans = GameDataTestUtil.germans(gameData);
final ITestDelegateBridge delegateBridge = getDelegateBridge(germans(gameData));
TechTracker.addAdvance(germans, delegateBridge, TechAdvance.findAdvance(TechAdvance.TECH_PROPERTY_JET_POWER, gameData, germans));
// Set up the territories
final Territory poland = territory("Poland", gameData);
final Territory eastPoland = territory("East Poland", gameData);
// Set up the unit types
final UnitType fighterType = GameDataTestUtil.fighter(gameData);
delegateBridge.setStepName("germanBattle");
while (!gameData.getSequence().getStep().getName().equals("germanBattle")) {
gameData.getSequence().next();
}
final Collection<TerritoryEffect> territoryEffects = TerritoryEffectHelper.getEffects(eastPoland);
// With JET_POWER attacking fighter hits on 4 (0 base)
final List<Unit> germanFighter = (List<Unit>) poland.getUnits().getUnits(fighterType, 1);
delegateBridge.setRandomSource(new ScriptedRandomSource(new int[] { 3 }));
final DiceRoll roll1 = DiceRoll.rollDice(germanFighter, false, germans, delegateBridge, new MockBattle(eastPoland), "", territoryEffects, null);
assertEquals(1, roll1.getHits());
// With JET_POWER defending fighter misses on 5 (0 base)
delegateBridge.setRandomSource(new ScriptedRandomSource(new int[] { 4 }));
final DiceRoll roll2 = DiceRoll.rollDice(germanFighter, true, germans, delegateBridge, new MockBattle(eastPoland), "", territoryEffects, null);
assertEquals(0, roll2.getHits());
}
use of games.strategy.engine.data.ITestDelegateBridge in project triplea by triplea-game.
the class WW2V3Year41Test method testOccupiedTerrOfAttachment.
@Test
public void testOccupiedTerrOfAttachment() {
// 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);
// 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 testTwoStepBlitz.
@Test
public void testTwoStepBlitz() {
final ITestDelegateBridge delegateBridge = getDelegateBridge(british(gameData));
// Set up the territories
final Territory libya = territory("Libya", gameData);
final Territory egypt = territory("Egypt", gameData);
final Territory morrocco = territory("Morocco Algeria", gameData);
removeFrom(libya, libya.getUnits().getUnits());
// Set up the move delegate
final MoveDelegate moveDelegate = moveDelegate(gameData);
delegateBridge.setStepName("CombatMove");
moveDelegate.setDelegateBridgeAndPlayer(delegateBridge);
moveDelegate.start();
// blitz in two steps
final Collection<Unit> armour = egypt.getUnits().getMatches(Matches.unitCanBlitz());
move(armour, new Route(egypt, libya));
assertEquals(libya.getOwner(), british(gameData));
move(armour, new Route(libya, morrocco));
}
Aggregations