From eee12a63f2efc500b11969840963a965a4d614db Mon Sep 17 00:00:00 2001 From: Sloth Date: Thu, 18 Oct 2012 17:47:17 +0000 Subject: [PATCH] - The AI will now try to avoid letting the human discard cards like Loxodon Smiter. --- .../AbilityFactoryZoneAffecting.java | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryZoneAffecting.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryZoneAffecting.java index 2f0e0602101..d0a0a18c301 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryZoneAffecting.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryZoneAffecting.java @@ -25,6 +25,8 @@ import java.util.Iterator; import java.util.List; import java.util.Random; +import com.google.common.base.Predicate; + import forge.Card; import forge.CardLists; @@ -1433,23 +1435,37 @@ public class AbilityFactoryZoneAffecting { // discard human cards for (int i = 0; i < numCards; i++) { if (dPChHand.size() > 0) { + List goodChoices = CardLists.filter(dPChHand, new Predicate() { + @Override + public boolean apply(final Card c) { + if (c.hasKeyword("If a spell or ability an opponent controls causes you to discard CARDNAME," + + " put it onto the battlefield instead of putting it into your graveyard.") + || !c.getSVar("DiscardMe").equals("")) { + return false; + } + return true; + } + }); + if (goodChoices.isEmpty()) { + goodChoices = dPChHand; + } final List dChoices = new ArrayList(); if (params.containsKey("DiscardValid")) { final String validString = params.get("DiscardValid"); if (validString.contains("Creature") && !validString.contains("nonCreature")) { - final Card c = CardFactoryUtil.getBestCreatureAI(dPChHand); + final Card c = CardFactoryUtil.getBestCreatureAI(goodChoices); if (c != null) { - dChoices.add(CardFactoryUtil.getBestCreatureAI(dPChHand)); + dChoices.add(CardFactoryUtil.getBestCreatureAI(goodChoices)); } } } - Collections.sort(dPChHand, CardLists.TextLenReverseComparator); + Collections.sort(goodChoices, CardLists.TextLenReverseComparator); - CardLists.sortCMC(dPChHand); - dChoices.add(dPChHand.get(0)); + CardLists.sortCMC(goodChoices); + dChoices.add(goodChoices.get(0)); - final Card dC = dChoices.get(CardUtil.getRandomIndex(dChoices)); + final Card dC = goodChoices.get(CardUtil.getRandomIndex(goodChoices)); dPChHand.remove(dC); if (mode.startsWith("Reveal")) {