Search in sources :

Example 11 with Deck

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

the class CardTestPlayerAPIImpl method createPlayer.

protected TestPlayer createPlayer(Game game, TestPlayer player, String name, String deckName) throws GameException {
    player = createNewPlayer(name, game.getRangeOfInfluence());
    player.setTestMode(true);
    logger.debug("Loading deck...");
    DeckCardLists list;
    if (loadedDecks.containsKey(deckName)) {
        list = loadedDecks.get(deckName);
    } else {
        list = DeckImporter.importDeckFromFile(deckName, true);
        loadedDecks.put(deckName, list);
    }
    Deck deck = Deck.load(list, false, false, loadedCardInfo);
    logger.debug("Done!");
    if (deck.getCards().size() < 40) {
        throw new IllegalArgumentException("Couldn't load deck, deck size=" + deck.getCards().size());
    }
    game.loadCards(deck.getCards(), player.getId());
    game.loadCards(deck.getSideboard(), player.getId());
    game.addPlayer(player, deck);
    // fake match
    currentMatch.addPlayer(player, deck);
    return player;
}
Also used : DeckCardLists(mage.cards.decks.DeckCardLists) Deck(mage.cards.decks.Deck)

Example 12 with Deck

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

the class DeckTestUtils method buildRandomDeckAndInitCards.

public static DeckCardLists buildRandomDeckAndInitCards(String colors, boolean onlyBasicLands, String allowedSets) {
    Deck deck = buildRandomDeck(colors, onlyBasicLands, allowedSets);
    DeckCardLists deckList = new DeckCardLists();
    for (Card card : deck.getCards()) {
        CardInfo cardInfo = CardRepository.instance.findCard(card.getExpansionSetCode(), card.getCardNumber());
        if (cardInfo != null) {
            deckList.getCards().add(new DeckCardInfo(cardInfo.getName(), cardInfo.getCardNumber(), cardInfo.getSetCode()));
        }
    }
    return deckList;
}
Also used : DeckCardLists(mage.cards.decks.DeckCardLists) DeckCardInfo(mage.cards.decks.DeckCardInfo) Deck(mage.cards.decks.Deck) DeckCardInfo(mage.cards.decks.DeckCardInfo) CardInfo(mage.cards.repository.CardInfo) Card(mage.cards.Card)

Example 13 with Deck

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

the class RandomTest method test_GenerateRandomLibraryShufflePng.

@Test
@Ignore
public void test_GenerateRandomLibraryShufflePng() throws IOException {
    String dest = "f:/test/xmage/";
    // RandomUtil.setSeed(123);
    Player player = new HumanPlayer("random", RangeOfInfluence.ALL, 1);
    Game game = new TwoPlayerDuel(MultiplayerAttackOption.MULTIPLE, RangeOfInfluence.ALL, MulliganType.GAME_DEFAULT.getMulligan(0), 50);
    Deck deck = DeckTestUtils.buildRandomDeck("WGUBR", false, "GRN");
    player.getLibrary().addAll(deck.getCards(), game);
    // multiple cards analyze
    for (int i = 0; i < player.getLibrary().size(); i++) {
        UUID cardId = player.getLibrary().getCardList().get(i);
        // int halfIndex = Math.floorDiv(player.getLibrary().size(), 2);
        int colorMult = Math.floorDiv(255, player.getLibrary().size());
        int height = 512;
        int weight = 512;
        BufferedImage image = new BufferedImage(weight, height, BufferedImage.TYPE_INT_RGB);
        for (int x = 0; x < weight; x++) {
            for (int y = 0; y < height; y++) {
                // shuffle, search card position and draw
                player.getLibrary().shuffle();
                int cardPos = player.getLibrary().getCardPosition(cardId);
                // image.setRGB(x, y, cardPos < halfIndex ? Color.white.getRGB() : Color.black.getRGB());
                image.setRGB(x, y, new Color(colorMult * cardPos, colorMult * cardPos, colorMult * cardPos).getRGB());
            }
        }
        ImageIO.write(image, "png", new File(dest + "xmage_random_shuffle_" + i + ".png"));
    }
}
Also used : Player(mage.players.Player) HumanPlayer(mage.player.human.HumanPlayer) Game(mage.game.Game) HumanPlayer(mage.player.human.HumanPlayer) TwoPlayerDuel(mage.game.TwoPlayerDuel) Deck(mage.cards.decks.Deck) UUID(java.util.UUID) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 14 with Deck

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

the class RandomTest method test_SeedAndSameRandomDecks.

@Test
public void test_SeedAndSameRandomDecks() {
    RandomUtil.setSeed(123);
    DeckCardLists listSameA = DeckTestUtils.buildRandomDeckAndInitCards("WGUBR", false, "GRN");
    String infoSameA = listSameA.getCards().stream().map(c -> (c.getSetCode() + "-" + c.getCardName())).collect(Collectors.joining(","));
    RandomUtil.setSeed(321);
    DeckCardLists listDifferent = DeckTestUtils.buildRandomDeckAndInitCards("WGUBR", false, "GRN");
    String infoDifferent = listDifferent.getCards().stream().map(c -> (c.getSetCode() + "-" + c.getCardName())).collect(Collectors.joining(","));
    RandomUtil.setSeed(123);
    DeckCardLists listSameB = DeckTestUtils.buildRandomDeckAndInitCards("WGUBR", false, "GRN");
    String infoSameB = listSameB.getCards().stream().map(c -> (c.getSetCode() + "-" + c.getCardName())).collect(Collectors.joining(","));
    Assert.assertEquals("same seed must have same deck", infoSameA, infoSameB);
    Assert.assertNotEquals("different seed must have different deck", infoSameA, infoDifferent);
}
Also used : BufferedImage(java.awt.image.BufferedImage) RangeOfInfluence(mage.constants.RangeOfInfluence) Deck(mage.cards.decks.Deck) MultiplayerAttackOption(mage.constants.MultiplayerAttackOption) Outcome(mage.constants.Outcome) Test(org.junit.Test) IOException(java.io.IOException) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Player(mage.players.Player) File(java.io.File) ArrayList(java.util.ArrayList) java.awt(java.awt) Game(mage.game.Game) List(java.util.List) MulliganType(mage.game.mulligan.MulliganType) HumanPlayer(mage.player.human.HumanPlayer) Ignore(org.junit.Ignore) TwoPlayerDuel(mage.game.TwoPlayerDuel) ImageIO(javax.imageio.ImageIO) PlanarDieRollResult(mage.constants.PlanarDieRollResult) DeckCardLists(mage.cards.decks.DeckCardLists) RandomUtil(mage.util.RandomUtil) Assert(org.junit.Assert) DeckCardLists(mage.cards.decks.DeckCardLists) Test(org.junit.Test)

Example 15 with Deck

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

the class TestPlayRandomGame method playOneGame.

private void playOneGame() throws GameException, FileNotFoundException, IllegalArgumentException {
    Game game = new TwoPlayerDuel(MultiplayerAttackOption.LEFT, RangeOfInfluence.ALL, MulliganType.GAME_DEFAULT.getMulligan(0), 20);
    Player computerA = createRandomPlayer("ComputerA");
    Deck deck = generateRandomDeck();
    if (deck.getCards().size() < DECK_SIZE) {
        throw new IllegalArgumentException("Couldn't load deck, deck size = " + deck.getCards().size() + ", but must be " + DECK_SIZE);
    }
    game.addPlayer(computerA, deck);
    game.loadCards(deck.getCards(), computerA.getId());
    Player computerB = createRandomPlayer("ComputerB");
    Deck deck2 = generateRandomDeck();
    if (deck2.getCards().size() < DECK_SIZE) {
        throw new IllegalArgumentException("Couldn't load deck, deck size=" + deck2.getCards().size() + ", but must be " + DECK_SIZE);
    }
    game.addPlayer(computerB, deck2);
    game.loadCards(deck2.getCards(), computerB.getId());
    long t1 = System.nanoTime();
    GameOptions options = new GameOptions();
    options.testMode = true;
    game.setGameOptions(options);
    game.start(computerA.getId());
    long t2 = System.nanoTime();
    logger.info("Winner: " + game.getWinner());
    logger.info("Time: " + (t2 - t1) / 1000000 + " ms");
}
Also used : Player(mage.players.Player) ComputerPlayer(mage.player.ai.ComputerPlayer) Game(mage.game.Game) GameOptions(mage.game.GameOptions) TwoPlayerDuel(mage.game.TwoPlayerDuel) Deck(mage.cards.decks.Deck)

Aggregations

Deck (mage.cards.decks.Deck)27 Card (mage.cards.Card)11 Player (mage.players.Player)7 Ability (mage.abilities.Ability)5 Test (org.junit.Test)5 java.util (java.util)4 CompanionAbility (mage.abilities.keyword.CompanionAbility)4 Constructed (mage.cards.decks.Constructed)4 DeckValidatorErrorType (mage.cards.decks.DeckValidatorErrorType)4 CardType (mage.constants.CardType)4 FilterMana (mage.filter.FilterMana)4 Game (mage.game.Game)4 TwoPlayerDuel (mage.game.TwoPlayerDuel)4 UUID (java.util.UUID)3 CanBeYourCommanderAbility (mage.abilities.common.CanBeYourCommanderAbility)3 PartnerAbility (mage.abilities.keyword.PartnerAbility)3 PartnerWithAbility (mage.abilities.keyword.PartnerWithAbility)3 ExpansionSet (mage.cards.ExpansionSet)3 Sets (mage.cards.Sets)3 DeckCardLists (mage.cards.decks.DeckCardLists)3