Search in sources :

Example 1 with PlayerAction

use of org.mage.test.player.PlayerAction in project mage by magefree.

the class CardTestPlayerAPIImpl method addPlayerAction.

private void addPlayerAction(TestPlayer player, int turnNum, PhaseStep step, String action) {
    PlayerAction playerAction = new PlayerAction("", turnNum, step, action);
    addPlayerAction(player, playerAction);
}
Also used : PlayerAction(org.mage.test.player.PlayerAction)

Example 2 with PlayerAction

use of org.mage.test.player.PlayerAction in project mage by magefree.

the class CardTestPlayerAPIImpl method runCode.

/**
 * Execute custom code under player's priority. You can stop debugger on it.
 * <p>
 * Example 1: check some conditions in the middle of the test
 * Example 2: make game modifications (if you don't want to use custom abilities)
 * Example 3: stop debugger in the middle of the game
 *
 * @param info
 * @param turnNum
 * @param step
 * @param player
 * @param codePayload code to execute
 */
public void runCode(String info, int turnNum, PhaseStep step, TestPlayer player, CardTestCodePayload codePayload) {
    PlayerAction playerAction = new PlayerAction(info, turnNum, step, RUN_PREFIX + RUN_COMMAND_CODE, codePayload);
    addPlayerAction(player, playerAction);
}
Also used : PlayerAction(org.mage.test.player.PlayerAction)

Example 3 with PlayerAction

use of org.mage.test.player.PlayerAction 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();
}
Also used : Player(mage.players.Player) TestPlayer(org.mage.test.player.TestPlayer) GameSessionPlayer(mage.server.game.GameSessionPlayer) TestPlayer(org.mage.test.player.TestPlayer) PlayerAction(org.mage.test.player.PlayerAction)

Aggregations

PlayerAction (org.mage.test.player.PlayerAction)3 Player (mage.players.Player)1 GameSessionPlayer (mage.server.game.GameSessionPlayer)1 TestPlayer (org.mage.test.player.TestPlayer)1