mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 03:38:01 +00:00
- AI: Improvements to tap/untap logic in order to try not to target something twice for tapping/untapping.
This commit is contained in:
@@ -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();
|
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()) {
|
for (SpellAbilityStackInstance si : game.getStack()) {
|
||||||
SpellAbility ab = si.getSpellAbility(false);
|
SpellAbility ab = si.getSpellAbility(false);
|
||||||
if (ab != null && ab.getApi() == ApiType.Tap) {
|
if (ab != null && ab.getApi() == ApiType.Tap) {
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import forge.game.phase.PhaseType;
|
|||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
import forge.game.player.PlayerCollection;
|
import forge.game.player.PlayerCollection;
|
||||||
import forge.game.spellability.SpellAbility;
|
import forge.game.spellability.SpellAbility;
|
||||||
|
import forge.game.spellability.SpellAbilityStackInstance;
|
||||||
import forge.game.spellability.TargetRestrictions;
|
import forge.game.spellability.TargetRestrictions;
|
||||||
import forge.game.zone.ZoneType;
|
import forge.game.zone.ZoneType;
|
||||||
|
|
||||||
@@ -167,6 +168,34 @@ public class UntapAi extends SpellAbilityAi {
|
|||||||
untapList.removeAll(toRemove);
|
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();
|
sa.resetTargets();
|
||||||
while (sa.getTargets().getNumTargeted() < tgt.getMaxTargets(sa.getHostCard(), sa)) {
|
while (sa.getTargets().getNumTargeted() < tgt.getMaxTargets(sa.getHostCard(), sa)) {
|
||||||
Card choice = null;
|
Card choice = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user