/** * Generates all the lands for the deck. Generates non-basic if selected by the user and if the * deck isn't monocolored. Will fetch non-basic lands if required and then fill up the remaining * space with basic lands. Basic lands are adjusted according to the mana symbols seen in the * cards used in this deck. Usually the lands will be well balanced relative to the color of * cards. * * @param criteria the criteria of the lands to search for in the database. * @param landsCount the amount of lands required for this deck. * @param basicLands information about the basic lands from the sets used. */ private static void generateLands( CardCriteria criteria, int landsCount, Map<String, List<CardInfo>> basicLands) { int tries = 0; int countNonBasic = 0; // Store the nonbasic lands (if any) we'll add List<Card> deckLands = new ArrayList<>(); // Calculates the percentage of colored mana symbols over all spells in the deck Map<String, Double> percentage = genPool.calculateSpellColorPercentages(); // Only dual/tri color lands are generated for now, and not non-basic lands that only produce // colorless mana. if (!genPool.isMonoColoredDeck() && genDialog.useNonBasicLand()) { List<Card> landCards = genPool.filterLands(CardRepository.instance.findCards(criteria)); int allCount = landCards.size(); Random random = new Random(); if (allCount > 0) { while (countNonBasic < landsCount / 2) { Card card = landCards.get(random.nextInt(allCount)); if (genPool.isValidLandCard(card)) { Card addedCard = card.copy(); deckLands.add(addedCard); genPool.addCard(addedCard); countNonBasic++; } tries++; // to avoid infinite loop if (tries > MAX_TRIES) { // Not a problem, just use what we have break; } } } } // Calculate the amount of colored mana already can be produced by the non-basic lands Map<String, Integer> count = genPool.countManaProduced(deckLands); // Fill up the rest of the land quota with basic lands adjusted to fit the deck's mana costs addBasicLands(landsCount - countNonBasic, percentage, count, basicLands); }