mirror of
https://github.com/magefree/mage.git
synced 2025-12-23 12:02:01 -08:00
tests, refactor: removed outdated code
This commit is contained in:
parent
1f36a32a6e
commit
99cfca6bfb
1 changed files with 1 additions and 162 deletions
|
|
@ -18,14 +18,12 @@ import mage.cards.CardImpl;
|
|||
import mage.cards.CardSetInfo;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
import mage.cards.repository.CardInfo;
|
||||
import mage.cards.repository.CardRepository;
|
||||
import mage.constants.*;
|
||||
import mage.filter.StaticFilters;
|
||||
import mage.game.Game;
|
||||
import mage.game.PutToBattlefieldInfo;
|
||||
import mage.game.match.Match;
|
||||
import mage.game.match.MatchType;
|
||||
import mage.game.permanent.PermanentCard;
|
||||
import mage.game.tournament.TournamentType;
|
||||
import mage.players.Player;
|
||||
import mage.server.game.GameFactory;
|
||||
|
|
@ -41,7 +39,6 @@ import mage.target.common.TargetAnyTarget;
|
|||
import mage.target.common.TargetCardInExile;
|
||||
import mage.target.common.TargetCardInGraveyard;
|
||||
import mage.target.common.TargetCardInLibrary;
|
||||
import mage.util.CardUtil;
|
||||
import mage.util.Copier;
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.Logger;
|
||||
|
|
@ -51,11 +48,8 @@ import org.mage.test.player.TestComputerPlayer;
|
|||
import org.mage.test.player.TestPlayer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Base class for all tests.
|
||||
|
|
@ -70,8 +64,6 @@ public abstract class MageTestPlayerBase {
|
|||
|
||||
private static final String pluginFolder = "plugins";
|
||||
|
||||
protected Pattern pattern = Pattern.compile("([a-zA-Z]*):([\\w]*):([a-zA-Z ,\\-.!'\\d]*):([\\d]*)(:\\{tapped\\})?");
|
||||
|
||||
protected Map<TestPlayer, List<Card>> handCards = new HashMap<>();
|
||||
protected Map<TestPlayer, List<PutToBattlefieldInfo>> battlefieldCards = new HashMap<>(); // cards + additional status like tapped
|
||||
protected Map<TestPlayer, List<Card>> graveyardCards = new HashMap<>();
|
||||
|
|
@ -105,26 +97,6 @@ public abstract class MageTestPlayerBase {
|
|||
|
||||
protected PhaseStep stopAtStep = PhaseStep.UNTAP;
|
||||
|
||||
protected enum ParserState {
|
||||
|
||||
INIT,
|
||||
OPTIONS,
|
||||
EXPECTED
|
||||
}
|
||||
|
||||
protected ParserState parserState; // TODO: remove outdated and unsued code
|
||||
|
||||
/**
|
||||
* Expected results of the test. Read from test case in {@link String} based
|
||||
* format:
|
||||
* <p/>
|
||||
* Example: turn:1 result:won:ComputerA life:ComputerA:20 life:ComputerB:0
|
||||
* battlefield:ComputerB:Tine Shrike:0 graveyard:ComputerB:Tine Shrike:1
|
||||
*/
|
||||
protected List<String> expectedResults = new ArrayList<>();
|
||||
|
||||
protected static final String TESTS_PATH = "tests" + File.separator;
|
||||
|
||||
@BeforeClass
|
||||
public static void init() {
|
||||
Logger.getRootLogger().setLevel(Level.DEBUG);
|
||||
|
|
@ -194,117 +166,6 @@ public abstract class MageTestPlayerBase {
|
|||
}
|
||||
}
|
||||
|
||||
protected void parseScenario(String filename) throws FileNotFoundException {
|
||||
parserState = ParserState.INIT;
|
||||
File f = new File(filename);
|
||||
try (Scanner scanner = new Scanner(f)) {
|
||||
while (scanner.hasNextLine()) {
|
||||
String line = scanner.nextLine().trim();
|
||||
if (line == null || line.isEmpty() || line.startsWith("#")) {
|
||||
continue;
|
||||
}
|
||||
if (line.startsWith("$include")) {
|
||||
includeFrom(line);
|
||||
continue;
|
||||
}
|
||||
if (line.startsWith("$expected")) {
|
||||
parserState = ParserState.EXPECTED;
|
||||
continue;
|
||||
}
|
||||
parseLine(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void parseLine(String line) {
|
||||
// TODO: delete unused code
|
||||
if (parserState == ParserState.EXPECTED) {
|
||||
expectedResults.add(line); // just remember for future use
|
||||
return;
|
||||
}
|
||||
|
||||
Matcher m = pattern.matcher(line);
|
||||
if (m.matches()) {
|
||||
|
||||
String zone = m.group(1);
|
||||
String nickname = m.group(2);
|
||||
|
||||
if (nickname.startsWith("Computer")) {
|
||||
List<Card> cards = null;
|
||||
//List<PermanentCard> perms = null;
|
||||
Zone gameZone;
|
||||
if ("hand".equalsIgnoreCase(zone)) {
|
||||
gameZone = Zone.HAND;
|
||||
cards = getHandCards(getPlayer(nickname));
|
||||
} else if ("battlefield".equalsIgnoreCase(zone)) {
|
||||
gameZone = Zone.BATTLEFIELD;
|
||||
//perms = getBattlefieldCards(getPlayer(nickname));
|
||||
} else if ("graveyard".equalsIgnoreCase(zone)) {
|
||||
gameZone = Zone.GRAVEYARD;
|
||||
cards = getGraveCards(getPlayer(nickname));
|
||||
} else if ("library".equalsIgnoreCase(zone)) {
|
||||
gameZone = Zone.LIBRARY;
|
||||
cards = getLibraryCards(getPlayer(nickname));
|
||||
} else if ("command".equalsIgnoreCase(zone)) {
|
||||
gameZone = Zone.COMMAND;
|
||||
cards = getCommandCards(getPlayer(nickname));
|
||||
} else if ("player".equalsIgnoreCase(zone)) {
|
||||
String command = m.group(3);
|
||||
if ("life".equals(command)) {
|
||||
getCommands(getPlayer(nickname)).put(Zone.OUTSIDE, "life:" + m.group(4));
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
return; // go parse next line
|
||||
}
|
||||
|
||||
String cardName = m.group(3);
|
||||
Integer amount = Integer.parseInt(m.group(4));
|
||||
boolean tapped = m.group(5) != null && m.group(5).equals(":{tapped}");
|
||||
|
||||
if (cardName.equals("clear")) {
|
||||
getCommands(getPlayer(nickname)).put(gameZone, "clear");
|
||||
} else {
|
||||
for (int i = 0; i < amount; i++) {
|
||||
CardInfo cardInfo = CardRepository.instance.findCard(cardName);
|
||||
Card newCard = cardInfo != null ? cardInfo.getCard() : null;
|
||||
if (newCard != null) {
|
||||
if (gameZone == Zone.BATTLEFIELD) {
|
||||
//Card permCard = CardUtil.getDefaultCardSideForBattlefield(currentGame, newCard);
|
||||
//PermanentCard p = new PermanentCard(permCard, null, currentGame);
|
||||
//p.setTapped(tapped);
|
||||
//perms.add(p);
|
||||
} else {
|
||||
cards.add(newCard);
|
||||
}
|
||||
} else {
|
||||
logger.fatal("Couldn't find a card: " + cardName);
|
||||
logger.fatal("line: " + line);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
logger.warn("Unknown player: " + nickname);
|
||||
}
|
||||
} else {
|
||||
logger.warn("Init string wasn't parsed: " + line);
|
||||
}
|
||||
}
|
||||
|
||||
private TestPlayer getPlayer(String name) {
|
||||
switch (name) {
|
||||
case "ComputerA":
|
||||
return playerA;
|
||||
case "ComputerB":
|
||||
return playerB;
|
||||
case "ComputerC":
|
||||
return playerC;
|
||||
case "ComputerD":
|
||||
return playerD;
|
||||
}
|
||||
throw new IllegalArgumentException("Couldn't find player for name=" + name);
|
||||
}
|
||||
|
||||
protected List<Card> getHandCards(TestPlayer player) {
|
||||
if (handCards.containsKey(player)) {
|
||||
return handCards.get(player);
|
||||
|
|
@ -368,26 +229,6 @@ public abstract class MageTestPlayerBase {
|
|||
return command;
|
||||
}
|
||||
|
||||
private void includeFrom(String line) throws FileNotFoundException {
|
||||
String[] params = line.split(" ");
|
||||
if (params.length == 2) {
|
||||
String paramName = params[1];
|
||||
if (!paramName.contains("..")) {
|
||||
String includePath = TESTS_PATH + paramName;
|
||||
File f = new File(includePath);
|
||||
if (f.exists()) {
|
||||
parseScenario(includePath);
|
||||
} else {
|
||||
logger.warn("Ignored (file doesn't exist): " + line);
|
||||
}
|
||||
} else {
|
||||
logger.warn("Ignored (wrong charactres): " + line);
|
||||
}
|
||||
} else {
|
||||
logger.warn("Ignored (wrong size): " + line);
|
||||
}
|
||||
}
|
||||
|
||||
protected TestPlayer createPlayer(String name, RangeOfInfluence rangeOfInfluence) {
|
||||
return new TestPlayer(new TestComputerPlayer(name, rangeOfInfluence));
|
||||
}
|
||||
|
|
@ -616,9 +457,7 @@ class CustomTestCard extends CardImpl {
|
|||
|
||||
Set<SubType> subTypeSet = subTypesList.get(setInfo.getName());
|
||||
if (subTypeSet != null) {
|
||||
for (SubType subType : subTypeSet) {
|
||||
this.subtype.add(subType);
|
||||
}
|
||||
this.subtype.addAll(subTypeSet);
|
||||
}
|
||||
if (cardType == CardType.CREATURE) {
|
||||
this.power = new MageInt(1);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue