Search in sources :

Example 86 with ITestDelegateBridge

use of games.strategy.engine.data.ITestDelegateBridge in project triplea by triplea-game.

the class RevisedTest method testSubAttackTransportNonCombat.

@Test
public void testSubAttackTransportNonCombat() {
    final Territory sz1 = territory("1 Sea Zone", gameData);
    final Territory sz8 = territory("8 Sea Zone", gameData);
    final PlayerID germans = germans(gameData);
    // german sub tries to attack a transport in non combat
    // should be an error
    final MoveDelegate moveDelegate = (MoveDelegate) gameData.getDelegateList().getDelegate("move");
    final ITestDelegateBridge bridge = getDelegateBridge(germans);
    bridge.setStepName("NonCombatMove");
    moveDelegate.setDelegateBridgeAndPlayer(bridge);
    moveDelegate.start();
    final String error = moveDelegate(gameData).move(sz8.getUnits().getUnits(), new Route(sz8, sz1));
    assertError(error);
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) Route(games.strategy.engine.data.Route) Test(org.junit.jupiter.api.Test)

Example 87 with ITestDelegateBridge

use of games.strategy.engine.data.ITestDelegateBridge in project triplea by triplea-game.

the class RevisedTest method testOverFlyBombersDies.

@Test
public void testOverFlyBombersDies() {
    final PlayerID british = british(gameData);
    final MoveDelegate moveDelegate = (MoveDelegate) gameData.getDelegateList().getDelegate("move");
    final ITestDelegateBridge bridge = getDelegateBridge(british);
    bridge.setStepName("CombatMove");
    moveDelegate.setDelegateBridgeAndPlayer(bridge);
    moveDelegate.start();
    when(dummyPlayer.confirmMoveInFaceOfAa(any())).thenReturn(true);
    bridge.setRemote(dummyPlayer);
    bridge.setRandomSource(new ScriptedRandomSource(0));
    final Territory uk = territory("United Kingdom", gameData);
    final Territory we = territory("Western Europe", gameData);
    final Territory se = territory("Southern Europe", gameData);
    final Route route = new Route(uk, territory("7 Sea Zone", gameData), we, se);
    move(uk.getUnits().getMatches(Matches.unitIsStrategicBomber()), route);
    // the aa gun should have fired. the bomber no longer exists
    assertTrue(se.getUnits().getMatches(Matches.unitIsStrategicBomber()).isEmpty());
    assertTrue(we.getUnits().getMatches(Matches.unitIsStrategicBomber()).isEmpty());
    assertTrue(uk.getUnits().getMatches(Matches.unitIsStrategicBomber()).isEmpty());
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) ScriptedRandomSource(games.strategy.engine.random.ScriptedRandomSource) Route(games.strategy.engine.data.Route) Test(org.junit.jupiter.api.Test)

Example 88 with ITestDelegateBridge

use of games.strategy.engine.data.ITestDelegateBridge in project triplea by triplea-game.

the class RevisedTest method testOverFlyBombersJoiningBattleDie.

@Test
public void testOverFlyBombersJoiningBattleDie() {
    // a bomber flies over aa to join a battle, gets hit,
    // it should not appear in the battle
    final PlayerID british = british(gameData);
    final MoveDelegate moveDelegate = (MoveDelegate) gameData.getDelegateList().getDelegate("move");
    final ITestDelegateBridge bridge = getDelegateBridge(british);
    bridge.setStepName("CombatMove");
    moveDelegate.setDelegateBridgeAndPlayer(bridge);
    moveDelegate.start();
    when(dummyPlayer.confirmMoveInFaceOfAa(any())).thenReturn(true);
    bridge.setRemote(dummyPlayer);
    bridge.setRandomSource(new ScriptedRandomSource(0));
    final Territory uk = territory("United Kingdom", gameData);
    final Territory we = territory("Western Europe", gameData);
    final Territory se = territory("Southern Europe", gameData);
    final Route route = new Route(uk, territory("7 Sea Zone", gameData), we, se);
    move(uk.getUnits().getMatches(Matches.unitIsStrategicBomber()), route);
    // the aa gun should have fired and hit
    assertTrue(se.getUnits().getMatches(Matches.unitIsStrategicBomber()).isEmpty());
    assertTrue(we.getUnits().getMatches(Matches.unitIsStrategicBomber()).isEmpty());
    assertTrue(uk.getUnits().getMatches(Matches.unitIsStrategicBomber()).isEmpty());
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) ScriptedRandomSource(games.strategy.engine.random.ScriptedRandomSource) Route(games.strategy.engine.data.Route) Test(org.junit.jupiter.api.Test)

Example 89 with ITestDelegateBridge

use of games.strategy.engine.data.ITestDelegateBridge in project triplea by triplea-game.

the class RevisedTest method testAttackSubsAndBattleshipOnDestroyerAndSubs.

@Test
public void testAttackSubsAndBattleshipOnDestroyerAndSubs() {
    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 and 1 BB (two hp) attacks 3 subs and 1 destroyer
    addTo(from, submarine(gameData).create(1, british(gameData)));
    addTo(from, battleship(gameData).create(1, british(gameData)));
    addTo(attacked, submarine(gameData).create(3, germans(gameData)));
    addTo(attacked, destroyer(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);
    /*
     * Here are the exact errata clarifications on how REVISED rules subs work:
     * Every sub, regardless of whether it is on the attacking or defending side, fires in the Opening Fire step of
     * combat. That is the only
     * time a sub ever fires.
     * Losses caused by attacking or defending subs are removed at the end of the Opening Fire step, before normal
     * attack and defense rolls,
     * unless the enemy has a destroyer present.
     * If the enemy (attacker or defender) has a destroyer, then hits caused by your subs are not removed until the
     * Remove Casualties step
     * (step 6) of combat.
     * In other words, subs work exactly the same for the attacker and the defender. Nothing, not even a destroyer, ever
     * stops a sub from
     * rolling its die (attack or defense) in the Opening Fire step.
     * What a destroyer does do is let you keep your units that were sunk by enemy subs on the battle board until step
     * 6, allowing them to
     * fire back before going to the scrap heap.
     */
    assertEquals(Arrays.asList(attacker + SUBS_FIRE, defender + SELECT_SUB_CASUALTIES, defender + SUBS_FIRE, attacker + SELECT_SUB_CASUALTIES, REMOVE_SNEAK_ATTACK_CASUALTIES, attacker + FIRE, defender + SELECT_CASUALTIES, defender + FIRE, attacker + SELECT_CASUALTIES, REMOVE_CASUALTIES, attacker + SUBS_SUBMERGE, defender + SUBS_SUBMERGE, attacker + ATTACKER_WITHDRAW).toString(), steps.toString());
    final List<IExecutable> execs = battle.getBattleExecutables(false);
    final int attackSubs = getIndex(execs, MustFightBattle.AttackSubs.class);
    final int defendSubs = getIndex(execs, MustFightBattle.DefendSubs.class);
    assertTrue(attackSubs < defendSubs);
    bridge.setRemote(dummyPlayer);
    // attacking subs fires, defending destroyer and sub still gets to fire
    // attacking subs still gets to fire even if defending sub hits
    // battleship will not get to fire since it is killed by defending sub's sneak attack
    final ScriptedRandomSource randomSource = new ScriptedRandomSource(0, 0, 0, 0, ScriptedRandomSource.ERROR);
    bridge.setRandomSource(randomSource);
    battle.fight(bridge);
    assertEquals(4, randomSource.getTotalRolled());
    assertTrue(attacked.getUnits().getMatches(Matches.unitIsOwnedBy(british(gameData))).isEmpty());
    assertEquals(3, attacked.getUnits().size());
}
Also used : Territory(games.strategy.engine.data.Territory) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) ScriptedRandomSource(games.strategy.engine.random.ScriptedRandomSource) Route(games.strategy.engine.data.Route) Test(org.junit.jupiter.api.Test)

Example 90 with ITestDelegateBridge

use of games.strategy.engine.data.ITestDelegateBridge in project triplea by triplea-game.

the class RevisedTest method testMoveSubAwayFromSubmergedSubsInBattleZone.

@Test
public void testMoveSubAwayFromSubmergedSubsInBattleZone() {
    final Territory sz45 = gameData.getMap().getTerritory("45 Sea Zone");
    final Territory sz50 = gameData.getMap().getTerritory("50 Sea Zone");
    final PlayerID british = GameDataTestUtil.british(gameData);
    final PlayerID japanese = GameDataTestUtil.japanese(gameData);
    // put 1 british sub in sz 45, this simulates a submerged enemy sub
    final UnitType sub = GameDataTestUtil.submarine(gameData);
    final Change c = ChangeFactory.addUnits(sz45, sub.create(1, british));
    gameData.performChange(c);
    // new move delegate
    final MoveDelegate moveDelegate = (MoveDelegate) gameData.getDelegateList().getDelegate("move");
    final ITestDelegateBridge bridge = getDelegateBridge(japanese);
    bridge.setStepName("CombatMove");
    moveDelegate.setDelegateBridgeAndPlayer(bridge);
    moveDelegate.start();
    // move a fighter into the sea zone, this will cause a battle
    final Route sz50To45 = new Route();
    sz50To45.setStart(sz50);
    sz50To45.add(sz45);
    String error = moveDelegate.move(sz50.getUnits().getMatches(Matches.unitIsAir()), sz50To45);
    assertNull(error);
    assertEquals(1, AbstractMoveDelegate.getBattleTracker(gameData).getPendingBattleSites(false).size());
    // we should be able to move the sub out of the sz
    final Route sz45To50 = new Route();
    sz45To50.setStart(sz45);
    sz45To50.add(sz50);
    final List<Unit> japSub = sz45.getUnits().getMatches(Matches.unitIsSub().and(Matches.unitIsOwnedBy(japanese)));
    error = moveDelegate.move(japSub, sz45To50);
    // make sure no error
    assertNull(error);
    // make sure the battle is still there
    assertEquals(1, AbstractMoveDelegate.getBattleTracker(gameData).getPendingBattleSites(false).size());
    // we should be able to undo the move of the sub
    error = moveDelegate.undoMove(1);
    assertNull(error);
    // undo the move of the fighter, should be no battles now
    error = moveDelegate.undoMove(0);
    assertNull(error);
    assertEquals(0, AbstractMoveDelegate.getBattleTracker(gameData).getPendingBattleSites(false).size());
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) UnitType(games.strategy.engine.data.UnitType) Change(games.strategy.engine.data.Change) ITestDelegateBridge(games.strategy.engine.data.ITestDelegateBridge) TripleAUnit(games.strategy.triplea.TripleAUnit) Unit(games.strategy.engine.data.Unit) Route(games.strategy.engine.data.Route) Test(org.junit.jupiter.api.Test)

Aggregations

ITestDelegateBridge (games.strategy.engine.data.ITestDelegateBridge)128 Test (org.junit.jupiter.api.Test)127 Territory (games.strategy.engine.data.Territory)119 PlayerID (games.strategy.engine.data.PlayerID)94 Route (games.strategy.engine.data.Route)80 TripleAUnit (games.strategy.triplea.TripleAUnit)60 Unit (games.strategy.engine.data.Unit)58 ScriptedRandomSource (games.strategy.engine.random.ScriptedRandomSource)56 UnitType (games.strategy.engine.data.UnitType)40 Change (games.strategy.engine.data.Change)12 ArrayList (java.util.ArrayList)11 UnitAttachment (games.strategy.triplea.attachments.UnitAttachment)8 GameData (games.strategy.engine.data.GameData)5 GameDataTestUtil.bidPlaceDelegate (games.strategy.triplea.delegate.GameDataTestUtil.bidPlaceDelegate)5 ITripleAPlayer (games.strategy.triplea.player.ITripleAPlayer)5 TestMapGameData (games.strategy.triplea.xml.TestMapGameData)5 IntegerMap (games.strategy.util.IntegerMap)5 List (java.util.List)5 TerritoryEffect (games.strategy.engine.data.TerritoryEffect)4 ChangeFactory (games.strategy.engine.data.changefactory.ChangeFactory)4