- Some improvements to DoNotDiscardIfAble discard AI for corner cases, to avoid (very rare) situations where the AI would not discard anything or crash.

git-svn-id: http://svn.slightlymagic.net/forge/trunk@35736 269b9781-a132-4a9b-9d4e-f004f1b56b58
This commit is contained in:
Agetian 2017-09-24 04:48:07 +00:00
parent d6d3a05547
commit 04da295f49
2 changed files with 27 additions and 0 deletions

View File

@ -943,6 +943,29 @@ public class AiController {
// for more discard options
worst = ComputerUtilCard.getCheapestSpellAI(validCards);
}
if (worst == null && !validCards.isEmpty()) {
// still nothing chosen, so choose the first thing that works, trying not to make DoNotDiscardIfAble
// discards
for (Card c : validCards) {
if (!c.hasSVar("DoNotDiscardIfAble")) {
worst = c;
break;
}
}
// Only DoNotDiscardIfAble cards? If we have a duplicate for something, discard it
if (worst == null) {
for (Card c : validCards) {
if (CardLists.filter(player.getCardsIn(ZoneType.Hand), CardPredicates.nameEquals(c.getName())).size() > 1) {
worst = c;
break;
}
}
if (worst == null) {
// Otherwise just grab a random card and discard it
worst = Aggregates.random(validCards);
}
}
}
discardList.add(worst);
validCards.remove(worst);
}

View File

@ -374,6 +374,10 @@ public class ComputerUtilCard {
Predicates.or(CardPredicates.isType("Instant"), CardPredicates.isType("Sorcery")));
Collections.sort(cc, CardLists.CmcComparatorInv);
if (cc.isEmpty()) {
return null;
}
Card cheapest = cc.getLast();
if (cheapest.hasSVar("DoNotDiscardIfAble")) {
for (int i = cc.size() - 1; i >= 0; i--) {