Search in sources :

Example 6 with TestPlayer

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;
}
Also used : Player(mage.players.Player) TestPlayer(org.mage.test.player.TestPlayer) GameSessionPlayer(mage.server.game.GameSessionPlayer) TestPlayer(org.mage.test.player.TestPlayer) MatchOptions(mage.game.match.MatchOptions) Before(org.junit.Before)

Example 7 with TestPlayer

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();
}
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)

Example 8 with TestPlayer

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);
}
Also used : TestPlayer(org.mage.test.player.TestPlayer) TestComputerPlayer7(org.mage.test.player.TestComputerPlayer7)

Example 9 with TestPlayer

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()));
}
Also used : TestPlayer(org.mage.test.player.TestPlayer) Arrays(java.util.Arrays) Zone(mage.constants.Zone) RangeOfInfluence(mage.constants.RangeOfInfluence) MultiplayerAttackOption(mage.constants.MultiplayerAttackOption) Test(org.junit.Test) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Player(mage.players.Player) FileNotFoundException(java.io.FileNotFoundException) FreeForAll(mage.game.FreeForAll) CardTestMultiPlayerBase(org.mage.test.serverside.base.CardTestMultiPlayerBase) Game(mage.game.Game) MulliganType(mage.game.mulligan.MulliganType) Permanent(mage.game.permanent.Permanent) PhaseStep(mage.constants.PhaseStep) Assert(org.junit.Assert) GameException(mage.game.GameException) TestPlayer(org.mage.test.player.TestPlayer) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TestPlayer(org.mage.test.player.TestPlayer)

Aggregations

TestPlayer (org.mage.test.player.TestPlayer)9 Player (mage.players.Player)5 GameSessionPlayer (mage.server.game.GameSessionPlayer)3 TestComputerPlayer7 (org.mage.test.player.TestComputerPlayer7)3 FileNotFoundException (java.io.FileNotFoundException)2 Arrays (java.util.Arrays)2 UUID (java.util.UUID)2 Collectors (java.util.stream.Collectors)2 MultiplayerAttackOption (mage.constants.MultiplayerAttackOption)2 PhaseStep (mage.constants.PhaseStep)2 RangeOfInfluence (mage.constants.RangeOfInfluence)2 Zone (mage.constants.Zone)2 FreeForAll (mage.game.FreeForAll)2 Game (mage.game.Game)2 GameException (mage.game.GameException)2 MulliganType (mage.game.mulligan.MulliganType)2 Permanent (mage.game.permanent.Permanent)2 Assert (org.junit.Assert)2 Test (org.junit.Test)2 CardTestMultiPlayerBase (org.mage.test.serverside.base.CardTestMultiPlayerBase)2