use of org.mage.test.player.TestPlayer in project mage by magefree.
the class CardTestPlayerAPIImpl method reset.
/**
* @throws GameException
* @throws FileNotFoundException
*/
@Before
public void reset() throws GameException, FileNotFoundException {
if (currentGame != null) {
logger.debug("Resetting previous game and creating new one!");
currentGame = null;
}
// prepare fake match (needs for testing some client-server code)
// always 4 seats
MatchOptions matchOptions = new MatchOptions("test match", "test game type", true, 4);
currentMatch = new FreeForAllMatch(matchOptions);
currentGame = createNewGameAndPlayers();
activePlayer = playerA;
stopOnTurn = 2;
stopAtStep = PhaseStep.UNTAP;
for (Player player : currentGame.getPlayers().values()) {
TestPlayer testPlayer = (TestPlayer) player;
getCommands(testPlayer).clear();
getLibraryCards(testPlayer).clear();
getHandCards(testPlayer).clear();
getBattlefieldCards(testPlayer).clear();
getGraveCards(testPlayer).clear();
// Reset the turn counter for tests
((TestPlayer) player).setInitialTurns(0);
}
gameOptions = new GameOptions();
rollbackBlock = 0;
rollbackBlockActive = false;
}
use of org.mage.test.player.TestPlayer in project mage by magefree.
the class CardTestPlayerAPIImpl method execute.
public void execute() throws IllegalStateException {
if (currentGame == null || activePlayer == null) {
throw new IllegalStateException("Game is not initialized. Use load method to load a test case and initialize a game.");
}
// check stop command
int maxTurn = 1;
int maxPhase = 0;
for (Player player : currentGame.getPlayers().values()) {
if (player instanceof TestPlayer) {
TestPlayer testPlayer = (TestPlayer) player;
for (PlayerAction action : testPlayer.getActions()) {
assertTrue("Wrong turn in action " + action.getTurnNum(), action.getTurnNum() >= 1);
int curTurn = action.getTurnNum();
int curPhase = action.getStep().getIndex();
if ((curTurn > maxTurn) || (curTurn == maxTurn && curPhase > maxPhase)) {
maxTurn = curTurn;
maxPhase = curPhase;
}
}
}
}
Assert.assertFalse("Wrong stop command on " + this.stopOnTurn + " / " + this.stopAtStep + " (" + this.stopAtStep.getIndex() + ")" + " (found actions after stop on " + maxTurn + " / " + maxPhase + ")", (maxTurn > this.stopOnTurn) || (maxTurn == this.stopOnTurn && maxPhase > this.stopAtStep.getIndex()));
if (!currentGame.isPaused()) {
// workaround to fill range info (cause real range fills after game start, but some cheated cards needs range on ETB)
for (Player player : currentGame.getPlayers().values()) {
player.updateRange(currentGame);
}
// add cards to game
for (Player player : currentGame.getPlayers().values()) {
TestPlayer testPlayer = (TestPlayer) player;
currentGame.cheat(testPlayer.getId(), getCommands(testPlayer));
currentGame.cheat(testPlayer.getId(), getLibraryCards(testPlayer), getHandCards(testPlayer), getBattlefieldCards(testPlayer), getGraveCards(testPlayer), getCommandCards(testPlayer));
}
}
long t1 = System.nanoTime();
gameOptions.testMode = true;
gameOptions.stopOnTurn = stopOnTurn;
gameOptions.stopAtStep = stopAtStep;
currentGame.setGameOptions(gameOptions);
if (currentGame.isPaused()) {
// needed if execute() is performed multiple times
currentGame.resume();
}
currentGame.start(activePlayer.getId());
// used for rollback handling
currentGame.setGameStopped(true);
long t2 = System.nanoTime();
logger.debug("Winner: " + currentGame.getWinner());
if (SHOW_EXECUTE_TIME_PER_TEST) {
logger.info(Thread.currentThread().getStackTrace()[2].getMethodName() + " has been executed. Execution time: " + (t2 - t1) / 1000000 + " ms");
}
// TODO: 01.12.2018, JayDi85 - uncomment and fix MANY broken tests with wrong commands
// assertAllCommandsUsed();
}
use of org.mage.test.player.TestPlayer in project mage by magefree.
the class CardTestPlayerBaseAI method createPlayer.
@Override
protected TestPlayer createPlayer(String name, RangeOfInfluence rangeOfInfluence) {
if (name.equals("PlayerA")) {
TestPlayer testPlayer = new TestPlayer(new TestComputerPlayer7("PlayerA", RangeOfInfluence.ONE, skill));
testPlayer.setAIPlayer(true);
// enable AI logic simulation for all turns by default
testPlayer.setAIRealGameSimulation(true);
return testPlayer;
}
return super.createPlayer(name, rangeOfInfluence);
}
use of org.mage.test.player.TestPlayer in project mage by magefree.
the class GoadTest method assertGoaded.
private void assertGoaded(String attacker, TestPlayer... players) {
Assert.assertTrue("At least one player should be provided", players.length > 0);
Permanent permanent = getPermanent(attacker);
Assert.assertEquals("Creature should be goaded by " + Arrays.stream(players).map(Player::getName).reduce((a, b) -> a + ", " + b).orElse(""), permanent.getGoadingPlayers(), Arrays.stream(players).map(TestPlayer::getId).collect(Collectors.toSet()));
}
Aggregations