mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +00:00
- More intelligent checking for the AI's reason to cast a sorcery spell in the given turn.
This commit is contained in:
@@ -1982,4 +1982,18 @@ public class ComputerUtil {
|
|||||||
|
|
||||||
return hasTarget;
|
return hasTarget;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean hasReasonToPlaySaThisTurn(final Player ai, final SpellAbility sa) {
|
||||||
|
// This is currently used by ComputerUtilCost.willPayUnlessCost to determine if there's a viable reason to cast a spell
|
||||||
|
// that can be paid for with an untapped shockland.
|
||||||
|
|
||||||
|
if (ai == null || sa == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
AiPlayDecision decision = ((PlayerControllerAi)ai.getController()).getAi().canPlaySa(sa);
|
||||||
|
boolean willPlay = decision == AiPlayDecision.WillPlay || decision == AiPlayDecision.WaitForMain2;
|
||||||
|
|
||||||
|
return willPlay;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,12 +7,15 @@ import forge.game.ability.AbilityUtils;
|
|||||||
import forge.game.card.Card;
|
import forge.game.card.Card;
|
||||||
import forge.game.card.CardCollection;
|
import forge.game.card.CardCollection;
|
||||||
import forge.game.card.CardLists;
|
import forge.game.card.CardLists;
|
||||||
|
import forge.game.card.CardPredicates;
|
||||||
import forge.game.card.CounterType;
|
import forge.game.card.CounterType;
|
||||||
import forge.game.combat.Combat;
|
import forge.game.combat.Combat;
|
||||||
import forge.game.cost.*;
|
import forge.game.cost.*;
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
import forge.game.spellability.Spell;
|
import forge.game.spellability.Spell;
|
||||||
import forge.game.spellability.SpellAbility;
|
import forge.game.spellability.SpellAbility;
|
||||||
|
import forge.game.spellability.TargetChoices;
|
||||||
|
import forge.game.spellability.TargetRestrictions;
|
||||||
import forge.game.zone.ZoneType;
|
import forge.game.zone.ZoneType;
|
||||||
import forge.util.collect.FCollectionView;
|
import forge.util.collect.FCollectionView;
|
||||||
import forge.util.MyRandom;
|
import forge.util.MyRandom;
|
||||||
@@ -420,6 +423,7 @@ public class ComputerUtilCost {
|
|||||||
// If the new land size would equal the CMC of a card in AIs hand, play it untapped
|
// If the new land size would equal the CMC of a card in AIs hand, play it untapped
|
||||||
final int landsize = payer.getLandsInPlay().size() + 1;
|
final int landsize = payer.getLandsInPlay().size() + 1;
|
||||||
for (Card c : payer.getCardsIn(ZoneType.Hand)) {
|
for (Card c : payer.getCardsIn(ZoneType.Hand)) {
|
||||||
|
int cmc = c.getCMC();
|
||||||
// try to determine if the mana shards provided by the lands would be applicable to pay the mana cost
|
// try to determine if the mana shards provided by the lands would be applicable to pay the mana cost
|
||||||
boolean canPay = c.getManaCost().canBePaidWithAvaliable(ColorSet.fromNames(getAvailableManaColors(payer, source)).getColor());
|
boolean canPay = c.getManaCost().canBePaidWithAvaliable(ColorSet.fromNames(getAvailableManaColors(payer, source)).getColor());
|
||||||
// try to determine that there is a valid target for a spell (very basic, consider expanding)
|
// try to determine that there is a valid target for a spell (very basic, consider expanding)
|
||||||
@@ -428,16 +432,13 @@ public class ComputerUtilCost {
|
|||||||
// for auras, make sure that a good enough target exists
|
// for auras, make sure that a good enough target exists
|
||||||
requirementsMet = ComputerUtil.hasGoodTargetForAura(payer, c);
|
requirementsMet = ComputerUtil.hasGoodTargetForAura(payer, c);
|
||||||
} else if (c.isSorcery()) {
|
} else if (c.isSorcery()) {
|
||||||
// for sorceries with one mode that has a target, consider actually having a target that makes the AI decide to play the spell ability
|
// for sorceries with one mode, consider actually checking for a reason for the AI to decide to play the spell ability
|
||||||
if (c.getAllSpellAbilities().size() == 1) {
|
if (c.getAllSpellAbilities().size() == 1) {
|
||||||
SpellAbility ability = c.getFirstSpellAbility();
|
SpellAbility ability = c.getFirstSpellAbility();
|
||||||
if (ability != null && ability.usesTargeting()) {
|
requirementsMet = ComputerUtil.hasReasonToPlaySaThisTurn(payer, ability);
|
||||||
AiPlayDecision decision = ((PlayerControllerAi)payer.getController()).getAi().canPlaySa(ability);
|
|
||||||
requirementsMet = decision == AiPlayDecision.WillPlay || decision == AiPlayDecision.WaitForMain2;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if (landsize == cmc && canPay && requirementsMet) {
|
||||||
if (landsize == c.getCMC() && canPay && requirementsMet) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user