- More precise mana cost analysis for the purpose of Mana Ritual and Nykthos AI (should lead to fewer wasted activations).

This commit is contained in:
Agetian
2017-01-27 11:21:09 +00:00
parent dc01a30136
commit 5382f4e1b0
3 changed files with 18 additions and 3 deletions

View File

@@ -580,7 +580,9 @@ public class ComputerUtilCost {
for (Card c : cardsToConsider) { for (Card c : cardsToConsider) {
for (SpellAbility sa : c.getManaAbilities()) { for (SpellAbility sa : c.getManaAbilities()) {
colorsAvailable.add(sa.getManaPart().getOrigProduced()); if (sa.getManaPart() != null) {
colorsAvailable.add(sa.getManaPart().getOrigProduced());
}
} }
} }

View File

@@ -24,6 +24,7 @@ import java.util.List;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import forge.card.ColorSet;
import forge.card.MagicColor; import forge.card.MagicColor;
import forge.card.mana.ManaCost; import forge.card.mana.ManaCost;
@@ -346,13 +347,17 @@ public class SpecialCardAi {
for (final SpellAbility testSa : ComputerUtilAbility.getOriginalAndAltCostAbilities(all, ai)) { for (final SpellAbility testSa : ComputerUtilAbility.getOriginalAndAltCostAbilities(all, ai)) {
ManaCost cost = testSa.getPayCosts().getTotalMana(); ManaCost cost = testSa.getPayCosts().getTotalMana();
boolean canPayWithAvailableColors = cost.canBePaidWithAvaliable(ColorSet.fromNames(
ComputerUtilCost.getAvailableManaColors(ai, sa.getHostCard())).getColor());
byte colorProfile = cost.getColorProfile(); byte colorProfile = cost.getColorProfile();
if (cost.getCMC() == 0 && cost.countX() == 0) { if (cost.getCMC() == 0 && cost.countX() == 0) {
// no mana cost, no need to activate this SA then (additional mana not needed) // no mana cost, no need to activate this SA then (additional mana not needed)
continue; continue;
} else if (colorProfile != 0 && (cost.getColorProfile() & MagicColor.fromName(prominentColor)) == 0) { } else if (colorProfile != 0 && !canPayWithAvailableColors
// does not feature prominent color, won't be able to pay for it with SA activated for this color && (cost.getColorProfile() & MagicColor.fromName(prominentColor)) == 0) {
// don't have at least one of each shard required to pay, so most likely won't be able to pay
continue; continue;
} else if ((testSa.getPayCosts().getTotalMana().getCMC() > devotion + numManaSrcs - activationCost)) { } else if ((testSa.getPayCosts().getTotalMana().getCMC() > devotion + numManaSrcs - activationCost)) {
// the cost may be too high even if we activate this SA // the cost may be too high even if we activate this SA

View File

@@ -4,9 +4,11 @@ import com.google.common.base.Predicates;
import forge.ai.AiPlayDecision; import forge.ai.AiPlayDecision;
import forge.ai.ComputerUtil; import forge.ai.ComputerUtil;
import forge.ai.ComputerUtilAbility; import forge.ai.ComputerUtilAbility;
import forge.ai.ComputerUtilCost;
import forge.ai.ComputerUtilMana; import forge.ai.ComputerUtilMana;
import forge.ai.PlayerControllerAi; import forge.ai.PlayerControllerAi;
import forge.ai.SpellAbilityAi; import forge.ai.SpellAbilityAi;
import forge.card.ColorSet;
import forge.card.MagicColor; import forge.card.MagicColor;
import forge.card.mana.ManaCost; import forge.card.mana.ManaCost;
import forge.game.ability.AbilityUtils; import forge.game.ability.AbilityUtils;
@@ -136,9 +138,15 @@ public class ManaEffectAi extends SpellAbilityAi {
List<SpellAbility> all = ComputerUtilAbility.getSpellAbilities(ai.getCardsIn(ZoneType.Hand), ai); List<SpellAbility> all = ComputerUtilAbility.getSpellAbilities(ai.getCardsIn(ZoneType.Hand), ai);
for (final SpellAbility testSa : ComputerUtilAbility.getOriginalAndAltCostAbilities(all, ai)) { for (final SpellAbility testSa : ComputerUtilAbility.getOriginalAndAltCostAbilities(all, ai)) {
ManaCost cost = testSa.getPayCosts().getTotalMana(); ManaCost cost = testSa.getPayCosts().getTotalMana();
boolean canPayWithAvailableColors = cost.canBePaidWithAvaliable(ColorSet.fromNames(
ComputerUtilCost.getAvailableManaColors(ai, (List<Card>)null)).getColor());
if (cost.getCMC() == 0 && cost.countX() == 0) { if (cost.getCMC() == 0 && cost.countX() == 0) {
// no mana cost, no need to activate this SA then (additional mana not needed) // no mana cost, no need to activate this SA then (additional mana not needed)
continue; continue;
} else if (cost.getColorProfile() != 0 && !canPayWithAvailableColors) {
// don't have one of each shard represented, may not be able to pay the cost
continue;
} }
if (testSa.getHostCard().getName().equals(host.getName()) || testSa.hasParam("AINoRecursiveCheck")) { if (testSa.getHostCard().getName().equals(host.getName()) || testSa.hasParam("AINoRecursiveCheck")) {