Search in sources :

Example 1 with Card

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

the class ComputerPlayer method addBasicLands.

private static void addBasicLands(Deck deck, String landName, int number) {
    Set<String> landSets = TournamentUtil.getLandSetCodeForDeckSets(deck.getExpansionSetCodes());
    CardCriteria criteria = new CardCriteria();
    if (!landSets.isEmpty()) {
        criteria.setCodes(landSets.toArray(new String[landSets.size()]));
    }
    criteria.rarities(Rarity.LAND).name(landName);
    List<CardInfo> cards = CardRepository.instance.findCards(criteria);
    if (cards.isEmpty()) {
        criteria = new CardCriteria();
        criteria.rarities(Rarity.LAND).name(landName);
        criteria.setCodes("M15");
        cards = CardRepository.instance.findCards(criteria);
    }
    for (int i = 0; i < number; i++) {
        Card land = cards.get(RandomUtil.nextInt(cards.size())).getCard();
        deck.getCards().add(land);
    }
}
Also used : CardCriteria(mage.cards.repository.CardCriteria) CardInfo(mage.cards.repository.CardInfo) RateCard(mage.game.draft.RateCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 2 with Card

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

the class ComputerPlayer method pickCard.

@Override
public void pickCard(List<Card> cards, Deck deck, Draft draft) {
    if (cards.isEmpty()) {
        throw new IllegalArgumentException("No cards to pick from.");
    }
    try {
        Card bestCard = pickBestCard(cards, chosenColors);
        int maxScore = RateCard.rateCard(bestCard, chosenColors);
        int pickedCardRate = RateCard.getBaseCardScore(bestCard);
        if (pickedCardRate <= 30) {
            // if card is bad
            // try to counter pick without any color restriction
            Card counterPick = pickBestCard(cards, null);
            int counterPickScore = RateCard.getBaseCardScore(counterPick);
            // take it!
            if (counterPickScore >= 80) {
                bestCard = counterPick;
                maxScore = RateCard.rateCard(bestCard, chosenColors);
            }
        }
        String colors = "not chosen yet";
        // remember card if colors are not chosen yet
        if (chosenColors == null) {
            rememberPick(bestCard, maxScore);
            chosenColors = chooseDeckColorsIfPossible();
        }
        if (chosenColors != null) {
            colors = "";
            for (ColoredManaSymbol symbol : chosenColors) {
                colors += symbol.toString();
            }
        }
        log.debug("[DEBUG] AI picked: " + bestCard.getName() + ", score=" + maxScore + ", deck colors=" + colors);
        draft.addPick(playerId, bestCard.getId(), null);
    } catch (Exception e) {
        log.debug("Exception during AI pick card for draft playerId= " + getId());
        draft.addPick(playerId, cards.get(0).getId(), null);
    }
}
Also used : IOException(java.io.IOException) RateCard(mage.game.draft.RateCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 3 with Card

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

the class ComputerPlayer method playLand.

// end priorityPlay method
protected void playLand(Game game) {
    log.debug("playLand");
    Set<Card> lands = new LinkedHashSet<>();
    for (Card landCard : hand.getCards(new FilterLandCard(), game)) {
        // remove lands that can not be played
        boolean canPlay = false;
        for (Ability ability : landCard.getAbilities(game)) {
            if (ability instanceof PlayLandAbility) {
                if (!game.getContinuousEffects().preventedByRuleModification(GameEvent.getEvent(GameEvent.EventType.PLAY_LAND, landCard.getId(), ability, playerId), null, game, true)) {
                    canPlay = true;
                }
            }
        }
        if (canPlay) {
            lands.add(landCard);
        }
    }
    while (!lands.isEmpty() && this.canPlayLand()) {
        if (lands.size() == 1) {
            this.playLand(lands.iterator().next(), game, false);
        } else {
            playALand(lands, game);
        }
    }
}
Also used : RateCard(mage.game.draft.RateCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 4 with Card

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

the class ComputerPlayer method chooseTarget.

@Override
public boolean chooseTarget(Outcome outcome, Cards cards, TargetCard target, Ability source, Game game) {
    if (cards == null || cards.isEmpty()) {
        return target.isRequired(source);
    }
    // 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();
    }
    // we still use playerId when getting cards even if they don't control the search
    List<Card> cardChoices = new ArrayList<>(cards.getCards(target.getFilter(), source != null ? source.getSourceId() : null, playerId, game));
    while (!target.doneChosing()) {
        Card card = pickTarget(abilityControllerId, cardChoices, outcome, target, source, game);
        if (card != null) {
            target.addTarget(card.getId(), source, 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 5 with Card

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

the class ComputerPlayer method pickWorstCard.

public Card pickWorstCard(List<Card> cards, List<ColoredManaSymbol> chosenColors, Target target, Ability source, Game game) {
    if (cards.isEmpty()) {
        return null;
    }
    Card worstCard = null;
    int minScore = Integer.MAX_VALUE;
    for (Card card : cards) {
        int score = RateCard.rateCard(card, chosenColors);
        boolean worseCard = false;
        if (worstCard == null) {
            // we need any card to prevent NPE in callers
            worseCard = true;
        } else if (score < minScore) {
            // we need worse card
            if (target != null && source != null && game != null) {
                // but also check it can be targeted
                worseCard = target.canTarget(getId(), card.getId(), source, game);
            } else {
                // target object wasn't provided, so accepting it anyway
                worseCard = true;
            }
        }
        // is it worse than previous one?
        if (worseCard) {
            minScore = score;
            worstCard = card;
        }
    }
    return worstCard;
}
Also used : 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