Search in sources :

Example 11 with ColoredManaSymbol

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

the class Sets method generateRandomCardPool.

public static List<Card> generateRandomCardPool(int cardsCount, List<ColoredManaSymbol> allowedColors, boolean onlyBasicLands, List<String> allowedSets) {
    CardCriteria criteria = new CardCriteria();
    if (onlyBasicLands) {
        // only lands
        criteria.rarities(Rarity.LAND);
        // basic lands is colorless
        criteria.colorless(true);
    } else {
        // any card, but not basic lands
        criteria.notTypes(CardType.LAND);
        // clear colors
        criteria.white(false);
        criteria.blue(false);
        criteria.black(false);
        criteria.red(false);
        criteria.green(false);
        // colorless is not allowed for gen
        criteria.colorless(false);
    }
    if (allowedSets != null && allowedSets.size() > 0) {
        for (String code : allowedSets) {
            criteria.setCodes(code);
        }
    }
    FilterMana manaNeed = new FilterMana();
    for (ColoredManaSymbol color : allowedColors) {
        switch(color) {
            case W:
                manaNeed.setWhite(true);
                criteria.white(true);
                break;
            case U:
                manaNeed.setBlue(true);
                criteria.blue(true);
                break;
            case B:
                manaNeed.setBlack(true);
                criteria.black(true);
                break;
            case R:
                manaNeed.setRed(true);
                criteria.red(true);
                break;
            case G:
                manaNeed.setGreen(true);
                criteria.green(true);
                break;
        }
    }
    List<CardInfo> cards = CardRepository.instance.findCards(criteria);
    if (cards.isEmpty()) {
        throw new IllegalStateException("Can't find cards for chosen colors to generate deck: " + allowedColors);
    }
    int count = 0;
    int tries = 0;
    List<Card> cardPool = new ArrayList<>();
    while (count < cardsCount) {
        CardInfo cardInfo = cards.get(RandomUtil.nextInt(cards.size()));
        Card card = cardInfo != null ? cardInfo.getCard() : null;
        if (card != null) {
            FilterMana manaCard = card.getColorIdentity();
            boolean cardManaOK = true;
            if (onlyBasicLands) {
                // Assert.assertEquals("only basic lands allow, but found " + card.getName(), 1, card.getMana().size());
                for (Mana manaLand : card.getMana()) {
                    if (manaLand.getWhite() > 0 && !manaNeed.isWhite()) {
                        cardManaOK = false;
                    }
                    if (manaLand.getBlue() > 0 && !manaNeed.isBlue()) {
                        cardManaOK = false;
                    }
                    if (manaLand.getBlack() > 0 && !manaNeed.isBlack()) {
                        cardManaOK = false;
                    }
                    if (manaLand.getRed() > 0 && !manaNeed.isRed()) {
                        cardManaOK = false;
                    }
                    if (manaLand.getGreen() > 0 && !manaNeed.isGreen()) {
                        cardManaOK = false;
                    }
                    if (manaLand.getColorless() > 0) {
                        cardManaOK = false;
                    }
                // ignore colorless land (wastes)
                }
            } else {
                // discard any card that have not needed color
                if (manaCard.isWhite() && !manaNeed.isWhite()) {
                    cardManaOK = false;
                }
                if (manaCard.isBlue() && !manaNeed.isBlue()) {
                    cardManaOK = false;
                }
                if (manaCard.isBlack() && !manaNeed.isBlack()) {
                    cardManaOK = false;
                }
                if (manaCard.isRed() && !manaNeed.isRed()) {
                    cardManaOK = false;
                }
                if (manaCard.isGreen() && !manaNeed.isGreen()) {
                    cardManaOK = false;
                }
            }
            if (cardManaOK) {
                cardPool.add(card);
                count++;
            }
        }
        tries++;
        if (tries > 4096) {
            // to avoid infinite loop
            throw new IllegalStateException("Not enough cards for chosen colors to generate deck: " + allowedColors);
        }
    }
    return cardPool;
}
Also used : FilterMana(mage.filter.FilterMana) Mana(mage.Mana) FilterMana(mage.filter.FilterMana) CardCriteria(mage.cards.repository.CardCriteria) CardInfo(mage.cards.repository.CardInfo) ColoredManaSymbol(mage.constants.ColoredManaSymbol)

Example 12 with ColoredManaSymbol

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

the class ManaTest method shouldCreateManaFromWhiteColoredManaSymbol.

@Test
public void shouldCreateManaFromWhiteColoredManaSymbol() {
    // given
    ColoredManaSymbol symbol = ColoredManaSymbol.W;
    // when
    Mana mana = new Mana(symbol);
    // then
    assertEquals(0, mana.getGreen());
    assertEquals(0, mana.getRed());
    assertEquals(0, mana.getBlack());
    assertEquals(0, mana.getBlue());
    assertEquals(1, mana.getWhite());
}
Also used : FilterMana(mage.filter.FilterMana) ColoredManaSymbol(mage.constants.ColoredManaSymbol) Test(org.junit.Test)

Example 13 with ColoredManaSymbol

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

the class ManaTest method shouldCreateManaFromBlackColoredManaSymbol.

@Test
public void shouldCreateManaFromBlackColoredManaSymbol() {
    // given
    ColoredManaSymbol symbol = ColoredManaSymbol.B;
    // when
    Mana mana = new Mana(symbol);
    // then
    assertEquals(0, mana.getGreen());
    assertEquals(0, mana.getRed());
    assertEquals(1, mana.getBlack());
    assertEquals(0, mana.getBlue());
    assertEquals(0, mana.getWhite());
}
Also used : FilterMana(mage.filter.FilterMana) ColoredManaSymbol(mage.constants.ColoredManaSymbol) Test(org.junit.Test)

Example 14 with ColoredManaSymbol

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

the class ManaTest method shouldCreateManaFromRedColoredManaSymbol.

@Test
public void shouldCreateManaFromRedColoredManaSymbol() {
    // given
    ColoredManaSymbol symbol = ColoredManaSymbol.R;
    // when
    Mana mana = new Mana(symbol);
    // then
    assertEquals(0, mana.getGreen());
    assertEquals(1, mana.getRed());
    assertEquals(0, mana.getBlack());
    assertEquals(0, mana.getBlue());
    assertEquals(0, mana.getWhite());
}
Also used : FilterMana(mage.filter.FilterMana) ColoredManaSymbol(mage.constants.ColoredManaSymbol) Test(org.junit.Test)

Example 15 with ColoredManaSymbol

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

the class ManaTest method shouldCreateManaFromGreenColoredManaSymbol.

@Test
public void shouldCreateManaFromGreenColoredManaSymbol() {
    // given
    ColoredManaSymbol symbol = ColoredManaSymbol.G;
    // when
    Mana mana = new Mana(symbol);
    // then
    assertEquals(1, mana.getGreen());
    assertEquals(0, mana.getRed());
    assertEquals(0, mana.getBlack());
    assertEquals(0, mana.getBlue());
    assertEquals(0, mana.getWhite());
}
Also used : FilterMana(mage.filter.FilterMana) ColoredManaSymbol(mage.constants.ColoredManaSymbol) Test(org.junit.Test)

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