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);
}
}
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);
}
}
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);
}
}
}
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;
}
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;
}
Aggregations