Search in sources :

Example 6 with Card

use of mage.cards.Card in project mage by magefree.

the class ComputerPlayer method choose.

@Override
public boolean choose(Outcome outcome, Cards cards, TargetCard target, Game game) {
    log.debug("choose 2");
    if (cards == null || cards.isEmpty()) {
        return true;
    }
    // sometimes a target selection can be made from a player that does not control the ability
    UUID abilityControllerId = playerId;
    if (target.getTargetController() != null && target.getAbilityController() != null) {
        abilityControllerId = target.getAbilityController();
    }
    List<Card> cardChoices = new ArrayList<>(cards.getCards(target.getFilter(), game));
    while (!target.doneChosing()) {
        Card card = pickTarget(abilityControllerId, cardChoices, outcome, target, null, game);
        if (card != null) {
            target.add(card.getId(), game);
            cardChoices.remove(card);
        } else {
            // We don't have any valid target to choose so stop choosing
            return target.getTargets().size() >= target.getNumberOfTargets();
        }
        if (outcome == Outcome.Neutral && target.getTargets().size() > target.getNumberOfTargets() + (target.getMaxNumberOfTargets() - target.getNumberOfTargets()) / 2) {
            return true;
        }
    }
    return true;
}
Also used : RateCard(mage.game.draft.RateCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 7 with Card

use of mage.cards.Card in project mage by magefree.

the class MCTSNode method randomizePlayers.

/*
     * Shuffles each players library so that there is no knowledge of its order
     * Swaps all other players hands with random cards from the library so that
     * there is no knowledge of what cards are in opponents hands
     */
protected void randomizePlayers(Game game, UUID playerId) {
    for (Player player : game.getState().getPlayers().values()) {
        if (!player.getId().equals(playerId)) {
            int handSize = player.getHand().size();
            player.getLibrary().addAll(player.getHand().getCards(game), game);
            player.getHand().clear();
            player.getLibrary().shuffle();
            for (int i = 0; i < handSize; i++) {
                Card card = player.getLibrary().removeFromTop(game);
                card.setZone(Zone.HAND, game);
                player.getHand().add(card);
            }
        } else {
            player.getLibrary().shuffle();
        }
    }
}
Also used : Player(mage.players.Player) Card(mage.cards.Card)

Example 8 with Card

use of mage.cards.Card in project mage by magefree.

the class ComputerPlayer method buildDeckWithNormalCards.

public static Deck buildDeckWithNormalCards(int deckMinSize, List<Card> cardPool, final List<ColoredManaSymbol> colors) {
    // top 23 cards plus basic lands until 40 deck size
    Deck deck = new Deck();
    final int DECK_SIZE = deckMinSize != 0 ? deckMinSize : 40;
    // 23 from 40
    final int DECK_CARDS_COUNT = Math.floorDiv(deckMinSize * 23, 40);
    final int DECK_LANDS_COUNT = DECK_SIZE - DECK_CARDS_COUNT;
    // sort card pool by top score
    List<Card> sortedCards = new ArrayList<>(cardPool);
    Collections.sort(sortedCards, new Comparator<Card>() {

        @Override
        public int compare(Card o1, Card o2) {
            Integer score1 = RateCard.rateCard(o1, colors);
            Integer score2 = RateCard.rateCard(o2, colors);
            return score2.compareTo(score1);
        }
    });
    // get top cards
    int cardNum = 0;
    while (deck.getCards().size() < DECK_CARDS_COUNT && sortedCards.size() > cardNum) {
        Card card = sortedCards.get(cardNum);
        if (!card.isBasic()) {
            deck.getCards().add(card);
            deck.getSideboard().remove(card);
        }
        cardNum++;
    }
    // add basic lands by color percent
    // TODO:  compensate for non basic lands
    Mana mana = new Mana();
    for (Card card : deck.getCards()) {
        mana.add(card.getManaCost().getMana());
    }
    double total = mana.getBlack() + mana.getBlue() + mana.getGreen() + mana.getRed() + mana.getWhite();
    // most frequent land is forest by default
    int mostLand = 0;
    String mostLandName = "Forest";
    if (mana.getGreen() > 0) {
        int number = (int) Math.round(mana.getGreen() / total * DECK_LANDS_COUNT);
        addBasicLands(deck, "Forest", number);
        mostLand = number;
    }
    if (mana.getBlack() > 0) {
        int number = (int) Math.round(mana.getBlack() / total * DECK_LANDS_COUNT);
        addBasicLands(deck, "Swamp", number);
        if (number > mostLand) {
            mostLand = number;
            mostLandName = "Swamp";
        }
    }
    if (mana.getBlue() > 0) {
        int number = (int) Math.round(mana.getBlue() / total * DECK_LANDS_COUNT);
        addBasicLands(deck, "Island", number);
        if (number > mostLand) {
            mostLand = number;
            mostLandName = "Island";
        }
    }
    if (mana.getWhite() > 0) {
        int number = (int) Math.round(mana.getWhite() / total * DECK_LANDS_COUNT);
        addBasicLands(deck, "Plains", number);
        if (number > mostLand) {
            mostLand = number;
            mostLandName = "Plains";
        }
    }
    if (mana.getRed() > 0) {
        int number = (int) Math.round(mana.getRed() / total * DECK_LANDS_COUNT);
        addBasicLands(deck, "Mountain", number);
        if (number > mostLand) {
            mostLandName = "Plains";
        }
    }
    // adds remaining lands (most popular name)
    addBasicLands(deck, mostLandName, DECK_SIZE - deck.getCards().size());
    return deck;
}
Also used : ConditionalMana(mage.ConditionalMana) Mana(mage.Mana) Deck(mage.cards.decks.Deck) RateCard(mage.game.draft.RateCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 9 with Card

use of mage.cards.Card in project mage by magefree.

the class ComputerPlayer method pickBestCard.

public Card pickBestCard(List<Card> cards, List<ColoredManaSymbol> chosenColors) {
    if (cards.isEmpty()) {
        return null;
    }
    Card bestCard = null;
    int maxScore = 0;
    for (Card card : cards) {
        int score = RateCard.rateCard(card, chosenColors);
        if (bestCard == null || score > maxScore) {
            maxScore = score;
            bestCard = card;
        }
    }
    return bestCard;
}
Also used : RateCard(mage.game.draft.RateCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 10 with Card

use of mage.cards.Card in project mage by magefree.

the class ComputerPlayer method buildDeckWithOnlyBasicLands.

public static Deck buildDeckWithOnlyBasicLands(int deckMinSize, List<Card> cardPool) {
    // random cards from card pool
    Deck deck = new Deck();
    final int DECK_SIZE = deckMinSize != 0 ? deckMinSize : 40;
    List<Card> sortedCards = new ArrayList<>(cardPool);
    if (!sortedCards.isEmpty()) {
        while (deck.getCards().size() < DECK_SIZE) {
            deck.getCards().add(sortedCards.get(RandomUtil.nextInt(sortedCards.size())));
        }
        return deck;
    } else {
        addBasicLands(deck, "Forest", DECK_SIZE);
        return deck;
    }
}
Also used : Deck(mage.cards.decks.Deck) RateCard(mage.game.draft.RateCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Aggregations

Card (mage.cards.Card)1448 Player (mage.players.Player)1096 Permanent (mage.game.permanent.Permanent)423 FilterCard (mage.filter.FilterCard)381 UUID (java.util.UUID)340 CardsImpl (mage.cards.CardsImpl)253 MageObject (mage.MageObject)212 FixedTarget (mage.target.targetpointer.FixedTarget)173 TargetCard (mage.target.TargetCard)165 Cards (mage.cards.Cards)159 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)111 ContinuousEffect (mage.abilities.effects.ContinuousEffect)99 TargetCardInHand (mage.target.common.TargetCardInHand)98 Target (mage.target.Target)86 HashSet (java.util.HashSet)85 FilterCreatureCard (mage.filter.common.FilterCreatureCard)84 ApprovingObject (mage.ApprovingObject)77 Ability (mage.abilities.Ability)71 TargetPlayer (mage.target.TargetPlayer)67 TargetPermanent (mage.target.TargetPermanent)64