diff --git a/Mage.Tests/src/test/java/org/mage/test/AI/basic/TestFrameworkCanPlayAITest.java b/Mage.Tests/src/test/java/org/mage/test/AI/basic/TestFrameworkCanPlayAITest.java index 64c863ba4af..38b1c2286c7 100644 --- a/Mage.Tests/src/test/java/org/mage/test/AI/basic/TestFrameworkCanPlayAITest.java +++ b/Mage.Tests/src/test/java/org/mage/test/AI/basic/TestFrameworkCanPlayAITest.java @@ -52,6 +52,40 @@ public class TestFrameworkCanPlayAITest extends CardTestPlayerBaseWithAIHelps { assertPermanentCount(playerB, "Balduvian Bears", 5 - 3); } + @Test + public void test_AI_Attack() { + addCard(Zone.BATTLEFIELD, playerA, "Balduvian Bears", 1); + + // AI must attack + aiPlayStep(1, PhaseStep.DECLARE_ATTACKERS, playerA); + + setStopAt(1, PhaseStep.END_TURN); + setStrictChooseMode(true); + execute(); + assertAllCommandsUsed(); + + assertLife(playerB, 20 - 2); + } + + @Test + public void test_AI_Block() { + addCard(Zone.BATTLEFIELD, playerA, "Balduvian Bears", 1); + addCard(Zone.BATTLEFIELD, playerB, "Balduvian Bears", 1); + + // AI must block + attack(1, playerA, "Balduvian Bears"); + aiPlayStep(1, PhaseStep.DECLARE_BLOCKERS, playerB); + + setStopAt(1, PhaseStep.END_TURN); + setStrictChooseMode(true); + execute(); + assertAllCommandsUsed(); + + assertGraveyardCount(playerA, 1); + assertGraveyardCount(playerB, 1); + assertLife(playerB, 20); + } + @Test @Ignore // AI can't play blade cause score system give priority for boost instead restriction effects like goad public void test_AI_GoadedByBloodthirstyBlade_Normal() { diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/requirement/BecomeBlockTriggersAITest.java b/Mage.Tests/src/test/java/org/mage/test/cards/requirement/BecomeBlockTriggersAITest.java new file mode 100644 index 00000000000..3012f384191 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/requirement/BecomeBlockTriggersAITest.java @@ -0,0 +1,93 @@ +package org.mage.test.cards.requirement; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import org.junit.Assert; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBaseWithAIHelps; + +/** + * @author JayDi85 + */ +public class BecomeBlockTriggersAITest extends CardTestPlayerBaseWithAIHelps { + + @Test + public void test_Manual_AutoBlock() { + removeAllCardsFromHand(playerA); + removeAllCardsFromHand(playerB); + + // All creatures able to block Nessian Boar do so. + // Whenever Nessian Boar becomes blocked by a creature, that creature’s controller draws a card. + addCard(Zone.BATTLEFIELD, playerA, "Nessian Boar", 1); + // + addCard(Zone.BATTLEFIELD, playerB, "Balduvian Bears", 1); + + // auto-block by requirement effect + attack(1, playerA, "Nessian Boar"); + //block(1, playerB, "Balduvian Bears", "Nessian Boar"); + + setStopAt(1, PhaseStep.END_TURN); + setStrictChooseMode(true); + execute(); + assertAllCommandsUsed(); + + assertGraveyardCount(playerA, 0); + assertGraveyardCount(playerB, 1); + assertHandCount(playerA, 0); + assertHandCount(playerB, 1); + } + + @Test + public void test_Manual_CantBlockAgain() { + removeAllCardsFromHand(playerA); + removeAllCardsFromHand(playerB); + + // All creatures able to block Nessian Boar do so. + // Whenever Nessian Boar becomes blocked by a creature, that creature’s controller draws a card. + addCard(Zone.BATTLEFIELD, playerA, "Nessian Boar", 1); + // + addCard(Zone.BATTLEFIELD, playerB, "Balduvian Bears", 1); + + // auto-block by requirement effect + attack(1, playerA, "Nessian Boar"); + // try to block manually, but it must raise error + block(1, playerB, "Balduvian Bears", "Nessian Boar"); + + setStopAt(1, PhaseStep.END_TURN); + setStrictChooseMode(true); + try { + execute(); + Assert.fail("Expected exception, but not raise"); + } catch (UnsupportedOperationException ue) { + Assert.assertEquals("Balduvian Bears cannot block Nessian Boar it is already blocking the maximum amount of creatures.", ue.getMessage()); + } + //assertAllCommandsUsed(); // must have 1 missing command (block) + } + + @Test + public void test_AI_CantBlockAgain() { + removeAllCardsFromHand(playerA); + removeAllCardsFromHand(playerB); + + // All creatures able to block Nessian Boar do so. + // Whenever Nessian Boar becomes blocked by a creature, that creature’s controller draws a card. + addCard(Zone.BATTLEFIELD, playerA, "Nessian Boar", 1); + // + addCard(Zone.BATTLEFIELD, playerB, "Balduvian Bears", 1); + + // auto-block by requirement effect + attack(1, playerA, "Nessian Boar"); + // AI can't block same creature twice + aiPlayStep(1, PhaseStep.DECLARE_BLOCKERS, playerB); + + setStopAt(1, PhaseStep.END_TURN); + setStrictChooseMode(true); + execute(); + assertAllCommandsUsed(); + + assertGraveyardCount(playerA, 0); + assertGraveyardCount(playerB, 1); + assertHandCount(playerA, 0); + assertHandCount(playerB, 1); + } +} diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/requirement/BlockRequirementTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/requirement/BlockRequirementTest.java index 8cdd2f194b8..ee778d4e57c 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/requirement/BlockRequirementTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/requirement/BlockRequirementTest.java @@ -1,4 +1,3 @@ - package org.mage.test.cards.requirement; import mage.constants.PhaseStep; @@ -10,7 +9,6 @@ import static junit.framework.TestCase.assertEquals; import static org.junit.Assert.fail; /** - * * @author LevelX2, icetc */ public class BlockRequirementTest extends CardTestPlayerBase { @@ -91,7 +89,7 @@ public class BlockRequirementTest extends CardTestPlayerBase { /** * Elemental Uprising - "it must be blocked this turn if able", not working - * + *
* The bug just happened for me today as well - the problem is "must be
* blocked" is not being enforced correctly. During opponent's main phase
* they cast Elemental Uprising targeting an untapped land. They attacked
@@ -186,7 +184,7 @@ public class BlockRequirementTest extends CardTestPlayerBase {
attack(1, playerA, "Breaker of Armies");
// not allowed due to Breaker of Armies having menace
- block(1, playerB, "Hill Giant", "Breaker of Armies");
+ //block(1, playerB, "Hill Giant", "Breaker of Armies"); // auto-block from requrement effect must add blocker without command
setStopAt(1, PhaseStep.POSTCOMBAT_MAIN);
@@ -197,7 +195,7 @@ public class BlockRequirementTest extends CardTestPlayerBase {
assertEquals("Breaker of Armies is blocked by 1 creature(s). It has to be blocked by 2 or more.", e.getMessage());
}
}
-
+
/*
Reported bug: Slayer's Cleaver did not force Wretched Gryff (an eldrazi) to block
*/
@@ -225,7 +223,7 @@ public class BlockRequirementTest extends CardTestPlayerBase {
assertGraveyardCount(playerB, "Dimensional Infiltrator", 1);
assertGraveyardCount(playerB, "Llanowar Elves", 1);
}
-
+
/*
Reported bug: Challenger Troll on field not enforcing block restrictions
*/
@@ -237,30 +235,30 @@ public class BlockRequirementTest extends CardTestPlayerBase {
Each creature you control with power 4 or greater can’t be blocked by more than one creature.
*/
String cTroll = "Challenger Troll";
-
+
String bSable = "Bronze Sable"; // {2} 2/1
String hGiant = "Hill Giant"; // {3}{R} 3/3
-
+
addCard(Zone.BATTLEFIELD, playerA, cTroll);
addCard(Zone.BATTLEFIELD, playerB, bSable);
addCard(Zone.BATTLEFIELD, playerB, hGiant);
-
+
attack(1, playerA, cTroll);
// only 1 should be able to block it since Troll >=4 power block restriction
block(1, playerB, bSable, cTroll);
block(1, playerB, hGiant, cTroll);
-
+
setStopAt(1, PhaseStep.POSTCOMBAT_MAIN);
-
+
try {
execute();
fail("Expected exception not thrown");
} catch (UnsupportedOperationException e) {
assertEquals("Challenger Troll is blocked by 2 creature(s). It can only be blocked by 1 or less.", e.getMessage());
- }
+ }
}
-
+
/*
Reported bug: Challenger Troll on field not enforcing block restrictions
*/
@@ -273,29 +271,29 @@ public class BlockRequirementTest extends CardTestPlayerBase {
*/
String cTroll = "Challenger Troll";
String bHulk = "Bloom Hulk"; // {3}{G} 4/4 ETB: proliferate
-
+
String bSable = "Bronze Sable"; // {2} 2/1
String hGiant = "Hill Giant"; // {3}{R} 3/3
-
+
addCard(Zone.BATTLEFIELD, playerA, cTroll);
addCard(Zone.BATTLEFIELD, playerA, bHulk);
addCard(Zone.BATTLEFIELD, playerB, bSable);
addCard(Zone.BATTLEFIELD, playerB, hGiant);
-
+
attack(1, playerA, cTroll);
attack(1, playerA, bHulk);
// only 1 should be able to block Bloom Hulk since >=4 power and Troll on field
block(1, playerB, bSable, bHulk);
block(1, playerB, hGiant, bHulk);
-
+
setStopAt(1, PhaseStep.POSTCOMBAT_MAIN);
-
+
try {
execute();
fail("Expected exception not thrown");
} catch (UnsupportedOperationException e) {
assertEquals("Bloom Hulk is blocked by 2 creature(s). It can only be blocked by 1 or less.", e.getMessage());
- }
+ }
}
}
diff --git a/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java b/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java
index 672140af986..08fcf3c4658 100644
--- a/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java
+++ b/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java
@@ -112,6 +112,12 @@ public class TestPlayer implements Player {
computerPlayer.setTestPlayerLink(this);
}
+ public TestPlayer(TestComputerPlayerMonteCarlo computerPlayer) {
+ this.computerPlayer = computerPlayer;
+ AIPlayer = false;
+ computerPlayer.setTestPlayerLink(this);
+ }
+
public TestPlayer(final TestPlayer testPlayer) {
this.AIPlayer = testPlayer.AIPlayer;
this.AICanChooseInStrictMode = testPlayer.AICanChooseInStrictMode;
@@ -1411,6 +1417,16 @@ public class TestPlayer implements Player {
boolean madeAttackByAction = false;
for (Iterator