Search in sources :

Example 6 with MatchOptions

use of mage.game.match.MatchOptions in project mage by magefree.

the class LoadTest method playTwoAIGame.

public void playTwoAIGame(String gameName, String deckColors, String deckAllowedSets, LoadTestGameResult gameResult) {
    Assert.assertFalse("need deck colors", deckColors.isEmpty());
    Assert.assertFalse("need allowed sets", deckAllowedSets.isEmpty());
    // monitor and game source
    LoadPlayer monitor = new LoadPlayer("monitor", true);
    // game by monitor
    GameTypeView gameType = monitor.session.getGameTypes().get(0);
    MatchOptions gameOptions = createSimpleGameOptionsForAI(gameType, monitor.session, gameName);
    TableView game = monitor.session.createTable(monitor.roomID, gameOptions);
    UUID tableId = game.getTableId();
    DeckCardLists deckList = DeckTestUtils.buildRandomDeckAndInitCards(deckColors, false, deckAllowedSets);
    Optional<TableView> checkGame;
    // join AI
    Assert.assertTrue(monitor.session.joinTable(monitor.roomID, tableId, "ai_1", PlayerType.COMPUTER_MAD, 5, deckList, ""));
    Assert.assertTrue(monitor.session.joinTable(monitor.roomID, tableId, "ai_2", PlayerType.COMPUTER_MAD, 5, deckList, ""));
    // match start
    Assert.assertTrue(monitor.session.startMatch(monitor.roomID, tableId));
    // playing until game over
    gameResult.start();
    boolean startToWatching = false;
    while (true) {
        GameView gameView = monitor.client.getLastGameView();
        checkGame = monitor.getTable(tableId);
        TableState state = checkGame.get().getTableState();
        logger.warn(checkGame.get().getTableName() + (gameView != null ? ", turn " + gameView.getTurn() + ", " + gameView.getStep().toString() : "") + (gameView != null ? ", active " + gameView.getActivePlayerName() : "") + ", " + state);
        if (state == TableState.FINISHED) {
            gameResult.finish(gameView);
            break;
        }
        if (!startToWatching && state == TableState.DUELING) {
            Assert.assertTrue(monitor.session.watchGame(checkGame.get().getGames().iterator().next()));
            startToWatching = true;
        }
        if (gameView != null) {
            for (PlayerView p : gameView.getPlayers()) {
                logger.info(p.getName() + " - Life=" + p.getLife() + "; Lib=" + p.getLibraryCount());
            }
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            logger.error(e.getMessage(), e);
        }
    }
}
Also used : DeckCardLists(mage.cards.decks.DeckCardLists) MatchOptions(mage.game.match.MatchOptions)

Example 7 with MatchOptions

use of mage.game.match.MatchOptions 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 8 with MatchOptions

use of mage.game.match.MatchOptions in project mage by magefree.

the class FreeformUnlimitedCommanderMatchTest method test_getOptions_returnsOriginalOptions.

@Test
public void test_getOptions_returnsOriginalOptions() {
    // Arrange
    MatchOptions options = new MatchOptions("test name", "test match name", false, 2);
    Match match = new FreeformUnlimitedCommanderMatch(options);
    // Act
    MatchOptions actual = match.getOptions();
    // Assert
    Assert.assertEquals(options, actual);
}
Also used : MatchOptions(mage.game.match.MatchOptions) FreeformUnlimitedCommanderMatch(mage.game.FreeformUnlimitedCommanderMatch) FreeformUnlimitedCommanderMatch(mage.game.FreeformUnlimitedCommanderMatch) Match(mage.game.match.Match) Test(org.junit.Test)

Example 9 with MatchOptions

use of mage.game.match.MatchOptions in project mage by magefree.

the class FreeformUnlimitedCommanderMatchTest method test_getName_returnsTestName.

@Test
public void test_getName_returnsTestName() {
    // Arrange
    MatchOptions options = new MatchOptions("test name", "test match name", false, 2);
    Match match = new FreeformUnlimitedCommanderMatch(options);
    // Act
    String actual = match.getName();
    // Assert
    Assert.assertEquals("test name", actual);
}
Also used : MatchOptions(mage.game.match.MatchOptions) FreeformUnlimitedCommanderMatch(mage.game.FreeformUnlimitedCommanderMatch) FreeformUnlimitedCommanderMatch(mage.game.FreeformUnlimitedCommanderMatch) Match(mage.game.match.Match) Test(org.junit.Test)

Example 10 with MatchOptions

use of mage.game.match.MatchOptions in project mage by magefree.

the class FreeformUnlimitedCommanderMatchTest method test_construct_returnsFreeformPlusCommanderMatch.

@Test
public void test_construct_returnsFreeformPlusCommanderMatch() {
    // Arrange
    MatchOptions options = new MatchOptions("test name", "test match name", false, 2);
    // Act
    Match match = new FreeformUnlimitedCommanderMatch(options);
    // Assert
    Assert.assertEquals(FreeformUnlimitedCommanderMatch.class, match.getClass());
}
Also used : MatchOptions(mage.game.match.MatchOptions) FreeformUnlimitedCommanderMatch(mage.game.FreeformUnlimitedCommanderMatch) FreeformUnlimitedCommanderMatch(mage.game.FreeformUnlimitedCommanderMatch) Match(mage.game.match.Match) Test(org.junit.Test)

Aggregations

MatchOptions (mage.game.match.MatchOptions)13 Test (org.junit.Test)4 DeckCardLists (mage.cards.decks.DeckCardLists)3 FreeformUnlimitedCommanderMatch (mage.game.FreeformUnlimitedCommanderMatch)3 Match (mage.game.match.Match)3 UUID (java.util.UUID)2 TablePlayerPanel (mage.client.table.TablePlayerPanel)2 PlayerType (mage.players.PlayerType)2 File (java.io.File)1 IOException (java.io.IOException)1 Date (java.util.Date)1 Entry (java.util.Map.Entry)1 Optional (java.util.Optional)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 MageException (mage.MageException)1 Deck (mage.cards.decks.Deck)1 TableState (mage.constants.TableState)1 TournamentPlayerState (mage.constants.TournamentPlayerState)1 GameException (mage.game.GameException)1