mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 19:58:00 +00:00
Optimize replacement effect lookup during AI calculating mana.
This commit is contained in:
@@ -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,13 +1098,9 @@ 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)
|
|
||||||
&& replacementEffect.canReplace(repParams)
|
|
||||||
&& replacementEffect.getMapParams().containsKey("ManaReplacement")
|
|
||||||
&& replacementEffect.zonesCheck(game.getZoneOf(crd))) {
|
|
||||||
String repType = crd.getSVar(replacementEffect.getMapParams().get("ManaReplacement"));
|
String repType = crd.getSVar(replacementEffect.getMapParams().get("ManaReplacement"));
|
||||||
if (repType.contains("Chosen")) {
|
if (repType.contains("Chosen")) {
|
||||||
repType = repType.replace("Chosen", MagicColor.toShortString(crd.getChosenColor()));
|
repType = repType.replace("Chosen", MagicColor.toShortString(crd.getChosenColor()));
|
||||||
@@ -1099,8 +1108,6 @@ public class ComputerUtilMana {
|
|||||||
mp.setManaReplaceType(repType);
|
mp.setManaReplaceType(repType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Set<String> reflectedColors = CardUtil.getReflectableManaColors(m);
|
Set<String> reflectedColors = CardUtil.getReflectableManaColors(m);
|
||||||
// find possible colors
|
// find possible colors
|
||||||
|
|||||||
Reference in New Issue
Block a user