- AI: Improvements to tap/untap logic in order to try not to target something twice for tapping/untapping.

This commit is contained in:
Agetian
2017-09-30 11:26:01 +00:00
parent 8326dc1dc7
commit 42f2b0a8e3
2 changed files with 43 additions and 1 deletions

View File

@@ -156,8 +156,21 @@ public abstract class TapAiBase extends SpellAbilityAi {
});
}
//try to exclude things that will already be tapped due to something on stack
//try to exclude things that will already be tapped due to something on stack or because something is
//already targeted in a parent or sub SA
CardCollection toExclude = new CardCollection();
SpellAbility saSub = sa.getRootAbility();
while (saSub != null) {
for (Card c : tapList) {
if (saSub.getApi() == ApiType.Tap) {
if (saSub.getTargets() != null && saSub.getTargets().getTargetCards().contains(c)) {
// Was already targeted in a parent or sub SA
toExclude.add(c);
}
}
}
saSub = saSub.getSubAbility();
}
for (SpellAbilityStackInstance si : game.getStack()) {
SpellAbility ab = si.getSpellAbility(false);
if (ab != null && ab.getApi() == ApiType.Tap) {

View File

@@ -16,6 +16,7 @@ import forge.game.phase.PhaseType;
import forge.game.player.Player;
import forge.game.player.PlayerCollection;
import forge.game.spellability.SpellAbility;
import forge.game.spellability.SpellAbilityStackInstance;
import forge.game.spellability.TargetRestrictions;
import forge.game.zone.ZoneType;
@@ -167,6 +168,34 @@ public class UntapAi extends SpellAbilityAi {
untapList.removeAll(toRemove);
}
//try to exclude things that will already be untapped due to something on stack or because something is
//already targeted in a parent or sub SA
CardCollection toExclude = new CardCollection();
SpellAbility saSub = sa.getRootAbility();
while (saSub != null) {
for (Card c : untapList) {
if (saSub.getApi() == ApiType.Untap) {
if (saSub.getTargets() != null && saSub.getTargets().getTargetCards().contains(c)) {
// Was already targeted in a parent or sub SA
toExclude.add(c);
}
}
}
saSub = saSub.getSubAbility();
}
for (SpellAbilityStackInstance si : ai.getGame().getStack()) {
SpellAbility ab = si.getSpellAbility(false);
if (ab != null && ab.getApi() == ApiType.Tap) {
for (Card c : untapList) {
// TODO: somehow ensure that the untapping SA won't be countered
if (si.getTargetChoices() != null && si.getTargetChoices().getTargetCards().contains(c)) {
toExclude.add(c);
}
}
}
}
untapList.removeAll(toExclude);
sa.resetTargets();
while (sa.getTargets().getNumTargeted() < tgt.getMaxTargets(sa.getHostCard(), sa)) {
Card choice = null;