From 4fd59f9e8c5b4e20b8a962bee4c9701cf4200745 Mon Sep 17 00:00:00 2001 From: BetaSteward Date: Mon, 6 Feb 2012 10:06:25 -0500 Subject: [PATCH] added test for continuous effects + modified tests to stop on specified turn and step --- .../test/serverside/base/CardTestAPI.java | 8 +++- .../test/serverside/base/CardTestBase.java | 3 ++ .../test/serverside/base/MageTestBase.java | 3 ++ .../serverside/base/impl/CardTestAPIImpl.java | 10 +++++ .../effects/BoostContinuousEffectTest.java | 43 +++++++++++++++++++ Mage/src/mage/game/Game.java | 2 + Mage/src/mage/game/GameImpl.java | 17 ++++++-- Mage/src/mage/game/GameOptions.java | 7 +++ Mage/src/mage/game/turn/Phase.java | 14 +++++- 9 files changed, 101 insertions(+), 6 deletions(-) diff --git a/Mage.Tests/src/test/java/org/mage/test/serverside/base/CardTestAPI.java b/Mage.Tests/src/test/java/org/mage/test/serverside/base/CardTestAPI.java index 8c5fb514c0..b103b22b41 100644 --- a/Mage.Tests/src/test/java/org/mage/test/serverside/base/CardTestAPI.java +++ b/Mage.Tests/src/test/java/org/mage/test/serverside/base/CardTestAPI.java @@ -6,6 +6,7 @@ import mage.filter.Filter; import mage.players.Player; import java.util.List; +import mage.Constants.PhaseStep; /** * Interface for all test initialization and assertion operations. @@ -82,7 +83,12 @@ public interface CardTestAPI { */ void setStopOnTurn(int turn); - //******* ASSERT METHODS *******/ + /** + * Define the turn number and step to stop the game on. + */ + void setStopAt(int turn, PhaseStep step); + + //******* ASSERT METHODS *******/ /** * Assert turn number after test execution. diff --git a/Mage.Tests/src/test/java/org/mage/test/serverside/base/CardTestBase.java b/Mage.Tests/src/test/java/org/mage/test/serverside/base/CardTestBase.java index 7cc9dc2fa0..05bdded685 100644 --- a/Mage.Tests/src/test/java/org/mage/test/serverside/base/CardTestBase.java +++ b/Mage.Tests/src/test/java/org/mage/test/serverside/base/CardTestBase.java @@ -17,6 +17,7 @@ import org.mage.test.serverside.base.impl.CardTestAPIImpl; import java.io.File; import java.io.FileNotFoundException; +import mage.Constants.PhaseStep; /** * Base class for testing single cards and effects. @@ -92,6 +93,7 @@ public abstract class CardTestBase extends CardTestAPIImpl { currentGame = game; stopOnTurn = 2; + stopAtStep = PhaseStep.UNTAP; handCardsA.clear(); handCardsB.clear(); battlefieldCardsA.clear(); @@ -176,6 +178,7 @@ public abstract class CardTestBase extends CardTestAPIImpl { GameOptions gameOptions = new GameOptions(); gameOptions.testMode = true; gameOptions.stopOnTurn = stopOnTurn; + gameOptions.stopAtStep = stopAtStep; currentGame.start(activePlayer.getId(), gameOptions); long t2 = System.nanoTime(); logger.info("Winner: " + currentGame.getWinner()); diff --git a/Mage.Tests/src/test/java/org/mage/test/serverside/base/MageTestBase.java b/Mage.Tests/src/test/java/org/mage/test/serverside/base/MageTestBase.java index 1e666d7f16..72caeacae8 100644 --- a/Mage.Tests/src/test/java/org/mage/test/serverside/base/MageTestBase.java +++ b/Mage.Tests/src/test/java/org/mage/test/serverside/base/MageTestBase.java @@ -27,6 +27,7 @@ import java.io.FilenameFilter; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; +import mage.Constants.PhaseStep; /** * Base class for all tests. @@ -69,6 +70,8 @@ public abstract class MageTestBase { protected static Player activePlayer = null; protected Integer stopOnTurn; + + protected PhaseStep stopAtStep = PhaseStep.UNTAP; protected enum ParserState { INIT, diff --git a/Mage.Tests/src/test/java/org/mage/test/serverside/base/impl/CardTestAPIImpl.java b/Mage.Tests/src/test/java/org/mage/test/serverside/base/impl/CardTestAPIImpl.java index 040909257c..74237e4f92 100644 --- a/Mage.Tests/src/test/java/org/mage/test/serverside/base/impl/CardTestAPIImpl.java +++ b/Mage.Tests/src/test/java/org/mage/test/serverside/base/impl/CardTestAPIImpl.java @@ -14,6 +14,7 @@ import org.mage.test.serverside.base.MageTestBase; import java.util.List; import java.util.UUID; +import mage.Constants.PhaseStep; /** * API for test initialization and asserting the test results. @@ -187,6 +188,15 @@ public abstract class CardTestAPIImpl extends MageTestBase implements CardTestAP */ public void setStopOnTurn(int turn) { stopOnTurn = turn == -1 ? null : Integer.valueOf(turn); + stopAtStep = PhaseStep.UNTAP; + } + + /** + * Define turn number and step to stop the game on. + */ + public void setStopAt(int turn, PhaseStep step) { + stopOnTurn = turn == -1 ? null : Integer.valueOf(turn); + stopAtStep = step; } /** diff --git a/Mage.Tests/src/test/java/org/mage/test/serverside/cards/effects/BoostContinuousEffectTest.java b/Mage.Tests/src/test/java/org/mage/test/serverside/cards/effects/BoostContinuousEffectTest.java index 2ca6b42743..9dfc4024c0 100644 --- a/Mage.Tests/src/test/java/org/mage/test/serverside/cards/effects/BoostContinuousEffectTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/serverside/cards/effects/BoostContinuousEffectTest.java @@ -1,5 +1,7 @@ package org.mage.test.serverside.cards.effects; +import mage.Constants; +import mage.Constants.PhaseStep; import mage.filter.Filter; import org.junit.Ignore; import org.junit.Test; @@ -21,4 +23,45 @@ public class BoostContinuousEffectTest extends CardTestBase { checkPermanentPT(playerA, "Tine Shrike", 3, 2, Filter.ComparisonScope.Any); checkPermanentPT(playerA, "Runeclaw Bear", 2, 2, Filter.ComparisonScope.Any); } + + @Test + public void testHonorOfThePoor2() { + addCard(Constants.Zone.BATTLEFIELD, playerA, "Honor of the Pure"); + addCard(Constants.Zone.BATTLEFIELD, playerA, "White Knight"); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Black Knight"); + + setStopAt(1, PhaseStep.CLEANUP); + execute(); + assertPowerToughness(playerA, "White Knight", 3, 3, Filter.ComparisonScope.Any); + assertPowerToughness(playerA, "Black Knight", 2, 2, Filter.ComparisonScope.Any); + } + + @Test + public void testHonorOfThePoor3() { + addCard(Constants.Zone.BATTLEFIELD, playerA, "Honor of the Pure"); + addCard(Constants.Zone.BATTLEFIELD, playerA, "White Knight"); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Black Knight"); + + setStopAt(2, PhaseStep.CLEANUP); + execute(); + assertPowerToughness(playerA, "White Knight", 3, 3, Filter.ComparisonScope.Any); + assertPowerToughness(playerA, "Black Knight", 2, 2, Filter.ComparisonScope.Any); + } + + @Test + public void testGiantGrowth() { + addCard(Constants.Zone.BATTLEFIELD, playerA, "Forest"); + addCard(Constants.Zone.BATTLEFIELD, playerA, "White Knight"); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Black Knight"); + addCard(Constants.Zone.HAND, playerA, "Giant Growth"); + + castSpell(playerA, "Giant Growth"); + addFixedTarget(playerA, "Giant Growth", "White Knight"); + + setStopAt(1, PhaseStep.CLEANUP); + execute(); + assertPowerToughness(playerA, "White Knight", 5, 5, Filter.ComparisonScope.Any); + assertPowerToughness(playerA, "Black Knight", 2, 2, Filter.ComparisonScope.Any); + } + } diff --git a/Mage/src/mage/game/Game.java b/Mage/src/mage/game/Game.java index 4f4b150a56..78b151f437 100644 --- a/Mage/src/mage/game/Game.java +++ b/Mage/src/mage/game/Game.java @@ -78,6 +78,7 @@ public interface Game extends MageItem, Serializable { public Collection getCards(); public Object getCustomData(); public void setCustomData(Object data); + public GameOptions getOptions(); public MageObject getObject(UUID objectId); public UUID getControllerId(UUID objectId); public Permanent getPermanent(UUID permanentId); @@ -135,6 +136,7 @@ public interface Game extends MageItem, Serializable { public void fireGetChoiceEvent(UUID playerId, String message, Collection choices); public void fireGetModeEvent(UUID playerId, String message, Map modes); public void fireGetAmountEvent(UUID playerId, String message, int min, int max); + public void fireChoosePileEvent(UUID playerId, List pile1, List pile2); public void fireInformEvent(String message); public void fireUpdatePlayersEvent(); public void informPlayers(String message); diff --git a/Mage/src/mage/game/GameImpl.java b/Mage/src/mage/game/GameImpl.java index 0095cbfab3..25fbbcb052 100644 --- a/Mage/src/mage/game/GameImpl.java +++ b/Mage/src/mage/game/GameImpl.java @@ -181,6 +181,11 @@ public abstract class GameImpl> implements Game, Serializa public void setCustomData(Object data) { this.customData = data; } + + @Override + public GameOptions getOptions() { + return gameOptions; + } @Override public void loadCards(Set cards, UUID ownerId) { @@ -423,7 +428,7 @@ public abstract class GameImpl> implements Game, Serializa } private boolean checkStopOnTurnOption() { - if (gameOptions.stopOnTurn != null) { + if (gameOptions.stopOnTurn != null && gameOptions.stopAtStep == PhaseStep.UNTAP) { if (gameOptions.stopOnTurn.equals(state.getTurnNum())) { winnerId = null; //DRAW saveState(); @@ -432,7 +437,7 @@ public abstract class GameImpl> implements Game, Serializa } return false; } - + protected void init(UUID choosingPlayerId, boolean testMode) { for (Player player: state.getPlayers().values()) { player.beginTurn(this); @@ -1025,7 +1030,13 @@ public abstract class GameImpl> implements Game, Serializa if (simulation) return; playerQueryEventSource.choose(playerId, choice.getMessage(), choice.getChoices()); } - + + @Override + public void fireChoosePileEvent(UUID playerId, List pile1, List pile2) { + if (simulation) return; + //playerQueryEventSource.choosePile(playerId, pile1, pile2); + } + @Override public void informPlayers(String message) { if (simulation) return; diff --git a/Mage/src/mage/game/GameOptions.java b/Mage/src/mage/game/GameOptions.java index 07cb50b019..968a8efbbf 100644 --- a/Mage/src/mage/game/GameOptions.java +++ b/Mage/src/mage/game/GameOptions.java @@ -1,6 +1,7 @@ package mage.game; import java.io.Serializable; +import mage.Constants.PhaseStep; /** * Game options for Mage game. @@ -26,4 +27,10 @@ public class GameOptions implements Serializable { * By default, is null meaning that game shouldn't stop on any specific turn. */ public Integer stopOnTurn = null; + + /** + * Stop at the end of the turn if true otherwise stop at the beginning + */ + public PhaseStep stopAtStep = PhaseStep.UNTAP; + } diff --git a/Mage/src/mage/game/turn/Phase.java b/Mage/src/mage/game/turn/Phase.java index c9eb1cd61f..7f24cfe732 100644 --- a/Mage/src/mage/game/turn/Phase.java +++ b/Mage/src/mage/game/turn/Phase.java @@ -102,10 +102,12 @@ public abstract class Phase> implements Serializable { if (beginPhase(game, activePlayerId)) { for (Step step: steps) { + currentStep = step; + if (!game.isSimulation()) + checkStopOnStepOption(game); if (game.isPaused() || game.isGameOver()) return false; - currentStep = step; - if (!game.getState().getTurnMods().skipStep(activePlayerId, currentStep.getType())) + if (!game.getState().getTurnMods().skipStep(activePlayerId, getStep().getType())) playStep(game); } if (game.isPaused() || game.isGameOver()) @@ -117,6 +119,14 @@ public abstract class Phase> implements Serializable { return false; } + private void checkStopOnStepOption(Game game) { + if (game.getOptions().stopOnTurn != null && game.getOptions().stopAtStep == getStep().getType()) { + if (game.getOptions().stopOnTurn.equals(game.getState().getTurnNum())) { + game.pause(); + } + } + } + public boolean resumePlay(Game game, PhaseStep stepType, boolean wasPaused) { if (game.isPaused() || game.isGameOver()) return false;