Test framework: added realtime checks for mana pool amount

This commit is contained in:
Oleg Agafonov 2018-06-11 04:20:21 +04:00
parent 4370dbe14b
commit 21276a1d7a
2 changed files with 78 additions and 20 deletions

View file

@ -4,6 +4,7 @@ import java.io.Serializable;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import mage.MageObject;
import mage.MageObjectReference;
import mage.ObjectColor;
@ -126,7 +127,7 @@ public class TestPlayer implements Player {
/**
* @param maxCallsWithoutAction max number of priority passes a player may
* have for this test (default = 100)
* have for this test (default = 100)
*/
public void setMaxCallsWithoutAction(int maxCallsWithoutAction) {
this.maxCallsWithoutAction = maxCallsWithoutAction;
@ -556,6 +557,13 @@ public class TestPlayer implements Player {
actions.remove(action);
checkProccessed = true;
}
// check mana pool: colors, amount
if (params[0].equals(CHECK_COMMAND_MANA_POOL) && params.length == 3) {
assertManaPool(action, game, computerPlayer, params[1], Integer.parseInt(params[2]));
actions.remove(action);
checkProccessed = true;
}
}
if (!checkProccessed) {
@ -678,6 +686,51 @@ public class TestPlayer implements Player {
}
}
private void assertManaPoolInner(PlayerAction action, Player player, ManaType manaType, Integer amount) {
Integer current = player.getManaPool().get(manaType);
Assert.assertEquals(action.getActionName() + " - mana pool must contain [" + amount.toString() + " " + manaType.toString() + "], but found [" + current.toString() + "]", amount, current);
}
private void assertManaPool(PlayerAction action, Game game, Player player, String colors, Integer amount) {
Assert.assertNotEquals(action.getActionName() + " - must setup color", "", colors);
// Can't use ObjectColor -- it's doesn't contain colorless -- need to use custom parse
for (int i = 0; i < colors.length(); i++) {
switch (colors.charAt(i)) {
case 'W':
assertManaPoolInner(action, player, ManaType.WHITE, amount);
break;
case 'U':
assertManaPoolInner(action, player, ManaType.BLUE, amount);
break;
case 'B':
assertManaPoolInner(action, player, ManaType.BLACK, amount);
break;
case 'R':
assertManaPoolInner(action, player, ManaType.RED, amount);
break;
case 'G':
assertManaPoolInner(action, player, ManaType.GREEN, amount);
break;
case 'C':
assertManaPoolInner(action, player, ManaType.COLORLESS, amount);
break;
default:
Assert.fail(action.getActionName() + " - unknown color char [" + colors.charAt(i) + "]");
break;
}
}
}
/*
* Iterates through each player on the current turn and asserts if they can attack or block legally this turn
*/
@ -721,7 +774,7 @@ public class TestPlayer implements Player {
// Loop through players and validate can attack/block this turn
UUID defenderId = null;
//List<PlayerAction>
for (Iterator<org.mage.test.player.PlayerAction> it = actions.iterator(); it.hasNext();) {
for (Iterator<org.mage.test.player.PlayerAction> it = actions.iterator(); it.hasNext(); ) {
PlayerAction action = it.next();
if (action.getTurnNum() == game.getTurnNum() && action.getAction().startsWith("attack:")) {
String command = action.getAction();
@ -2389,7 +2442,7 @@ public class TestPlayer implements Player {
@Override
public boolean choose(Outcome outcome, Target target,
UUID sourceId, Game game
UUID sourceId, Game game
) {
// needed to call here the TestPlayer because it's overwitten
return choose(outcome, target, sourceId, game, null);
@ -2397,7 +2450,7 @@ public class TestPlayer implements Player {
@Override
public boolean choose(Outcome outcome, Cards cards,
TargetCard target, Game game
TargetCard target, Game game
) {
if (!choices.isEmpty()) {
for (String choose2 : choices) {
@ -2429,7 +2482,7 @@ public class TestPlayer implements Player {
@Override
public boolean chooseTargetAmount(Outcome outcome, TargetAmount target,
Ability source, Game game
Ability source, Game game
) {
return computerPlayer.chooseTargetAmount(outcome, target, source, game);
}
@ -2442,15 +2495,15 @@ public class TestPlayer implements Player {
@Override
public boolean choosePile(Outcome outcome, String message,
List<? extends Card> pile1, List<? extends Card> pile2,
Game game
List<? extends Card> pile1, List<? extends Card> pile2,
Game game
) {
return computerPlayer.choosePile(outcome, message, pile1, pile2, game);
}
@Override
public boolean playMana(Ability ability, ManaCost unpaid,
String promptText, Game game
String promptText, Game game
) {
groupsForTargetHandling = null;
return computerPlayer.playMana(ability, unpaid, promptText, game);
@ -2464,15 +2517,15 @@ public class TestPlayer implements Player {
@Override
public UUID chooseBlockerOrder(List<Permanent> blockers, CombatGroup combatGroup,
List<UUID> blockerOrder, Game game
List<UUID> blockerOrder, Game game
) {
return computerPlayer.chooseBlockerOrder(blockers, combatGroup, blockerOrder, game);
}
@Override
public void assignDamage(int damage, List<UUID> targets,
String singleTargetName, UUID sourceId,
Game game
String singleTargetName, UUID sourceId,
Game game
) {
computerPlayer.assignDamage(damage, targets, singleTargetName, sourceId, game);
}
@ -2491,14 +2544,14 @@ public class TestPlayer implements Player {
@Override
public void pickCard(List<Card> cards, Deck deck,
Draft draft
Draft draft
) {
computerPlayer.pickCard(cards, deck, draft);
}
@Override
public boolean scry(int value, Ability source,
Game game
Game game
) {
// Don't scry at the start of the game.
if (game.getTurnNum() == 1 && game.getStep() == null) {
@ -2509,37 +2562,37 @@ public class TestPlayer implements Player {
@Override
public boolean moveCards(Card card, Zone toZone,
Ability source, Game game
Ability source, Game game
) {
return computerPlayer.moveCards(card, toZone, source, game);
}
@Override
public boolean moveCards(Card card, Zone toZone,
Ability source, Game game,
boolean tapped, boolean faceDown, boolean byOwner, List<UUID> appliedEffects
Ability source, Game game,
boolean tapped, boolean faceDown, boolean byOwner, List<UUID> appliedEffects
) {
return computerPlayer.moveCards(card, toZone, source, game, tapped, faceDown, byOwner, appliedEffects);
}
@Override
public boolean moveCards(Cards cards, Zone toZone,
Ability source, Game game
Ability source, Game game
) {
return computerPlayer.moveCards(cards, toZone, source, game);
}
@Override
public boolean moveCards(Set<Card> cards, Zone toZone,
Ability source, Game game
Ability source, Game game
) {
return computerPlayer.moveCards(cards, toZone, source, game);
}
@Override
public boolean moveCards(Set<Card> cards, Zone toZone,
Ability source, Game game,
boolean tapped, boolean faceDown, boolean byOwner, List<UUID> appliedEffects
Ability source, Game game,
boolean tapped, boolean faceDown, boolean byOwner, List<UUID> appliedEffects
) {
return computerPlayer.moveCards(cards, toZone, source, game, tapped, faceDown, byOwner, appliedEffects);
}

View file

@ -54,6 +54,7 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
public static final String CHECK_COMMAND_HAND_COUNT = "HAND_COUNT";
public static final String CHECK_COMMAND_COLOR = "COLOR";
public static final String CHECK_COMMAND_SUBTYPE = "SUBTYPE";
public static final String CHECK_COMMAND_MANA_POOL = "MANA_POOL";
protected GameOptions gameOptions;
@ -259,6 +260,10 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
check(checkName, turnNum, step, player, CHECK_COMMAND_SUBTYPE, permanentName, subType.toString(), mustHave.toString());
}
public void checkManaPool(String checkName, int turnNum, PhaseStep step, TestPlayer player, String colors, Integer amount) {
check(checkName, turnNum, step, player, CHECK_COMMAND_MANA_POOL, colors, amount.toString());
}
/**
* Removes all cards from player's library from the game. Usually this
* should be used once before initialization to form the library in certain