Tests - Added the possibility to attack planeswalker in tests- Added attack planeswalker test.

This commit is contained in:
LevelX2 2014-03-29 17:48:09 +01:00
parent b5ef4a7f45
commit 0d290a2431
4 changed files with 147 additions and 14 deletions

View file

@ -59,8 +59,8 @@ public class CrypticCommandTest extends CardTestPlayerBase {
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Thoughtseize", playerB);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerB, "Cryptic Command", "Thoughtseize");
setModeChoice(playerB, "0"); // Counter target spell
setModeChoice(playerB, "3"); // Draw a card
setModeChoice(playerB, "1"); // Counter target spell
setModeChoice(playerB, "4"); // Draw a card
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Remand", "Thoughtseize", "Cryptic Command");

View file

@ -0,0 +1,98 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package org.mage.test.combat;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import mage.counters.CounterType;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
/**
* Check if attacking a planswalker and removing loyality counter from damage works
*
* @author LevelX2
*/
public class AttackPlaneswalkerTest extends CardTestPlayerBase {
@Test
public void testAttackPlaneswalker() {
addCard(Zone.BATTLEFIELD, playerA, "Kiora, the Crashing Wave");
addCard(Zone.BATTLEFIELD, playerB, "Giant Tortoise");
attack(2, playerB, "Giant Tortoise", "Kiora, the Crashing Wave");
setStopAt(2, PhaseStep.END_TURN);
execute();
assertLife(playerA, 20);
assertLife(playerB, 20);
assertPermanentCount(playerA, "Kiora, the Crashing Wave", 1);
assertPermanentCount(playerB, "Giant Tortoise", 1);
assertCounterCount("Kiora, the Crashing Wave", CounterType.LOYALTY, 1);
}
/**
* Tests that giving a planeswalker hexproof does not prevent opponent from attacking it
*/
@Test
public void testAttackPlaneswalkerWithHexproof() {
/*
Simic Charm English
Instant, UG
Choose one Target creature gets +3/+3 until end of turn;
or permanents you control gain hexproof until end of turn;
or return target creature to its owner's hand.
*/
addCard(Zone.HAND, playerA, "Simic Charm");
addCard(Zone.BATTLEFIELD, playerA, "Island");
addCard(Zone.BATTLEFIELD, playerA, "Forest");
addCard(Zone.BATTLEFIELD, playerA, "Kiora, the Crashing Wave");
addCard(Zone.BATTLEFIELD, playerB, "Giant Tortoise");
castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerA, "Simic Charm");
setModeChoice(playerA, "2");
attack(2, playerB, "Giant Tortoise", "Kiora, the Crashing Wave");
setStopAt(2, PhaseStep.END_TURN);
execute();
assertLife(playerA, 20);
assertLife(playerB, 20);
assertPermanentCount(playerA, "Kiora, the Crashing Wave", 1);
assertPermanentCount(playerB, "Giant Tortoise", 1);
assertCounterCount("Kiora, the Crashing Wave", CounterType.LOYALTY, 1);
}
}

View file

@ -57,6 +57,7 @@ import java.util.UUID;
import mage.abilities.Mode;
import mage.abilities.Modes;
import mage.filter.common.FilterCreatureForCombatBlock;
import mage.filter.common.FilterPlaneswalkerPermanent;
import mage.game.stack.StackObject;
/**
@ -147,16 +148,34 @@ public class TestPlayer extends ComputerPlayer<TestPlayer> {
@Override
public void selectAttackers(Game game, UUID attackingPlayerId) {
UUID opponentId = game.getCombat().getDefenders().iterator().next();
UUID defenderId = null;
for (PlayerAction action: actions) {
if (action.getTurnNum() == game.getTurnNum() && action.getAction().startsWith("attack:")) {
for (UUID uuid: game.getCombat().getDefenders()) {
Player defender = game.getPlayer(uuid);
if (defender != null) {
defenderId = uuid;
}
}
String command = action.getAction();
command = command.substring(command.indexOf("attack:") + 7);
String[] groups = command.split(";");
for (int i = 1; i < groups.length; i++) {
String group = groups[i];
if (group.startsWith("planeswalker=")) {
String planeswalkerName = group.substring(group.indexOf("planeswalker=") + 13);
for (Permanent permanent :game.getBattlefield().getAllActivePermanents(new FilterPlaneswalkerPermanent(), game)) {
if (permanent.getName().equals(planeswalkerName)) {
defenderId = permanent.getId();
}
}
}
}
FilterCreatureForCombat filter = new FilterCreatureForCombat();
filter.add(new NamePredicate(command));
filter.add(new NamePredicate(groups[0]));
Permanent attacker = findPermanent(filter, playerId, game);
if (attacker != null && attacker.canAttack(game)) {
this.declareAttacker(attacker.getId(), opponentId, game);
this.declareAttacker(attacker.getId(), defenderId, game);
}
}
}
@ -189,7 +208,7 @@ public class TestPlayer extends ComputerPlayer<TestPlayer> {
public Mode chooseMode(Modes modes, Ability source, Game game) {
if (!modesSet.isEmpty() && modes.getMaxModes() > modes.getSelectedModes().size()) {
int selectedMode = Integer.parseInt(modesSet.get(0));
int i = 0;
int i = 1;
for (Mode mode: modes.values()) {
if (i == selectedMode) {
modesSet.remove(0);

View file

@ -256,18 +256,24 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
public void assertResult(Player player, GameResult result) throws AssertionError {
if (player.equals(playerA)) {
GameResult actual = CardTestAPI.GameResult.DRAW;
if (currentGame.getWinner().equals("Player PlayerA is the winner")) {
actual = CardTestAPI.GameResult.WON;
} else if (currentGame.getWinner().equals("Player PlayerB is the winner")) {
actual = CardTestAPI.GameResult.LOST;
switch (currentGame.getWinner()) {
case "Player PlayerA is the winner":
actual = CardTestAPI.GameResult.WON;
break;
case "Player PlayerB is the winner":
actual = CardTestAPI.GameResult.LOST;
break;
}
Assert.assertEquals("Game results are not equal", result, actual);
} else if (player.equals(playerB)) {
GameResult actual = CardTestAPI.GameResult.DRAW;
if (currentGame.getWinner().equals("Player PlayerB is the winner")) {
actual = CardTestAPI.GameResult.WON;
} else if (currentGame.getWinner().equals("Player PlayerA is the winner")) {
actual = CardTestAPI.GameResult.LOST;
switch (currentGame.getWinner()) {
case "Player PlayerB is the winner":
actual = CardTestAPI.GameResult.WON;
break;
case "Player PlayerA is the winner":
actual = CardTestAPI.GameResult.LOST;
break;
}
Assert.assertEquals("Game results are not equal", result, actual);
}
@ -668,6 +674,10 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
player.addAction(turnNum, PhaseStep.DECLARE_ATTACKERS, "attack:"+attacker);
}
public void attack(int turnNum, TestPlayer player, String attacker, String planeswalker) {
player.addAction(turnNum, PhaseStep.DECLARE_ATTACKERS, new StringBuilder("attack:").append(attacker).append(";planeswalker=").append(planeswalker).toString());
}
public void block(int turnNum, TestPlayer player, String blocker, String attacker) {
player.addAction(turnNum, PhaseStep.DECLARE_BLOCKERS, "block:"+blocker+";"+attacker);
}
@ -676,6 +686,12 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
player.addChoice(choice);
}
/**
* Set the modes for modal spells
*
* @param player
* @param choice starting with "1" for mode 1, "2" for mode 2 and so on (to set multiple modes call the command multiple times)
*/
public void setModeChoice(TestPlayer player, String choice) {
player.addModeChoice(choice);
}