Search in sources :

Example 6 with ColoredManaSymbol

use of mage.constants.ColoredManaSymbol in project mage by magefree.

the class DeckBuilder method addLandsToDeck.

/**
 * Adds lands from non basic land (if provided), adds basic lands getting
 * them from provided {@link RateCallback}}.
 *
 * @param allowedColors
 * @param landCardPool
 * @param callback
 */
private static void addLandsToDeck(List<ColoredManaSymbol> allowedColors, List<String> setsToUse, List<Card> landCardPool, RateCallback callback) {
    // Calculate statistics per color.
    final Map<String, Integer> colorCount = new HashMap<>();
    for (final Card card : deck.getCards()) {
        for (String symbol : card.getManaCostSymbols()) {
            int count = 0;
            symbol = symbol.replace("{", "").replace("}", "");
            if (isColoredMana(symbol)) {
                for (ColoredManaSymbol allowed : allowedColors) {
                    if (symbol.contains(allowed.toString())) {
                        count++;
                    }
                }
                if (count > 0) {
                    Integer typeCount = colorCount.getOrDefault(symbol, 0);
                    typeCount += 1;
                    colorCount.put(symbol, typeCount);
                }
            }
        }
    }
    // Add suitable non basic lands to deck in order of pack.
    final Map<String, Integer> colorSource = new HashMap<>();
    for (final ColoredManaSymbol color : ColoredManaSymbol.values()) {
        colorSource.put(color.toString(), 0);
    }
    if (landCardPool != null) {
        for (final Card landCard : landCardPool) {
            deck.getCards().add(landCard);
            for (Mana mana : landCard.getMana()) {
                for (ColoredManaSymbol color : allowedColors) {
                    int amount = mana.getColor(color);
                    if (amount > 0) {
                        Integer count = colorSource.get(color.toString());
                        count += amount;
                        colorSource.put(color.toString(), count);
                    }
                }
            }
        }
    }
    // Add optimal basic lands to deck.
    while (deck.getCards().size() < deckSize) {
        ColoredManaSymbol bestColor = null;
        // Default to a color in the allowed colors
        if (allowedColors != null && !allowedColors.isEmpty()) {
            bestColor = allowedColors.get(RandomUtil.nextInt(allowedColors.size()));
        }
        int lowestRatio = Integer.MAX_VALUE;
        for (final ColoredManaSymbol color : ColoredManaSymbol.values()) {
            final Integer count = colorCount.get(color.toString());
            if (count != null && count > 0) {
                final int source = colorSource.get(color.toString());
                final int ratio;
                if (source < MIN_SOURCE) {
                    ratio = source - count;
                } else {
                    ratio = source * 100 / count;
                }
                if (ratio < lowestRatio) {
                    lowestRatio = ratio;
                    bestColor = color;
                }
            }
        }
        final Card landCard = callback.getBestBasicLand(bestColor, setsToUse);
        Integer count = colorSource.get(bestColor.toString());
        count++;
        colorSource.put(bestColor.toString(), count);
        deck.getCards().add(landCard);
    }
}
Also used : Mana(mage.Mana) ColoredManaSymbol(mage.constants.ColoredManaSymbol) Card(mage.cards.Card)

Example 7 with ColoredManaSymbol

use of mage.constants.ColoredManaSymbol in project mage by magefree.

the class DeckBuilderTest method testAllArtifacts.

@Test
public void testAllArtifacts() {
    final List<Card> spellCardPool = new ArrayList<>();
    final UUID owner = UUID.randomUUID();
    final List<ColoredManaSymbol> allowedColors = new ArrayList<>(Arrays.asList(ColoredManaSymbol.U));
    final List<String> setsToUse = new ArrayList<>();
    final List<Card> landCardPool = null;
    final RateCallback rateCallback = new RateCallback() {

        @Override
        public int rateCard(Card card) {
            return 6;
        }

        @Override
        public Card getBestBasicLand(ColoredManaSymbol color, List<String> setsToUse) {
            Assert.assertNotNull(color);
            return new Island(owner, new CardSetInfo("Island", "MRD", "999", Rarity.LAND));
        }
    };
    for (int i = 0; i < 24; i++) {
        Card c = new RandomArtifactCreature(owner, i, "Random Artifact " + i);
        spellCardPool.add(c);
    }
    DeckBuilder.buildDeck(spellCardPool, allowedColors, setsToUse, landCardPool, 40, rateCallback);
}
Also used : CardSetInfo(mage.cards.CardSetInfo) ArrayList(java.util.ArrayList) RateCallback(mage.interfaces.rate.RateCallback) Island(mage.cards.basiclands.Island) Card(mage.cards.Card) ColoredManaSymbol(mage.constants.ColoredManaSymbol) ArrayList(java.util.ArrayList) List(java.util.List) UUID(java.util.UUID) Test(org.junit.Test)

Example 8 with ColoredManaSymbol

use of mage.constants.ColoredManaSymbol in project mage by magefree.

the class AddManaInAnyCombinationEffect method produceMana.

@Override
public Mana produceMana(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
        int size = manaSymbols.size();
        Mana mana = new Mana();
        List<String> manaStrings = new ArrayList<>(size);
        for (ColoredManaSymbol coloredManaSymbol : manaSymbols) {
            manaStrings.add(coloredManaSymbol.toString());
        }
        List<Integer> manaList = player.getMultiAmount(this.outcome, manaStrings, 0, amount.calculate(game, source, this), MultiAmountType.MANA, game);
        for (int i = 0; i < size; i++) {
            ColoredManaSymbol coloredManaSymbol = manaSymbols.get(i);
            int amount = manaList.get(i);
            for (int j = 0; j < amount; j++) {
                mana.add(new Mana(coloredManaSymbol));
            }
        }
        return mana;
    }
    return null;
}
Also used : Player(mage.players.Player) Mana(mage.Mana) ColoredManaSymbol(mage.constants.ColoredManaSymbol)

Example 9 with ColoredManaSymbol

use of mage.constants.ColoredManaSymbol in project mage by magefree.

the class AddManaInAnyCombinationEffect method setText.

private String setText() {
    StringBuilder sb = new StringBuilder("Add ");
    String amountString = CardUtil.numberToText(amount.toString());
    sb.append(amountString);
    sb.append(" mana in any combination of ");
    if (manaSymbols.size() == 5) {
        sb.append("colors");
    } else {
        int i = 0;
        for (ColoredManaSymbol coloredManaSymbol : manaSymbols) {
            i++;
            if (i > 1) {
                sb.append(" and/or ");
            }
            sb.append('{').append(coloredManaSymbol.toString()).append('}');
        }
    }
    if (amountString.equals("X")) {
        sb.append(", where X is ");
        sb.append(amount.getMessage());
    }
    return sb.toString();
}
Also used : ColoredManaSymbol(mage.constants.ColoredManaSymbol)

Example 10 with ColoredManaSymbol

use of mage.constants.ColoredManaSymbol in project mage by magefree.

the class RateCard method getManaCostScore.

/**
 * Get manacost score.
 * Depends on chosen colors. Returns negative score for those cards that doesn't fit allowed colors.
 * If allowed colors are not chosen, then score based on converted cost is returned with penalty for heavy colored cards.
 * gives bonus to multicolor cards that fit within allowed colors and if allowed colors is <5
 *
 * @param card
 * @param allowedColors Can be null.
 * @return
 */
private static int getManaCostScore(Card card, List<ColoredManaSymbol> allowedColors) {
    int converted = card.getManaValue();
    if (allowedColors == null) {
        int colorPenalty = 0;
        for (String symbol : card.getManaCostSymbols()) {
            if (isColoredMana(symbol)) {
                colorPenalty++;
            }
        }
        return 2 * (converted - colorPenalty + 1);
    }
    final Map<String, Integer> singleCount = new HashMap<>();
    int maxSingleCount = 0;
    for (String symbol : card.getManaCostSymbols()) {
        int count = 0;
        symbol = symbol.replace("{", "").replace("}", "");
        if (isColoredMana(symbol)) {
            for (ColoredManaSymbol allowed : allowedColors) {
                if (allowed.toString().equals(symbol)) {
                    count++;
                }
            }
            if (count == 0) {
                return -100;
            }
            Integer typeCount = singleCount.get(symbol);
            if (typeCount == null) {
                typeCount = 0;
            }
            typeCount += 1;
            singleCount.put(symbol, typeCount);
            maxSingleCount = Math.max(maxSingleCount, typeCount);
        }
    }
    if (maxSingleCount > 5)
        maxSingleCount = 5;
    int rate = 2 * converted + 3 * (10 - SINGLE_PENALTY[maxSingleCount]);
    if (singleCount.size() > 1 && singleCount.size() < 5) {
        rate += MULTICOLOR_BONUS;
    }
    return rate;
}
Also used : ColoredManaSymbol(mage.constants.ColoredManaSymbol)

Aggregations

ColoredManaSymbol (mage.constants.ColoredManaSymbol)20 FilterMana (mage.filter.FilterMana)7 Test (org.junit.Test)7 Mana (mage.Mana)4 Card (mage.cards.Card)4 Ability (mage.abilities.Ability)2 CardCriteria (mage.cards.repository.CardCriteria)2 CardInfo (mage.cards.repository.CardInfo)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 UUID (java.util.UUID)1 ManaOptions (mage.abilities.mana.ManaOptions)1 CardSetInfo (mage.cards.CardSetInfo)1 Island (mage.cards.basiclands.Island)1 RateCallback (mage.interfaces.rate.RateCallback)1 Player (mage.players.Player)1