use of games.strategy.triplea.player.ITripleAPlayer in project triplea by triplea-game.
the class RevisedTest method testStratBombRaidWithHeavyBombers.
@Test
public void testStratBombRaidWithHeavyBombers() {
final Territory germany = gameData.getMap().getTerritory("Germany");
final Territory uk = gameData.getMap().getTerritory("United Kingdom");
final PlayerID germans = GameDataTestUtil.germans(gameData);
final PlayerID british = GameDataTestUtil.british(gameData);
final BattleTracker tracker = new BattleTracker();
final StrategicBombingRaidBattle battle = new StrategicBombingRaidBattle(germany, gameData, british, tracker);
battle.addAttackChange(gameData.getMap().getRoute(uk, germany), uk.getUnits().getMatches(Matches.unitIsStrategicBomber()), null);
addTo(germany, uk.getUnits().getMatches(Matches.unitIsStrategicBomber()));
tracker.getBattleRecords().addBattle(british, battle.getBattleId(), germany, battle.getBattleType());
final ITestDelegateBridge bridge = getDelegateBridge(british);
TechTracker.addAdvance(british, bridge, TechAdvance.findAdvance(TechAdvance.TECH_PROPERTY_HEAVY_BOMBER, gameData, british));
// aa guns rolls 3, misses, bomber rolls 2 dice at 3
bridge.setRandomSource(new ScriptedRandomSource(new int[] { 3, 2, 2 }));
// if we try to move aa, then the game will ask us if we want to move
// fail if we are called
final InvocationHandler handler = (proxy, method, args) -> null;
final ITripleAPlayer player = (ITripleAPlayer) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[] { ITripleAPlayer.class }, handler);
bridge.setRemote(player);
final int pusBeforeRaid = germans.getResources().getQuantity(gameData.getResourceList().getResource(Constants.PUS));
battle.fight(bridge);
final int pusAfterRaid = germans.getResources().getQuantity(gameData.getResourceList().getResource(Constants.PUS));
assertEquals(pusBeforeRaid - 6, pusAfterRaid);
}
use of games.strategy.triplea.player.ITripleAPlayer in project triplea by triplea-game.
the class LhtrTest method testLhtrBombingRaid.
@Test
public void testLhtrBombingRaid() {
final Territory germany = gameData.getMap().getTerritory("Germany");
final Territory uk = gameData.getMap().getTerritory("United Kingdom");
final PlayerID germans = GameDataTestUtil.germans(gameData);
final PlayerID british = GameDataTestUtil.british(gameData);
final BattleTracker tracker = new BattleTracker();
final StrategicBombingRaidBattle battle = new StrategicBombingRaidBattle(germany, gameData, british, tracker);
battle.addAttackChange(gameData.getMap().getRoute(uk, germany), uk.getUnits().getMatches(Matches.unitIsStrategicBomber()), null);
addTo(germany, uk.getUnits().getMatches(Matches.unitIsStrategicBomber()));
tracker.getBattleRecords().addBattle(british, battle.getBattleId(), germany, battle.getBattleType());
final ITestDelegateBridge bridge = getDelegateBridge(british);
TechTracker.addAdvance(british, bridge, TechAdvance.findAdvance(TechAdvance.TECH_PROPERTY_HEAVY_BOMBER, gameData, british));
// aa guns rolls 3, misses, bomber rolls 2 dice at 3 and 4
bridge.setRandomSource(new ScriptedRandomSource(new int[] { 2, 2, 3 }));
// if we try to move aa, then the game will ask us if we want to move
// fail if we are called
final ITripleAPlayer player = (ITripleAPlayer) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[] { ITripleAPlayer.class }, (p, m, a) -> null);
bridge.setRemote(player);
final int pusBeforeRaid = germans.getResources().getQuantity(gameData.getResourceList().getResource(Constants.PUS));
battle.fight(bridge);
final int pusAfterRaid = germans.getResources().getQuantity(gameData.getResourceList().getResource(Constants.PUS));
// targets dice is 4, so damage is 1 + 4 = 5
// Changed to match StrategicBombingRaidBattle changes
assertEquals(pusBeforeRaid - 5, pusAfterRaid);
}
use of games.strategy.triplea.player.ITripleAPlayer in project triplea by triplea-game.
the class LhtrTest method testLhtrBombingRaid2Bombers.
@Test
public void testLhtrBombingRaid2Bombers() {
final Territory germany = gameData.getMap().getTerritory("Germany");
final Territory uk = gameData.getMap().getTerritory("United Kingdom");
final PlayerID germans = GameDataTestUtil.germans(gameData);
final PlayerID british = GameDataTestUtil.british(gameData);
// add a unit
final Unit bomber = GameDataTestUtil.bomber(gameData).create(british);
final Change change = ChangeFactory.addUnits(uk, Collections.singleton(bomber));
gameData.performChange(change);
final BattleTracker tracker = new BattleTracker();
final StrategicBombingRaidBattle battle = new StrategicBombingRaidBattle(germany, gameData, british, tracker);
battle.addAttackChange(gameData.getMap().getRoute(uk, germany), uk.getUnits().getMatches(Matches.unitIsStrategicBomber()), null);
addTo(germany, uk.getUnits().getMatches(Matches.unitIsStrategicBomber()));
tracker.getBattleRecords().addBattle(british, battle.getBattleId(), germany, battle.getBattleType());
final ITestDelegateBridge bridge = getDelegateBridge(british);
TechTracker.addAdvance(british, bridge, TechAdvance.findAdvance(TechAdvance.TECH_PROPERTY_HEAVY_BOMBER, gameData, british));
// aa guns rolls 3,3 both miss, bomber 1 rolls 2 dice at 3,4 and bomber 2 rolls dice at 1,2
bridge.setRandomSource(new ScriptedRandomSource(new int[] { 3, 3, 2, 3, 0, 1 }));
// if we try to move aa, then the game will ask us if we want to move
// fail if we are called
final ITripleAPlayer player = (ITripleAPlayer) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[] { ITripleAPlayer.class }, (p, m, a) -> null);
bridge.setRemote(player);
final int pusBeforeRaid = germans.getResources().getQuantity(gameData.getResourceList().getResource(Constants.PUS));
battle.fight(bridge);
final int pusAfterRaid = germans.getResources().getQuantity(gameData.getResourceList().getResource(Constants.PUS));
// targets dice is 4, so damage is 1 + 4 = 5
// bomber 2 hits at 2, so damage is 3, for a total of 8
// Changed to match StrategicBombingRaidBattle changes
assertEquals(pusBeforeRaid - 8, pusAfterRaid);
}
use of games.strategy.triplea.player.ITripleAPlayer in project triplea by triplea-game.
the class LhtrTest method testAaGunsDontFireNonCombat.
@Test
public void testAaGunsDontFireNonCombat() {
final MoveDelegate delegate = (MoveDelegate) gameData.getDelegateList().getDelegate("move");
delegate.initialize("MoveDelegate", "MoveDelegate");
final PlayerID germans = GameDataTestUtil.germans(gameData);
final ITestDelegateBridge bridge = getDelegateBridge(germans);
bridge.setStepName("germanNonCombatMove");
delegate.setDelegateBridgeAndPlayer(bridge);
delegate.start();
// if we try to move aa, then the game will ask us if we want to move
// fail if we are called
final ITripleAPlayer player = (ITripleAPlayer) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[] { ITripleAPlayer.class }, (p, m, a) -> fail("method called:" + m));
bridge.setRemote(player);
// move 1 fighter over the aa gun in caucus
final Route route = new Route();
route.setStart(gameData.getMap().getTerritory("Ukraine S.S.R."));
route.add(gameData.getMap().getTerritory("Caucasus"));
route.add(gameData.getMap().getTerritory("West Russia"));
final List<Unit> fighter = route.getStart().getUnits().getMatches(Matches.unitIsAir());
delegate.move(fighter, route);
}
Aggregations