mirror of
https://github.com/correl/mage.git
synced 2025-04-04 17:00:13 -09:00
Updated test framework with minimum functionality.
This commit is contained in:
parent
ec7da844a4
commit
a3d590fc79
20 changed files with 220 additions and 136 deletions
Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai
Mage.Tests
plugins
mage-deck-constructed.jarmage-deck-limited.jarmage-game-twoplayerduel.jarmage-player-ai-ma.jarmage-player-aiminimax.jarmage-tournament-booster-draft.jar
src/test/java/org/mage/test/serverside
Mage/src/mage/players
|
@ -52,8 +52,10 @@ import mage.game.stack.StackAbility;
|
|||
import mage.game.stack.StackObject;
|
||||
import mage.game.turn.*;
|
||||
import mage.players.Player;
|
||||
import mage.sets.alarareborn.OfferingToAsha;
|
||||
import mage.target.Target;
|
||||
import mage.target.TargetCard;
|
||||
import sun.rmi.transport.ObjectTable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
@ -197,6 +199,17 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
|||
this.activateAbility((ActivatedAbility) ability, game);
|
||||
if (ability.isUsesStack())
|
||||
usedStack = true;
|
||||
if (!suggested.isEmpty()) {
|
||||
Iterator<String> it = suggested.iterator();
|
||||
while (it.hasNext()) {
|
||||
Card card = game.getCard(ability.getSourceId());
|
||||
String action = it.next();
|
||||
if (action.equals(card.getName())) {
|
||||
System.out.println("removed from suggested="+action);
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (usedStack)
|
||||
pass();
|
||||
|
@ -233,6 +246,9 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
|||
root = root.children.get(0);
|
||||
}
|
||||
logger.info("simlating -- game value:" + game.getState().getValue() + " test value:" + test.gameValue);
|
||||
if (!suggested.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
if (root.playerId.equals(playerId) && root.abilities != null && game.getState().getValue().hashCode() == test.gameValue) {
|
||||
|
||||
/*
|
||||
|
@ -467,13 +483,7 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
|||
SimulationNode2 newNode = new SimulationNode2(node, sim, action, depth, currentPlayer.getId());
|
||||
logger.debug("simulating -- node #:" + SimulationNode2.getCount() + " actions:" + action);
|
||||
sim.checkStateAndTriggered();
|
||||
if (depth == 20) {
|
||||
logger.info("*** Action *** " + action.toString());
|
||||
}
|
||||
int val = addActions(newNode, depth-1, alpha, beta);
|
||||
if (depth == 20) {
|
||||
logger.info("*** Value *** " + val);
|
||||
}
|
||||
if (!currentPlayer.getId().equals(playerId)) {
|
||||
if (val < beta) {
|
||||
beta = val;
|
||||
|
@ -768,6 +778,7 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
|||
|
||||
for (Player copyPlayer: sim.getState().getPlayers().values()) {
|
||||
Player origPlayer = game.getState().getPlayers().get(copyPlayer.getId()).copy();
|
||||
System.out.println("suggested=" + suggested);
|
||||
SimulatedPlayer2 newPlayer = new SimulatedPlayer2(copyPlayer.getId(), copyPlayer.getId().equals(playerId), suggested);
|
||||
newPlayer.restore(origPlayer);
|
||||
sim.getState().getPlayers().put(copyPlayer.getId(), newPlayer);
|
||||
|
@ -812,4 +823,12 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAction(String action) {
|
||||
System.out.println("adding to suggested actions: " + action);
|
||||
if (action != null && action.startsWith("cast:") || action.startsWith("play:")) {
|
||||
suggested.add(action.substring(5, action.length()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -32,7 +32,7 @@ public class PlayGameTest extends MageTestBase {
|
|||
Game game = new TwoPlayerDuel(Constants.MultiplayerAttackOption.LEFT, Constants.RangeOfInfluence.ALL);
|
||||
|
||||
Player computerA = createPlayer("ComputerA", "Computer - minimax hybrid");
|
||||
// Player computerA = createPlayer("ComputerA", "Computer - mad");
|
||||
// Player playerA = createPlayer("ComputerA", "Computer - mad");
|
||||
// Deck deck = Deck.load(Sets.loadDeck("RB Aggro.dck"));
|
||||
Deck deck = generateRandomDeck();
|
||||
|
||||
|
@ -43,7 +43,7 @@ public class PlayGameTest extends MageTestBase {
|
|||
game.loadCards(deck.getCards(), computerA.getId());
|
||||
|
||||
Player computerB = createPlayer("ComputerB", "Computer - minimax hybrid");
|
||||
// Player computerB = createPlayer("ComputerB", "Computer - mad");
|
||||
// Player playerB = createPlayer("ComputerB", "Computer - mad");
|
||||
// Deck deck2 = Deck.load(Sets.loadDeck("RB Aggro.dck"));
|
||||
Deck deck2 = generateRandomDeck();
|
||||
if (deck2.getCards().size() < 40) {
|
||||
|
@ -53,10 +53,10 @@ public class PlayGameTest extends MageTestBase {
|
|||
game.loadCards(deck2.getCards(), computerB.getId());
|
||||
|
||||
// parseScenario("scenario1.txt");
|
||||
// game.cheat(computerA.getId(), commandsA);
|
||||
// game.cheat(computerA.getId(), libraryCardsA, handCardsA, battlefieldCardsA, graveyardCardsA);
|
||||
// game.cheat(computerB.getId(), commandsB);
|
||||
// game.cheat(computerB.getId(), libraryCardsB, handCardsB, battlefieldCardsB, graveyardCardsB);
|
||||
// game.cheat(playerA.getId(), commandsA);
|
||||
// game.cheat(playerA.getId(), libraryCardsA, handCardsA, battlefieldCardsA, graveyardCardsA);
|
||||
// game.cheat(playerB.getId(), commandsB);
|
||||
// game.cheat(playerB.getId(), libraryCardsB, handCardsB, battlefieldCardsB, graveyardCardsB);
|
||||
|
||||
//boolean testMode = false;
|
||||
boolean testMode = true;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.mage.test.serverside.ai;
|
||||
|
||||
import mage.Constants;
|
||||
import mage.filter.Filter;
|
||||
import org.junit.Test;
|
||||
import org.mage.test.serverside.base.CardTestBase;
|
||||
|
||||
|
@ -15,22 +14,22 @@ public class BugDoesntAttackWithKnightTest extends CardTestBase {
|
|||
@Test
|
||||
public void testVersusInfectCreature() throws Exception {
|
||||
useRedDefault();
|
||||
addCard(Constants.Zone.HAND, computerA, "Zephyr Sprite");
|
||||
addCard(Constants.Zone.HAND, computerA, "Island");
|
||||
addCard(Constants.Zone.HAND, computerA, "Rupture Spire");
|
||||
setLife(computerB, 1);
|
||||
addCard(Constants.Zone.HAND, playerA, "Zephyr Sprite");
|
||||
addCard(Constants.Zone.HAND, playerA, "Island");
|
||||
addCard(Constants.Zone.HAND, playerA, "Rupture Spire");
|
||||
setLife(playerB, 1);
|
||||
|
||||
setStopOnTurn(4);
|
||||
execute();
|
||||
|
||||
// life:ComputerB:0
|
||||
assertLife(computerB, 0);
|
||||
assertLife(playerB, 0);
|
||||
// turn:1
|
||||
assertTurn(3);
|
||||
// result:won
|
||||
assertResult(computerA, GameResult.WON);
|
||||
assertResult(playerA, GameResult.WON);
|
||||
// life:ComputerA:20
|
||||
assertLife(computerA, 20);
|
||||
assertLife(playerA, 20);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,14 +18,14 @@ public class BugTapsItselfTest extends CardTestBase {
|
|||
@Test
|
||||
public void testVersusInfectCreature() throws Exception {
|
||||
useWhiteDefault();
|
||||
addCard(Constants.Zone.BATTLEFIELD, computerA, "Blinding Mage");
|
||||
addCard(Constants.Zone.BATTLEFIELD, computerB, "Myr Sire");
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerA, "Blinding Mage");
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerB, "Myr Sire");
|
||||
|
||||
setStopOnTurn(4);
|
||||
execute();
|
||||
|
||||
assertResult(computerA, GameResult.DRAW);
|
||||
Permanent permanent = getPermanent("Blinding Mage", computerA.getId());
|
||||
assertResult(playerA, GameResult.DRAW);
|
||||
Permanent permanent = getPermanent("Blinding Mage", playerA.getId());
|
||||
Assert.assertFalse("Should have been untapped", permanent.isTapped());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
package org.mage.test.serverside.base;
|
||||
|
||||
import mage.Constants;
|
||||
import mage.abilities.Ability;
|
||||
import mage.filter.Filter;
|
||||
import mage.players.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Interface for all test initialization and assertion operations.
|
||||
*/
|
||||
|
@ -37,7 +40,7 @@ public interface CardTestAPI {
|
|||
* Add a card to specified zone of specified player.
|
||||
*
|
||||
* @param gameZone {@link Constants.Zone} to add cards to.
|
||||
* @param player {@link Player} to add cards for. Use either computerA or computerB.
|
||||
* @param player {@link Player} to add cards for. Use either playerA or playerB.
|
||||
* @param cardName Card name in string format.
|
||||
*/
|
||||
void addCard(Constants.Zone gameZone, Player player, String cardName);
|
||||
|
@ -46,7 +49,7 @@ public interface CardTestAPI {
|
|||
* Add any amount of cards to specified zone of specified player.
|
||||
*
|
||||
* @param gameZone {@link Constants.Zone} to add cards to.
|
||||
* @param player {@link Player} to add cards for. Use either computerA or computerB.
|
||||
* @param player {@link Player} to add cards for. Use either playerA or playerB.
|
||||
* @param cardName Card name in string format.
|
||||
* @param count Amount of cards to be added.
|
||||
*/
|
||||
|
@ -56,7 +59,7 @@ public interface CardTestAPI {
|
|||
* Add any amount of cards to specified zone of specified player.
|
||||
*
|
||||
* @param gameZone {@link Constants.Zone} to add cards to.
|
||||
* @param player {@link Player} to add cards for. Use either computerA or computerB.
|
||||
* @param player {@link Player} to add cards for. Use either playerA or playerB.
|
||||
* @param cardName Card name in string format.
|
||||
* @param count Amount of cards to be added.
|
||||
* @param tapped In case gameZone is Battlefield, determines whether permanent should be tapped.
|
||||
|
@ -124,6 +127,21 @@ public interface CardTestAPI {
|
|||
void assertPowerToughness(Player player, String cardName, int power, int toughness, Filter.ComparisonScope scope)
|
||||
throws AssertionError;
|
||||
|
||||
/**
|
||||
* Assert creature's abilities.
|
||||
* <p/>
|
||||
* Throws {@link AssertionError} in the following cases:
|
||||
* 1. no such player
|
||||
* 2. no such creature under player's control
|
||||
* 3. there is more than one creature with such name
|
||||
*
|
||||
* @param player {@link Player} to get creatures for comparison.
|
||||
* @param cardName Card name to compare with.
|
||||
* @param abilities Expected abilities
|
||||
*/
|
||||
void assertAbilities(Player player, String cardName, List<Ability> abilities)
|
||||
throws AssertionError;
|
||||
|
||||
/**
|
||||
* Assert permanent count under player's control.
|
||||
*
|
||||
|
|
|
@ -65,31 +65,33 @@ public abstract class CardTestBase extends CardTestAPIImpl {
|
|||
|
||||
Game game = new TwoPlayerDuel(Constants.MultiplayerAttackOption.LEFT, Constants.RangeOfInfluence.ALL);
|
||||
|
||||
computerA = aiTypeA.equals(CardTestBase.AIType.MinimaxHybrid) ?
|
||||
playerA = aiTypeA.equals(CardTestBase.AIType.MinimaxHybrid) ?
|
||||
createPlayer("ComputerA", "Computer - minimax hybrid") :
|
||||
createPlayer("ComputerA", "Computer - mad");
|
||||
computerA.setTestMode(true);
|
||||
playerA.setTestMode(true);
|
||||
logger.info("Loading deck...");
|
||||
Deck deck = Deck.load(Sets.loadDeck("RB Aggro.dck"));
|
||||
logger.info("Done!");
|
||||
if (deck.getCards().size() < 40) {
|
||||
throw new IllegalArgumentException("Couldn't load deck, deck size=" + deck.getCards().size());
|
||||
}
|
||||
game.addPlayer(computerA, deck);
|
||||
game.loadCards(deck.getCards(), computerA.getId());
|
||||
game.addPlayer(playerA, deck);
|
||||
game.loadCards(deck.getCards(), playerA.getId());
|
||||
|
||||
computerB = aiTypeB.equals(CardTestBase.AIType.MinimaxHybrid) ?
|
||||
playerB = aiTypeB.equals(CardTestBase.AIType.MinimaxHybrid) ?
|
||||
createPlayer("ComputerB", "Computer - minimax hybrid") :
|
||||
createPlayer("ComputerB", "Computer - mad");
|
||||
computerB.setTestMode(true);
|
||||
playerB.setTestMode(true);
|
||||
Deck deck2 = Deck.load(Sets.loadDeck("RB Aggro.dck"));
|
||||
if (deck2.getCards().size() < 40) {
|
||||
throw new IllegalArgumentException("Couldn't load deck, deck size=" + deck2.getCards().size());
|
||||
}
|
||||
game.addPlayer(computerB, deck2);
|
||||
game.loadCards(deck2.getCards(), computerB.getId());
|
||||
activePlayer = computerA;
|
||||
game.addPlayer(playerB, deck2);
|
||||
game.loadCards(deck2.getCards(), playerB.getId());
|
||||
activePlayer = playerA;
|
||||
currentGame = game;
|
||||
|
||||
stopOnTurn = null;
|
||||
stopOnTurn = 2;
|
||||
handCardsA.clear();
|
||||
handCardsB.clear();
|
||||
battlefieldCardsA.clear();
|
||||
|
@ -124,33 +126,33 @@ public abstract class CardTestBase extends CardTestAPIImpl {
|
|||
|
||||
Game game = new TwoPlayerDuel(Constants.MultiplayerAttackOption.LEFT, Constants.RangeOfInfluence.ALL);
|
||||
|
||||
computerA = aiTypeA.equals(CardTestBase.AIType.MinimaxHybrid) ?
|
||||
playerA = aiTypeA.equals(CardTestBase.AIType.MinimaxHybrid) ?
|
||||
createPlayer("ComputerA", "Computer - minimax hybrid") :
|
||||
createPlayer("ComputerA", "Computer - mad");
|
||||
computerA.setTestMode(true);
|
||||
playerA.setTestMode(true);
|
||||
|
||||
Deck deck = Deck.load(Sets.loadDeck("RB Aggro.dck"));
|
||||
|
||||
if (deck.getCards().size() < 40) {
|
||||
throw new IllegalArgumentException("Couldn't load deck, deck size=" + deck.getCards().size());
|
||||
}
|
||||
game.addPlayer(computerA, deck);
|
||||
game.loadCards(deck.getCards(), computerA.getId());
|
||||
game.addPlayer(playerA, deck);
|
||||
game.loadCards(deck.getCards(), playerA.getId());
|
||||
|
||||
computerB = aiTypeB.equals(CardTestBase.AIType.MinimaxHybrid) ?
|
||||
playerB = aiTypeB.equals(CardTestBase.AIType.MinimaxHybrid) ?
|
||||
createPlayer("ComputerB", "Computer - minimax hybrid") :
|
||||
createPlayer("ComputerB", "Computer - mad");
|
||||
computerB.setTestMode(true);
|
||||
playerB.setTestMode(true);
|
||||
Deck deck2 = Deck.load(Sets.loadDeck("RB Aggro.dck"));
|
||||
if (deck2.getCards().size() < 40) {
|
||||
throw new IllegalArgumentException("Couldn't load deck, deck size=" + deck2.getCards().size());
|
||||
}
|
||||
game.addPlayer(computerB, deck2);
|
||||
game.loadCards(deck2.getCards(), computerB.getId());
|
||||
game.addPlayer(playerB, deck2);
|
||||
game.loadCards(deck2.getCards(), playerB.getId());
|
||||
|
||||
parseScenario(cardPath);
|
||||
|
||||
activePlayer = computerA;
|
||||
activePlayer = playerA;
|
||||
currentGame = game;
|
||||
}
|
||||
|
||||
|
@ -164,10 +166,10 @@ public abstract class CardTestBase extends CardTestAPIImpl {
|
|||
throw new IllegalStateException("Game is not initialized. Use load method to load a test case and initialize a game.");
|
||||
}
|
||||
|
||||
currentGame.cheat(computerA.getId(), commandsA);
|
||||
currentGame.cheat(computerA.getId(), libraryCardsA, handCardsA, battlefieldCardsA, graveyardCardsA);
|
||||
currentGame.cheat(computerB.getId(), commandsB);
|
||||
currentGame.cheat(computerB.getId(), libraryCardsB, handCardsB, battlefieldCardsB, graveyardCardsB);
|
||||
currentGame.cheat(playerA.getId(), commandsA);
|
||||
currentGame.cheat(playerA.getId(), libraryCardsA, handCardsA, battlefieldCardsA, graveyardCardsA);
|
||||
currentGame.cheat(playerB.getId(), commandsB);
|
||||
currentGame.cheat(playerB.getId(), libraryCardsB, handCardsB, battlefieldCardsB, graveyardCardsB);
|
||||
|
||||
boolean testMode = true;
|
||||
long t1 = System.nanoTime();
|
||||
|
@ -242,10 +244,10 @@ public abstract class CardTestBase extends CardTestAPIImpl {
|
|||
String player = getStringParam(line, 1);
|
||||
int expected = getIntParam(line, 2);
|
||||
if (player.equals("ComputerA")) {
|
||||
int actual = currentGame.getPlayer(computerA.getId()).getLife();
|
||||
int actual = currentGame.getPlayer(playerA.getId()).getLife();
|
||||
Assert.assertEquals("Life amounts are not equal", expected, actual);
|
||||
} else if (player.equals("ComputerB")) {
|
||||
int actual = currentGame.getPlayer(computerB.getId()).getLife();
|
||||
int actual = currentGame.getPlayer(playerB.getId()).getLife();
|
||||
Assert.assertEquals("Life amounts are not equal", expected, actual);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Wrong player in 'life' line, player=" + player + ", line=" + line);
|
||||
|
@ -258,9 +260,9 @@ public abstract class CardTestBase extends CardTestAPIImpl {
|
|||
int expectedCount = getIntParam(line, 3);
|
||||
Player player = null;
|
||||
if (playerName.equals("ComputerA")) {
|
||||
player = currentGame.getPlayer(computerA.getId());
|
||||
player = currentGame.getPlayer(playerA.getId());
|
||||
} else if (playerName.equals("ComputerB")) {
|
||||
player = currentGame.getPlayer(computerB.getId());
|
||||
player = currentGame.getPlayer(playerB.getId());
|
||||
} else {
|
||||
throw new IllegalArgumentException("Wrong player in 'battlefield' line, player=" + player + ", line=" + line);
|
||||
}
|
||||
|
@ -281,9 +283,9 @@ public abstract class CardTestBase extends CardTestAPIImpl {
|
|||
int expectedCount = getIntParam(line, 3);
|
||||
Player player = null;
|
||||
if (playerName.equals("ComputerA")) {
|
||||
player = currentGame.getPlayer(computerA.getId());
|
||||
player = currentGame.getPlayer(playerA.getId());
|
||||
} else if (playerName.equals("ComputerB")) {
|
||||
player = currentGame.getPlayer(computerB.getId());
|
||||
player = currentGame.getPlayer(playerB.getId());
|
||||
} else {
|
||||
throw new IllegalArgumentException("Wrong player in 'graveyard' line, player=" + player + ", line=" + line);
|
||||
}
|
||||
|
|
|
@ -54,8 +54,8 @@ public abstract class MageTestBase {
|
|||
protected Map<Constants.Zone, String> commandsA = new HashMap<Constants.Zone, String>();
|
||||
protected Map<Constants.Zone, String> commandsB = new HashMap<Constants.Zone, String>();
|
||||
|
||||
protected Player computerA;
|
||||
protected Player computerB;
|
||||
protected Player playerA;
|
||||
protected Player playerB;
|
||||
|
||||
/**
|
||||
* Game instance initialized in load method.
|
||||
|
@ -293,6 +293,6 @@ public abstract class MageTestBase {
|
|||
}
|
||||
|
||||
protected Player createPlayer(String name, String playerType) {
|
||||
return PlayerFactory.getInstance().createPlayer(playerType, name, Constants.RangeOfInfluence.ALL, 1);
|
||||
return PlayerFactory.getInstance().createPlayer(playerType, name, Constants.RangeOfInfluence.ALL, 10);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.util.List;
|
|||
import java.util.UUID;
|
||||
|
||||
import mage.Constants;
|
||||
import mage.abilities.Ability;
|
||||
import mage.cards.Card;
|
||||
import mage.filter.Filter;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
@ -28,23 +29,23 @@ public abstract class CardTestAPIImpl extends MageTestBase implements CardTestAP
|
|||
public void useRedDefault() {
|
||||
// *** ComputerA ***
|
||||
// battlefield:ComputerA:Mountain:5
|
||||
addCard(Constants.Zone.BATTLEFIELD, computerA, "Mountain", 5);
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerA, "Mountain", 5);
|
||||
// hand:ComputerA:Mountain:4
|
||||
addCard(Constants.Zone.HAND, computerA, "Mountain", 5);
|
||||
addCard(Constants.Zone.HAND, playerA, "Mountain", 5);
|
||||
// library:ComputerA:clear:0
|
||||
removeAllCardsFromLibrary(computerA);
|
||||
removeAllCardsFromLibrary(playerA);
|
||||
// library:ComputerA:Mountain:10
|
||||
addCard(Constants.Zone.LIBRARY, computerA, "Mountain", 10);
|
||||
addCard(Constants.Zone.LIBRARY, playerA, "Mountain", 10);
|
||||
|
||||
// *** ComputerB ***
|
||||
// battlefield:ComputerB:Plains:2
|
||||
addCard(Constants.Zone.BATTLEFIELD, computerB, "Plains", 2);
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerB, "Plains", 2);
|
||||
// hand:ComputerB:Plains:2
|
||||
addCard(Constants.Zone.HAND, computerB, "Plains", 2);
|
||||
addCard(Constants.Zone.HAND, playerB, "Plains", 2);
|
||||
// library:ComputerB:clear:0
|
||||
removeAllCardsFromLibrary(computerB);
|
||||
removeAllCardsFromLibrary(playerB);
|
||||
// library:ComputerB:Plains:10
|
||||
addCard(Constants.Zone.LIBRARY, computerB, "Plains", 10);
|
||||
addCard(Constants.Zone.LIBRARY, playerB, "Plains", 10);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -52,16 +53,16 @@ public abstract class CardTestAPIImpl extends MageTestBase implements CardTestAP
|
|||
*/
|
||||
public void useWhiteDefault() {
|
||||
// *** ComputerA ***
|
||||
addCard(Constants.Zone.BATTLEFIELD, computerA, "Plains", 5);
|
||||
addCard(Constants.Zone.HAND, computerA, "Plains", 5);
|
||||
removeAllCardsFromLibrary(computerA);
|
||||
addCard(Constants.Zone.LIBRARY, computerA, "Plains", 10);
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerA, "Plains", 5);
|
||||
addCard(Constants.Zone.HAND, playerA, "Plains", 5);
|
||||
removeAllCardsFromLibrary(playerA);
|
||||
addCard(Constants.Zone.LIBRARY, playerA, "Plains", 10);
|
||||
|
||||
// *** ComputerB ***
|
||||
addCard(Constants.Zone.BATTLEFIELD, computerB, "Plains", 2);
|
||||
addCard(Constants.Zone.HAND, computerB, "Plains", 2);
|
||||
removeAllCardsFromLibrary(computerB);
|
||||
addCard(Constants.Zone.LIBRARY, computerB, "Plains", 10);
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerB, "Plains", 2);
|
||||
addCard(Constants.Zone.HAND, playerB, "Plains", 2);
|
||||
removeAllCardsFromLibrary(playerB);
|
||||
addCard(Constants.Zone.LIBRARY, playerB, "Plains", 10);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -71,9 +72,9 @@ public abstract class CardTestAPIImpl extends MageTestBase implements CardTestAP
|
|||
* @param player {@link Player} to remove all library cards from.
|
||||
*/
|
||||
public void removeAllCardsFromLibrary(Player player) {
|
||||
if (player.equals(computerA)) {
|
||||
if (player.equals(playerA)) {
|
||||
commandsA.put(Constants.Zone.LIBRARY, "clear");
|
||||
} else if (player.equals(computerB)) {
|
||||
} else if (player.equals(playerB)) {
|
||||
commandsB.put(Constants.Zone.LIBRARY, "clear");
|
||||
}
|
||||
}
|
||||
|
@ -82,7 +83,7 @@ public abstract class CardTestAPIImpl extends MageTestBase implements CardTestAP
|
|||
* Add a card to specified zone of specified player.
|
||||
*
|
||||
* @param gameZone {@link Constants.Zone} to add cards to.
|
||||
* @param player {@link Player} to add cards for. Use either computerA or computerB.
|
||||
* @param player {@link Player} to add cards for. Use either playerA or playerB.
|
||||
* @param cardName Card name in string format.
|
||||
*/
|
||||
public void addCard(Constants.Zone gameZone, Player player, String cardName) {
|
||||
|
@ -93,7 +94,7 @@ public abstract class CardTestAPIImpl extends MageTestBase implements CardTestAP
|
|||
* Add any amount of cards to specified zone of specified player.
|
||||
*
|
||||
* @param gameZone {@link Constants.Zone} to add cards to.
|
||||
* @param player {@link Player} to add cards for. Use either computerA or computerB.
|
||||
* @param player {@link Player} to add cards for. Use either playerA or playerB.
|
||||
* @param cardName Card name in string format.
|
||||
* @param count Amount of cards to be added.
|
||||
*/
|
||||
|
@ -105,7 +106,7 @@ public abstract class CardTestAPIImpl extends MageTestBase implements CardTestAP
|
|||
* Add any amount of cards to specified zone of specified player.
|
||||
*
|
||||
* @param gameZone {@link Constants.Zone} to add cards to.
|
||||
* @param player {@link Player} to add cards for. Use either computerA or computerB.
|
||||
* @param player {@link Player} to add cards for. Use either playerA or playerB.
|
||||
* @param cardName Card name in string format.
|
||||
* @param count Amount of cards to be added.
|
||||
* @param tapped In case gameZone is Battlefield, determines whether permanent should be tapped.
|
||||
|
@ -119,9 +120,9 @@ public abstract class CardTestAPIImpl extends MageTestBase implements CardTestAP
|
|||
Card card = Sets.findCard(cardName, true);
|
||||
PermanentCard p = new PermanentCard(card, null);
|
||||
p.setTapped(tapped);
|
||||
if (player.equals(computerA)) {
|
||||
if (player.equals(playerA)) {
|
||||
battlefieldCardsA.add(p);
|
||||
} else if (player.equals(computerB)) {
|
||||
} else if (player.equals(playerB)) {
|
||||
battlefieldCardsB.add(p);
|
||||
}
|
||||
}
|
||||
|
@ -145,7 +146,7 @@ public abstract class CardTestAPIImpl extends MageTestBase implements CardTestAP
|
|||
* @return
|
||||
*/
|
||||
private List<Card> getCardList(Constants.Zone gameZone, Player player) {
|
||||
if (player.equals(computerA)) {
|
||||
if (player.equals(playerA)) {
|
||||
if (gameZone.equals(Constants.Zone.HAND)) {
|
||||
return handCardsA;
|
||||
} else if (gameZone.equals(Constants.Zone.GRAVEYARD)) {
|
||||
|
@ -153,7 +154,7 @@ public abstract class CardTestAPIImpl extends MageTestBase implements CardTestAP
|
|||
} else if (gameZone.equals(Constants.Zone.LIBRARY)) {
|
||||
return libraryCardsA;
|
||||
}
|
||||
} else if (player.equals(computerB)) {
|
||||
} else if (player.equals(playerB)) {
|
||||
if (gameZone.equals(Constants.Zone.HAND)) {
|
||||
return handCardsB;
|
||||
} else if (gameZone.equals(Constants.Zone.GRAVEYARD)) {
|
||||
|
@ -172,9 +173,9 @@ public abstract class CardTestAPIImpl extends MageTestBase implements CardTestAP
|
|||
* @param life Life count to set.
|
||||
*/
|
||||
public void setLife(Player player, int life) {
|
||||
if (player.equals(computerA)) {
|
||||
if (player.equals(playerA)) {
|
||||
commandsA.put(Constants.Zone.OUTSIDE, "life:" + String.valueOf(life));
|
||||
} else if (player.equals(computerB)) {
|
||||
} else if (player.equals(playerB)) {
|
||||
commandsB.put(Constants.Zone.OUTSIDE, "life:" + String.valueOf(life));
|
||||
}
|
||||
}
|
||||
|
@ -201,7 +202,7 @@ public abstract class CardTestAPIImpl extends MageTestBase implements CardTestAP
|
|||
* @param result Expected {@link GameResult} to compare with.
|
||||
*/
|
||||
public void assertResult(Player player, GameResult result) throws AssertionError {
|
||||
if (player.equals(computerA)) {
|
||||
if (player.equals(playerA)) {
|
||||
GameResult actual = CardTestAPI.GameResult.DRAW;
|
||||
if (currentGame.getWinner().equals("Player ComputerA is the winner")) {
|
||||
actual = CardTestAPI.GameResult.WON;
|
||||
|
@ -209,7 +210,7 @@ public abstract class CardTestAPIImpl extends MageTestBase implements CardTestAP
|
|||
actual = CardTestAPI.GameResult.LOST;
|
||||
}
|
||||
Assert.assertEquals("Game results are not equal", result, actual);
|
||||
} else if (player.equals(computerB)) {
|
||||
} else if (player.equals(playerB)) {
|
||||
GameResult actual = CardTestAPI.GameResult.DRAW;
|
||||
if (currentGame.getWinner().equals("Player ComputerB is the winner")) {
|
||||
actual = CardTestAPI.GameResult.WON;
|
||||
|
@ -278,6 +279,31 @@ public abstract class CardTestAPIImpl extends MageTestBase implements CardTestAP
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void assertAbilities(Player player, String cardName, List<Ability> abilities)
|
||||
throws AssertionError {
|
||||
int count = 0;
|
||||
Permanent found = null;
|
||||
for (Permanent permanent : currentGame.getBattlefield().getAllActivePermanents(player.getId())) {
|
||||
if (permanent.getName().equals(cardName)) {
|
||||
found = permanent;
|
||||
}
|
||||
}
|
||||
|
||||
Assert.assertNotNull("There is no such permanent under player's control, player=" + player.getName() +
|
||||
", cardName=" + cardName, found);
|
||||
|
||||
Assert.assertTrue("There is more than one such permanent under player's control, player=" + player.getName() +
|
||||
", cardName=" + cardName, count == 1);
|
||||
|
||||
for (Ability ability : abilities) {
|
||||
Assert.assertTrue("No such ability=" + ability.toString() + ", player=" + player.getName() +
|
||||
", cardName" + cardName, found.getAbilities().contains(ability));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert permanent count under player's control.
|
||||
*
|
||||
|
@ -328,4 +354,19 @@ public abstract class CardTestAPIImpl extends MageTestBase implements CardTestAP
|
|||
Assert.assertEquals("More than one permanent was found: " + cardName + "(" + count + ")", 1, count);
|
||||
return permanent0;
|
||||
}
|
||||
|
||||
public void playLand(Player player, String cardName) {
|
||||
player.addAction("play:"+cardName);
|
||||
}
|
||||
|
||||
public void castSpell(Player player, String cardName) {
|
||||
player.addAction("cast:"+cardName);
|
||||
}
|
||||
|
||||
public void castSpell(Player player, String cardName, String target) {
|
||||
player.addAction("cast:"+cardName + ";" + target);
|
||||
}
|
||||
|
||||
public void useAbility(Player player, String cardName) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.mage.test.serverside.cards.abilities;
|
||||
|
||||
import mage.Constants;
|
||||
import mage.filter.Filter;
|
||||
import org.junit.Test;
|
||||
import org.mage.test.serverside.base.CardTestAPI;
|
||||
import org.mage.test.serverside.base.CardTestBase;
|
||||
|
@ -14,44 +13,44 @@ public class ProtectionFromColorTest extends CardTestBase {
|
|||
@Test
|
||||
public void testAgainstAbilityInTheStack() {
|
||||
useRedDefault();
|
||||
addCard(Constants.Zone.BATTLEFIELD, computerA, "Royal Assassin");
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerA, "Royal Assassin");
|
||||
|
||||
// tapped White Knight with Protection from Black
|
||||
addCard(Constants.Zone.BATTLEFIELD, computerB, "White Knight", 1, true);
|
||||
addCard(Constants.Zone.BATTLEFIELD, computerB, "Runeclaw Bear", 1, true);
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerB, "White Knight", 1, true);
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerB, "Runeclaw Bear", 1, true);
|
||||
// one not tapped White Knight to prevent AI from attacking
|
||||
addCard(Constants.Zone.BATTLEFIELD, computerB, "White Knight", 1, false);
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerB, "White Knight", 1, false);
|
||||
|
||||
setStopOnTurn(2);
|
||||
execute();
|
||||
|
||||
assertTurn(2);
|
||||
assertResult(computerA, CardTestAPI.GameResult.DRAW);
|
||||
assertLife(computerA, 20);
|
||||
assertLife(computerB, 20);
|
||||
assertResult(playerA, CardTestAPI.GameResult.DRAW);
|
||||
assertLife(playerA, 20);
|
||||
assertLife(playerB, 20);
|
||||
|
||||
// no one should be destroyed
|
||||
assertPermanentCount(computerB, "White Knight", 2);
|
||||
assertPermanentCount(computerB, "Runeclaw Bear", 0);
|
||||
assertPermanentCount(playerB, "White Knight", 2);
|
||||
assertPermanentCount(playerB, "Runeclaw Bear", 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAgainstAbilityInTheStackNoProtection() {
|
||||
useRedDefault();
|
||||
addCard(Constants.Zone.BATTLEFIELD, computerA, "Royal Assassin");
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerA, "Royal Assassin");
|
||||
|
||||
addCard(Constants.Zone.BATTLEFIELD, computerB, "Runeclaw Bear", 1, true);
|
||||
addCard(Constants.Zone.BATTLEFIELD, computerB, "Runeclaw Bear", 1, false);
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerB, "Runeclaw Bear", 1, true);
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerB, "Runeclaw Bear", 1, false);
|
||||
|
||||
setStopOnTurn(2);
|
||||
execute();
|
||||
|
||||
assertTurn(2);
|
||||
assertResult(computerA, CardTestAPI.GameResult.DRAW);
|
||||
assertLife(computerA, 20);
|
||||
assertLife(computerB, 20);
|
||||
assertResult(playerA, CardTestAPI.GameResult.DRAW);
|
||||
assertLife(playerA, 20);
|
||||
assertLife(playerB, 20);
|
||||
|
||||
// One should have beendestroyed by Royal Assassin
|
||||
assertPermanentCount(computerB, "Runeclaw Bear", 1);
|
||||
assertPermanentCount(playerB, "Runeclaw Bear", 1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,38 +12,38 @@ public class ProtectionFromTypeTest extends CardTestBase {
|
|||
@Test
|
||||
public void testProtectionFromArtifacts() {
|
||||
useRedDefault();
|
||||
addCard(Constants.Zone.HAND, computerA, "Trigon of Corruption");
|
||||
addCard(Constants.Zone.HAND, playerA, "Trigon of Corruption");
|
||||
|
||||
addCard(Constants.Zone.BATTLEFIELD, computerB, "Tel-Jilad Fallen");
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerB, "Tel-Jilad Fallen");
|
||||
|
||||
setStopOnTurn(2);
|
||||
execute();
|
||||
|
||||
assertTurn(2);
|
||||
assertResult(computerA, GameResult.DRAW);
|
||||
assertLife(computerA, 20);
|
||||
assertLife(computerB, 20);
|
||||
assertResult(playerA, GameResult.DRAW);
|
||||
assertLife(playerA, 20);
|
||||
assertLife(playerB, 20);
|
||||
|
||||
// no one should be destroyed
|
||||
assertPermanentCount(computerB, "Tel-Jilad Fallen", 1);
|
||||
assertPermanentCount(playerB, "Tel-Jilad Fallen", 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoProtection() {
|
||||
useRedDefault();
|
||||
addCard(Constants.Zone.HAND, computerA, "Trigon of Corruption");
|
||||
addCard(Constants.Zone.HAND, playerA, "Trigon of Corruption");
|
||||
|
||||
addCard(Constants.Zone.BATTLEFIELD, computerB, "Coral Merfolk");
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerB, "Coral Merfolk");
|
||||
|
||||
setStopOnTurn(2);
|
||||
execute();
|
||||
|
||||
assertTurn(2);
|
||||
assertResult(computerA, GameResult.DRAW);
|
||||
assertLife(computerA, 20);
|
||||
assertLife(computerB, 20);
|
||||
assertResult(playerA, GameResult.DRAW);
|
||||
assertLife(playerA, 20);
|
||||
assertLife(playerB, 20);
|
||||
|
||||
// no one should be destroyed
|
||||
assertPermanentCount(computerB, "Coral Merfolk", 0);
|
||||
assertPermanentCount(playerB, "Coral Merfolk", 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.mage.test.serverside.cards.effects;
|
||||
|
||||
import com.sun.xml.bind.v2.schemagen.xmlschema.Any;
|
||||
import mage.filter.Filter;
|
||||
import org.junit.Test;
|
||||
import org.mage.test.serverside.base.CardTestBase;
|
||||
|
@ -17,7 +16,7 @@ public class BoostContinuousEffectTest extends CardTestBase {
|
|||
load("M11/Honor of the Pure.test");
|
||||
execute();
|
||||
|
||||
checkPermanentPT(computerA, "Tine Shrike", 3, 2, Filter.ComparisonScope.Any);
|
||||
checkPermanentPT(computerA, "Runeclaw Bear", 2, 2, Filter.ComparisonScope.Any);
|
||||
checkPermanentPT(playerA, "Tine Shrike", 3, 2, Filter.ComparisonScope.Any);
|
||||
checkPermanentPT(playerA, "Runeclaw Bear", 2, 2, Filter.ComparisonScope.Any);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,11 +28,11 @@ public class BurntheImpureTest extends CardTestBase {
|
|||
// $include red.default
|
||||
useRedDefault();
|
||||
// hand:ComputerA:Burn the Impure:1
|
||||
addCard(Constants.Zone.HAND, computerA, "Burn the Impure");
|
||||
addCard(Constants.Zone.HAND, playerA, "Burn the Impure");
|
||||
// battlefield:ComputerB:Tine Shrike:1
|
||||
addCard(Constants.Zone.BATTLEFIELD, computerB, "Tine Shrike");
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerB, "Tine Shrike");
|
||||
// player:ComputerB:life:3
|
||||
setLife(computerB, 3);
|
||||
setLife(playerB, 3);
|
||||
|
||||
setStopOnTurn(2);
|
||||
execute();
|
||||
|
@ -40,13 +40,13 @@ public class BurntheImpureTest extends CardTestBase {
|
|||
// turn:1
|
||||
assertTurn(1);
|
||||
// result:won
|
||||
assertResult(computerA, CardTestAPI.GameResult.WON);
|
||||
assertResult(playerA, CardTestAPI.GameResult.WON);
|
||||
// life:ComputerA:20
|
||||
assertLife(computerA, 20);
|
||||
assertLife(playerA, 20);
|
||||
// life:ComputerB:0
|
||||
assertLife(computerB, 0);
|
||||
assertLife(playerB, 0);
|
||||
// assert Tine Shrike has been killed
|
||||
assertPermanentCount(computerB, "Tine Shrike", 0);
|
||||
assertPermanentCount(playerB, "Tine Shrike", 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -56,19 +56,19 @@ public class BurntheImpureTest extends CardTestBase {
|
|||
@Test
|
||||
public void testVersusNonInfectCreature() throws Exception {
|
||||
useRedDefault();
|
||||
addCard(Constants.Zone.HAND, computerA, "Burn the Impure");
|
||||
addCard(Constants.Zone.BATTLEFIELD, computerB, "Runeclaw Bear", 3);
|
||||
setLife(computerB, 3);
|
||||
addCard(Constants.Zone.HAND, playerA, "Burn the Impure");
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerB, "Runeclaw Bear", 3);
|
||||
setLife(playerB, 3);
|
||||
|
||||
setStopOnTurn(2);
|
||||
execute();
|
||||
|
||||
assertTurn(2);
|
||||
assertResult(computerA, CardTestAPI.GameResult.DRAW);
|
||||
assertLife(computerA, 20);
|
||||
assertLife(computerB, 3);
|
||||
assertPermanentCount(computerB, "Runeclaw Bear", 2);
|
||||
assertPowerToughness(computerB, "Runeclaw Bear", 2, 2, Filter.ComparisonScope.Any);
|
||||
assertPowerToughness(computerB, "Runeclaw Bear", 2, 2, Filter.ComparisonScope.All);
|
||||
assertResult(playerA, CardTestAPI.GameResult.DRAW);
|
||||
assertLife(playerA, 20);
|
||||
assertLife(playerB, 3);
|
||||
assertPermanentCount(playerB, "Runeclaw Bear", 2);
|
||||
assertPowerToughness(playerB, "Runeclaw Bear", 2, 2, Filter.ComparisonScope.Any);
|
||||
assertPowerToughness(playerB, "Runeclaw Bear", 2, 2, Filter.ComparisonScope.All);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -163,6 +163,7 @@ public interface Player extends MageItem, Copyable<Player> {
|
|||
|
||||
public boolean isTestMode();
|
||||
public void setTestMode(boolean value);
|
||||
public void addAction(String action);
|
||||
|
||||
public void init(Game game);
|
||||
public void init(Game game, boolean testMode);
|
||||
|
|
|
@ -1345,4 +1345,10 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
|
|||
public void setUserData(UserData userData) {
|
||||
this.userData = userData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAction(String action) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue