mirror of
https://github.com/Relintai/mtg-forge-ios.git
synced 2025-01-08 15:39:35 +01:00
- 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:
parent
d6d3a05547
commit
04da295f49
@ -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);
|
||||
}
|
||||
|
@ -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--) {
|
||||
|
Loading…
Reference in New Issue
Block a user