Search in sources :

Example 11 with ITripleAPlayer

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);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) GameDataTestUtil.move(games.strategy.triplea.delegate.GameDataTestUtil.move) Arrays(java.util.Arrays) GameDataTestUtil.bomber(games.strategy.triplea.delegate.GameDataTestUtil.bomber) GameDataTestUtil.japanese(games.strategy.triplea.delegate.GameDataTestUtil.japanese) Constants(games.strategy.triplea.Constants) UnitAttachment(games.strategy.triplea.attachments.UnitAttachment) GameDataTestUtil.addTo(games.strategy.triplea.delegate.GameDataTestUtil.addTo) TechAttachment(games.strategy.triplea.attachments.TechAttachment) GameDataTestUtil.aaGun(games.strategy.triplea.delegate.GameDataTestUtil.aaGun) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) GameDataTestUtil.moveDelegate(games.strategy.triplea.delegate.GameDataTestUtil.moveDelegate) GameDataTestUtil.makeGameLowLuck(games.strategy.triplea.delegate.GameDataTestUtil.makeGameLowLuck) GameDataTestUtil.americans(games.strategy.triplea.delegate.GameDataTestUtil.americans) GameDataTestUtil.getIndex(games.strategy.triplea.delegate.GameDataTestUtil.getIndex) TestMapGameData(games.strategy.triplea.xml.TestMapGameData) GameDataTestUtil.techDelegate(games.strategy.triplea.delegate.GameDataTestUtil.techDelegate) GameDataTestUtil.removeFrom(games.strategy.triplea.delegate.GameDataTestUtil.removeFrom) ScriptedRandomSource(games.strategy.engine.random.ScriptedRandomSource) GameDataTestUtil.assertValid(games.strategy.triplea.delegate.GameDataTestUtil.assertValid) Collection(java.util.Collection) GameDataTestUtil.load(games.strategy.triplea.delegate.GameDataTestUtil.load) Set(java.util.Set) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) GameDataTestUtil.territory(games.strategy.triplea.delegate.GameDataTestUtil.territory) SUBS_FIRE(games.strategy.triplea.delegate.BattleStepStrings.SUBS_FIRE) GameDataTestUtil.armour(games.strategy.triplea.delegate.GameDataTestUtil.armour) Test(org.junit.jupiter.api.Test) SUBS_SUBMERGE(games.strategy.triplea.delegate.BattleStepStrings.SUBS_SUBMERGE) GameData(games.strategy.engine.data.GameData) List(java.util.List) PlayerID(games.strategy.engine.data.PlayerID) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ITripleAPlayer(games.strategy.triplea.player.ITripleAPlayer) REMOVE_CASUALTIES(games.strategy.triplea.delegate.BattleStepStrings.REMOVE_CASUALTIES) GameDataTestUtil.destroyer(games.strategy.triplea.delegate.GameDataTestUtil.destroyer) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) GameDataTestUtil.infantry(games.strategy.triplea.delegate.GameDataTestUtil.infantry) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Proxy(java.lang.reflect.Proxy) GameDataTestUtil.battleship(games.strategy.triplea.delegate.GameDataTestUtil.battleship) SELECT_SUB_CASUALTIES(games.strategy.triplea.delegate.BattleStepStrings.SELECT_SUB_CASUALTIES) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) GameDataTestUtil.placeDelegate(games.strategy.triplea.delegate.GameDataTestUtil.placeDelegate) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) ArrayList(java.util.ArrayList) PlaceableUnits(games.strategy.triplea.delegate.dataObjects.PlaceableUnits) Answer(org.mockito.stubbing.Answer) Route(games.strategy.engine.data.Route) GameDataTestUtil.assertError(games.strategy.triplea.delegate.GameDataTestUtil.assertError) InvocationOnMock(org.mockito.invocation.InvocationOnMock) SELECT_CASUALTIES(games.strategy.triplea.delegate.BattleStepStrings.SELECT_CASUALTIES) CasualtyDetails(games.strategy.triplea.delegate.dataObjects.CasualtyDetails) GameDataTestUtil.bidPlaceDelegate(games.strategy.triplea.delegate.GameDataTestUtil.bidPlaceDelegate) CasualtyList(games.strategy.triplea.delegate.dataObjects.CasualtyList) UnitType(games.strategy.engine.data.UnitType) FIRE(games.strategy.triplea.delegate.BattleStepStrings.FIRE) GameDataTestUtil.germans(games.strategy.triplea.delegate.GameDataTestUtil.germans) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TripleAUnit(games.strategy.triplea.TripleAUnit) TechResults(games.strategy.triplea.delegate.dataObjects.TechResults) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) TechnologyFrontier(games.strategy.engine.data.TechnologyFrontier) CollectionUtils(games.strategy.util.CollectionUtils) Unit(games.strategy.engine.data.Unit) GameDataTestUtil.submarine(games.strategy.triplea.delegate.GameDataTestUtil.submarine) GameDataTestUtil.transport(games.strategy.triplea.delegate.GameDataTestUtil.transport) Territory(games.strategy.engine.data.Territory) Mockito.when(org.mockito.Mockito.when) GameDataTestUtil.british(games.strategy.triplea.delegate.GameDataTestUtil.british) ChangeFactory(games.strategy.engine.data.changefactory.ChangeFactory) REMOVE_SNEAK_ATTACK_CASUALTIES(games.strategy.triplea.delegate.BattleStepStrings.REMOVE_SNEAK_ATTACK_CASUALTIES) Change(games.strategy.engine.data.Change) ATTACKER_WITHDRAW(games.strategy.triplea.delegate.BattleStepStrings.ATTACKER_WITHDRAW) GameDataTestUtil.assertMoveError(games.strategy.triplea.delegate.GameDataTestUtil.assertMoveError) InvocationHandler(java.lang.reflect.InvocationHandler) Collections(java.util.Collections) PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) ScriptedRandomSource(games.strategy.engine.random.ScriptedRandomSource) InvocationHandler(java.lang.reflect.InvocationHandler) ITripleAPlayer(games.strategy.triplea.player.ITripleAPlayer) Test(org.junit.jupiter.api.Test)

Example 12 with ITripleAPlayer

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);
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) BeforeEach(org.junit.jupiter.api.BeforeEach) Proxy(java.lang.reflect.Proxy) Constants(games.strategy.triplea.Constants) UnitAttachment(games.strategy.triplea.attachments.UnitAttachment) GameDataTestUtil.addTo(games.strategy.triplea.delegate.GameDataTestUtil.addTo) Route(games.strategy.engine.data.Route) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) UnitType(games.strategy.engine.data.UnitType) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TripleAUnit(games.strategy.triplea.TripleAUnit) TestMapGameData(games.strategy.triplea.xml.TestMapGameData) ScriptedRandomSource(games.strategy.engine.random.ScriptedRandomSource) Unit(games.strategy.engine.data.Unit) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) Territory(games.strategy.engine.data.Territory) Test(org.junit.jupiter.api.Test) GameData(games.strategy.engine.data.GameData) ChangeFactory(games.strategy.engine.data.changefactory.ChangeFactory) List(java.util.List) PlayerID(games.strategy.engine.data.PlayerID) Change(games.strategy.engine.data.Change) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ITripleAPlayer(games.strategy.triplea.player.ITripleAPlayer) Collections(java.util.Collections) PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) ScriptedRandomSource(games.strategy.engine.random.ScriptedRandomSource) ITripleAPlayer(games.strategy.triplea.player.ITripleAPlayer) Test(org.junit.jupiter.api.Test)

Example 13 with ITripleAPlayer

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);
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) BeforeEach(org.junit.jupiter.api.BeforeEach) Proxy(java.lang.reflect.Proxy) Constants(games.strategy.triplea.Constants) UnitAttachment(games.strategy.triplea.attachments.UnitAttachment) GameDataTestUtil.addTo(games.strategy.triplea.delegate.GameDataTestUtil.addTo) Route(games.strategy.engine.data.Route) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) UnitType(games.strategy.engine.data.UnitType) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TripleAUnit(games.strategy.triplea.TripleAUnit) TestMapGameData(games.strategy.triplea.xml.TestMapGameData) ScriptedRandomSource(games.strategy.engine.random.ScriptedRandomSource) Unit(games.strategy.engine.data.Unit) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) Territory(games.strategy.engine.data.Territory) Test(org.junit.jupiter.api.Test) GameData(games.strategy.engine.data.GameData) ChangeFactory(games.strategy.engine.data.changefactory.ChangeFactory) List(java.util.List) PlayerID(games.strategy.engine.data.PlayerID) Change(games.strategy.engine.data.Change) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ITripleAPlayer(games.strategy.triplea.player.ITripleAPlayer) Collections(java.util.Collections) PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) Change(games.strategy.engine.data.Change) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) ScriptedRandomSource(games.strategy.engine.random.ScriptedRandomSource) TripleAUnit(games.strategy.triplea.TripleAUnit) Unit(games.strategy.engine.data.Unit) ITripleAPlayer(games.strategy.triplea.player.ITripleAPlayer) Test(org.junit.jupiter.api.Test)

Example 14 with ITripleAPlayer

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);
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) BeforeEach(org.junit.jupiter.api.BeforeEach) Proxy(java.lang.reflect.Proxy) Constants(games.strategy.triplea.Constants) UnitAttachment(games.strategy.triplea.attachments.UnitAttachment) GameDataTestUtil.addTo(games.strategy.triplea.delegate.GameDataTestUtil.addTo) Route(games.strategy.engine.data.Route) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) UnitType(games.strategy.engine.data.UnitType) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TripleAUnit(games.strategy.triplea.TripleAUnit) TestMapGameData(games.strategy.triplea.xml.TestMapGameData) ScriptedRandomSource(games.strategy.engine.random.ScriptedRandomSource) Unit(games.strategy.engine.data.Unit) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) Territory(games.strategy.engine.data.Territory) Test(org.junit.jupiter.api.Test) GameData(games.strategy.engine.data.GameData) ChangeFactory(games.strategy.engine.data.changefactory.ChangeFactory) List(java.util.List) PlayerID(games.strategy.engine.data.PlayerID) Change(games.strategy.engine.data.Change) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ITripleAPlayer(games.strategy.triplea.player.ITripleAPlayer) Collections(java.util.Collections) PlayerID(games.strategy.engine.data.PlayerID) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) TripleAUnit(games.strategy.triplea.TripleAUnit) Unit(games.strategy.engine.data.Unit) ITripleAPlayer(games.strategy.triplea.player.ITripleAPlayer) Route(games.strategy.engine.data.Route) Test(org.junit.jupiter.api.Test)

Aggregations

ITripleAPlayer (games.strategy.triplea.player.ITripleAPlayer)14 GameData (games.strategy.engine.data.GameData)8 PlayerID (games.strategy.engine.data.PlayerID)8 Territory (games.strategy.engine.data.Territory)8 Unit (games.strategy.engine.data.Unit)8 ArrayList (java.util.ArrayList)8 TripleAUnit (games.strategy.triplea.TripleAUnit)7 Change (games.strategy.engine.data.Change)6 UnitType (games.strategy.engine.data.UnitType)6 UnitAttachment (games.strategy.triplea.attachments.UnitAttachment)6 ITestDelegateBridge (games.strategy.engine.data.ITestDelegateBridge)5 Route (games.strategy.engine.data.Route)5 List (java.util.List)5 Test (org.junit.jupiter.api.Test)5 ChangeFactory (games.strategy.engine.data.changefactory.ChangeFactory)4 ScriptedRandomSource (games.strategy.engine.random.ScriptedRandomSource)4 Constants (games.strategy.triplea.Constants)4 GameDataTestUtil.addTo (games.strategy.triplea.delegate.GameDataTestUtil.addTo)4 TestMapGameData (games.strategy.triplea.xml.TestMapGameData)4 Proxy (java.lang.reflect.Proxy)4