Optimize replacement effect lookup during AI calculating mana.

This commit is contained in:
Myrd
2015-02-14 15:06:14 +00:00
parent da74a6f70a
commit ed9bc163cf

View File

@@ -1046,6 +1046,19 @@ public class ComputerUtilMana {
final ArrayListMultimap<Integer, SpellAbility> manaMap = ArrayListMultimap.create(); final ArrayListMultimap<Integer, SpellAbility> manaMap = ArrayListMultimap.create();
final Game game = ai.getGame(); final Game game = ai.getGame();
List<ReplacementEffect> replacementEffects = new ArrayList<ReplacementEffect>();
for (final Player p : game.getPlayers()) {
for (final Card crd : p.getAllCards()) {
for (final ReplacementEffect replacementEffect : crd.getReplacementEffects()) {
if (replacementEffect.requirementsCheck(game)
&& replacementEffect.getMapParams().containsKey("ManaReplacement")
&& replacementEffect.zonesCheck(game.getZoneOf(crd))) {
replacementEffects.add(replacementEffect);
}
}
}
}
// Loop over all current available mana sources // Loop over all current available mana sources
for (final Card sourceCard : getAvailableMana(ai, checkPlayable)) { for (final Card sourceCard : getAvailableMana(ai, checkPlayable)) {
if (DEBUG_MANA_PAYMENT) { if (DEBUG_MANA_PAYMENT) {
@@ -1085,20 +1098,14 @@ public class ComputerUtilMana {
repParams.put("Player", ai); repParams.put("Player", ai);
repParams.put("AbilityMana", m); repParams.put("AbilityMana", m);
for (final Player p : game.getPlayers()) { for (final ReplacementEffect replacementEffect : replacementEffects) {
for (final Card crd : p.getAllCards()) { if (replacementEffect.canReplace(repParams)) {
for (final ReplacementEffect replacementEffect : crd.getReplacementEffects()) { Card crd = replacementEffect.getHostCard();
if (replacementEffect.requirementsCheck(game) String repType = crd.getSVar(replacementEffect.getMapParams().get("ManaReplacement"));
&& replacementEffect.canReplace(repParams) if (repType.contains("Chosen")) {
&& replacementEffect.getMapParams().containsKey("ManaReplacement") repType = repType.replace("Chosen", MagicColor.toShortString(crd.getChosenColor()));
&& replacementEffect.zonesCheck(game.getZoneOf(crd))) {
String repType = crd.getSVar(replacementEffect.getMapParams().get("ManaReplacement"));
if (repType.contains("Chosen")) {
repType = repType.replace("Chosen", MagicColor.toShortString(crd.getChosenColor()));
}
mp.setManaReplaceType(repType);
}
} }
mp.setManaReplaceType(repType);
} }
} }