Search in sources :

Example 1 with DeckCardLists

use of mage.cards.decks.DeckCardLists in project mage by magefree.

the class MtgArenaDeckExporterTest method writeDeck.

@Test
public void writeDeck() throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DeckCardLists deck = new DeckCardLists();
    deck.getCards().add(new DeckCardInfo("Forest", "1", "RNA", 2));
    deck.getCards().add(new DeckCardInfo("Plains", "2", "RNA", 3));
    // must combine
    deck.getCards().add(new DeckCardInfo("Plains", "2", "RNA", 5));
    deck.getCards().add(new DeckCardInfo("Mountain", "3", "RNA", 1));
    deck.getCards().add(new DeckCardInfo("Goblin Chainwhirler", "129", "DOM", 4));
    deck.getSideboard().add(new DeckCardInfo("Island", "1", "RNA", 2));
    // must combine
    deck.getSideboard().add(new DeckCardInfo("Island", "1", "RNA", 5));
    deck.getSideboard().add(new DeckCardInfo("Mountain", "2", "RNA", 3));
    DeckExporter exporter = new MtgArenaDeckExporter();
    exporter.writeDeck(baos, deck);
    assertEquals("2 Forest (RNA) 1" + System.lineSeparator() + "8 Plains (RNA) 2" + System.lineSeparator() + "1 Mountain (RNA) 3" + System.lineSeparator() + "4 Goblin Chainwhirler (DAR) 129" + System.lineSeparator() + System.lineSeparator() + "7 Island (RNA) 1" + System.lineSeparator() + "3 Mountain (RNA) 2" + System.lineSeparator(), baos.toString());
}
Also used : DeckCardLists(mage.cards.decks.DeckCardLists) MtgArenaDeckExporter(mage.cards.decks.exporter.MtgArenaDeckExporter) DeckExporter(mage.cards.decks.exporter.DeckExporter) DeckCardInfo(mage.cards.decks.DeckCardInfo) MtgArenaDeckExporter(mage.cards.decks.exporter.MtgArenaDeckExporter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 2 with DeckCardLists

use of mage.cards.decks.DeckCardLists in project mage by magefree.

the class TxtDeckImporterTest method testImportWithBlankLineAboveSideboard.

@Test
public void testImportWithBlankLineAboveSideboard() {
    TxtDeckImporter importer = new TxtDeckImporter(false);
    CardInfo card;
    DeckCardLists deck = new DeckCardLists();
    String[] cards = { "Plains", "Forest", "Island" };
    String[] sideboard = { "Swamp", "Mountain" };
    for (String c : cards) {
        card = CardRepository.instance.findPreferredCoreExpansionCard(c, true);
        assert card != null;
        deck.getCards().add(new DeckCardInfo(card.getName(), card.getCardNumber(), card.getSetCode()));
    }
    for (String s : sideboard) {
        card = CardRepository.instance.findPreferredCoreExpansionCard(s, true);
        assert card != null;
        deck.getSideboard().add(new DeckCardInfo(card.getName(), card.getCardNumber(), card.getSetCode()));
    }
    Assert.assertEquals("Deck does not contain 3 cards, found " + deck.getCards().size(), 3, deck.getCards().size());
    Assert.assertEquals("Sideboard does not contain 2 cards, found " + deck.getSideboard().size(), 2, deck.getSideboard().size());
    DeckCardLists imported = importer.importDeck("JustLands.txt", false);
    Assert.assertEquals("Imported deck does not contain 3 cards, found " + imported.getCards().size(), 3, imported.getCards().size());
    Assert.assertEquals("Imported sideboard does not contain 2 cards, found " + imported.getSideboard().size(), 2, imported.getSideboard().size());
}
Also used : DeckCardLists(mage.cards.decks.DeckCardLists) DeckCardInfo(mage.cards.decks.DeckCardInfo) TxtDeckImporter(mage.cards.decks.importer.TxtDeckImporter) DeckCardInfo(mage.cards.decks.DeckCardInfo) CardInfo(mage.cards.repository.CardInfo) Test(org.junit.Test)

Example 3 with DeckCardLists

use of mage.cards.decks.DeckCardLists in project mage by magefree.

the class GameChooser method createTestGame.

// GEN-LAST:event_btnNewTournamentActionPerformed
private void createTestGame(String gameName, String gameType, boolean useMonteCarloAI) {
    TableView table;
    try {
        String testDeckFile = "test.dck";
        File f = new File(testDeckFile);
        if (!f.exists()) {
            // default test deck
            testDeckFile = DeckUtil.writeTextToTempFile("" + "5 Swamp" + System.lineSeparator() + "5 Forest" + System.lineSeparator() + "5 Island" + System.lineSeparator() + "5 Mountain" + System.lineSeparator() + "5 Plains");
        }
        DeckCardLists testDeck = DeckImporter.importDeckFromFile(testDeckFile, false);
        PlayerType aiType = useMonteCarloAI ? PlayerType.COMPUTER_MONTE_CARLO : PlayerType.COMPUTER_MAD;
        MatchOptions options = new MatchOptions(gameName, gameType, false, 2);
        options.getPlayerTypes().add(PlayerType.HUMAN);
        options.getPlayerTypes().add(aiType);
        options.setDeckType("Limited");
        options.setAttackOption(MultiplayerAttackOption.LEFT);
        options.setRange(RangeOfInfluence.ALL);
        options.setWinsNeeded(1);
        options.setMatchTimeLimit(MatchTimeLimit.NONE);
        options.setFreeMulligans(2);
        options.setSkillLevel(SkillLevel.CASUAL);
        options.setRollbackTurnsAllowed(true);
        options.setQuitRatio(100);
        options.setMinimumRating(0);
        String serverAddress = SessionHandler.getSession().getServerHostname().orElse("");
        options.setBannedUsers(IgnoreList.getIgnoredUsers(serverAddress));
        table = SessionHandler.createTable(roomId, options);
        SessionHandler.joinTable(roomId, table.getTableId(), "Human", PlayerType.HUMAN, 1, testDeck, "");
        SessionHandler.joinTable(roomId, table.getTableId(), "Computer", aiType, 5, testDeck, "");
        SessionHandler.startMatch(roomId, table.getTableId());
    } catch (HeadlessException ex) {
        handleError(ex);
    }
}
Also used : DeckCardLists(mage.cards.decks.DeckCardLists) PlayerType(mage.players.PlayerType) MatchOptions(mage.game.match.MatchOptions) File(java.io.File) TableView(mage.view.TableView)

Example 4 with DeckCardLists

use of mage.cards.decks.DeckCardLists in project mage by magefree.

the class LoadTest method test_TwoUsersPlayGameUntilEnd.

@Test
@Ignore
public void test_TwoUsersPlayGameUntilEnd() {
    // monitor other players
    LoadPlayer monitor = new LoadPlayer("monitor");
    // users
    LoadPlayer player1 = new LoadPlayer("1");
    LoadPlayer player2 = new LoadPlayer("2");
    // game by user 1
    GameTypeView gameType = player1.session.getGameTypes().get(0);
    MatchOptions gameOptions = createSimpleGameOptionsForBots(gameType, player1.session);
    TableView game = player1.session.createTable(player1.roomID, gameOptions);
    UUID tableId = game.getTableId();
    Assert.assertEquals(player1.userName, game.getControllerName());
    DeckCardLists deckList = DeckTestUtils.buildRandomDeckAndInitCards("GR", true);
    Optional<TableView> checkGame;
    /*
        for(DeckCardInfo info: deckList.getCards()) {
            logger.info(info.getCardName());
        }*/
    // before connect
    checkGame = monitor.getTable(tableId);
    Assert.assertTrue(checkGame.isPresent());
    Assert.assertEquals(2, checkGame.get().getSeats().size());
    Assert.assertEquals("", checkGame.get().getSeats().get(0).getPlayerName());
    Assert.assertEquals("", checkGame.get().getSeats().get(1).getPlayerName());
    // connect user 1
    Assert.assertTrue(player1.session.joinTable(player1.roomID, tableId, player1.userName, PlayerType.HUMAN, 1, deckList, ""));
    checkGame = monitor.getTable(tableId);
    Assert.assertTrue(checkGame.isPresent());
    Assert.assertEquals(2, checkGame.get().getSeats().size());
    Assert.assertEquals(player1.userName, checkGame.get().getSeats().get(0).getPlayerName());
    Assert.assertEquals("", checkGame.get().getSeats().get(1).getPlayerName());
    // connect user 2
    Assert.assertTrue(player2.session.joinTable(player2.roomID, tableId, player2.userName, PlayerType.HUMAN, 1, deckList, ""));
    checkGame = monitor.getTable(tableId);
    Assert.assertTrue(checkGame.isPresent());
    Assert.assertEquals(2, checkGame.get().getSeats().size());
    Assert.assertEquals(player1.userName, checkGame.get().getSeats().get(0).getPlayerName());
    Assert.assertEquals(player2.userName, checkGame.get().getSeats().get(1).getPlayerName());
    // match start
    Assert.assertTrue(player1.session.startMatch(player1.roomID, tableId));
    // playing until game over
    while (!player1.client.isGameOver() && !player2.client.isGameOver()) {
        checkGame = monitor.getTable(tableId);
        logger.warn(checkGame.get().getTableState());
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            logger.error(e.getMessage(), e);
        }
    }
}
Also used : DeckCardLists(mage.cards.decks.DeckCardLists) MatchOptions(mage.game.match.MatchOptions) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with DeckCardLists

use of mage.cards.decks.DeckCardLists 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)

Aggregations

DeckCardLists (mage.cards.decks.DeckCardLists)23 Test (org.junit.Test)14 DeckCardInfo (mage.cards.decks.DeckCardInfo)5 File (java.io.File)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Deck (mage.cards.decks.Deck)3 MatchOptions (mage.game.match.MatchOptions)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 CardInfo (mage.cards.repository.CardInfo)2 Ignore (org.junit.Ignore)2 Document (org.w3c.dom.Document)2 Node (org.w3c.dom.Node)2 java.awt (java.awt)1 BufferedImage (java.awt.image.BufferedImage)1 FileReader (java.io.FileReader)1 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)1 SecureRandom (java.security.SecureRandom)1 List (java.util.List)1 Scanner (java.util.Scanner)1