diff --git a/forge-ai/src/main/java/forge/ai/ComputerUtil.java b/forge-ai/src/main/java/forge/ai/ComputerUtil.java index 0729bde23b3..2f870cb0540 100644 --- a/forge-ai/src/main/java/forge/ai/ComputerUtil.java +++ b/forge-ai/src/main/java/forge/ai/ComputerUtil.java @@ -257,6 +257,7 @@ public class ComputerUtil { } public static Card getCardPreference(final Player ai, final Card activate, final String pref, final CardCollection typeList) { + final Game game = ai.getGame(); if (activate != null) { final String[] prefValid = activate.getSVar("AIPreference").split("\\$"); if (prefValid[0].equals(pref)) { @@ -271,6 +272,13 @@ public class ComputerUtil { // search for permanents with SacMe. priority 1 is the lowest, priority 5 the highest for (int ip = 0; ip < 6; ip++) { final int priority = 6 - ip; + if (priority == 2 && ai.isCardInPlay("Crucible of Worlds")) { + CardCollection landsInPlay = CardLists.getType(typeList, "Land"); + if (!landsInPlay.isEmpty()) { + // Don't need more land. + return ComputerUtilCard.getWorstLand(landsInPlay); + } + } final CardCollection sacMeList = CardLists.filter(typeList, new Predicate() { @Override public boolean apply(final Card c) { @@ -295,13 +303,23 @@ public class ComputerUtil { return ComputerUtilCard.getWorstLand(landsInPlay); } } + + // try everything when about to die + if (game.getPhaseHandler().getPhase().equals(PhaseType.COMBAT_DECLARE_BLOCKERS) + && ComputerUtilCombat.lifeInSeriousDanger(ai, game.getCombat())) { + final CardCollection nonCreatures = CardLists.getNotType(typeList, "Creature"); + if (!nonCreatures.isEmpty()) { + return ComputerUtilCard.getWorstAI(nonCreatures); + } else if (!typeList.isEmpty()) { + return ComputerUtilCard.getWorstAI(typeList); + } + } } else if (pref.contains("DiscardCost")) { // search for permanents with DiscardMe for (int ip = 0; ip < 6; ip++) { // priority 0 is the lowest, priority 5 the highest final int priority = 6 - ip; for (Card c : typeList) { - if (priority == 3 && c.isLand() - && !ai.getCardsIn(ZoneType.Battlefield, "Crucible of Worlds").isEmpty()) { + if (priority == 3 && c.isLand() && ai.isCardInPlay("Crucible of Worlds")) { return c; } if (c.hasSVar("DiscardMe") && Integer.parseInt(c.getSVar("DiscardMe")) == priority) { @@ -322,6 +340,14 @@ public class ComputerUtil { return ComputerUtilCard.getWorstLand(landsInHand); } } + + // try everything when about to die + if (game.getPhaseHandler().getPhase().equals(PhaseType.COMBAT_DECLARE_BLOCKERS) + && ComputerUtilCombat.lifeInSeriousDanger(ai, game.getCombat())) { + if (!typeList.isEmpty()) { + return ComputerUtilCard.getWorstAI(typeList); + } + } } return null; }