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;
}
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;
}
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"));
}
}
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);
}
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");
}
Aggregations