- Refactored the code that deals with holding mana sources for spells. Still need to figure out where to best place the decision to hold mana so that the AI is not too conservative in its plays related to useful pump spells.

This commit is contained in:
Agetian
2014-09-05 06:20:28 +00:00
parent aa6c0e9208
commit cfcb0b7549
3 changed files with 24 additions and 7 deletions

View File

@@ -209,6 +209,15 @@ public class AiCardMemory {
return false;
}
/**
* Determines if the memory set is empty.
* @param set the memory set to inspect.
* @return true, if the given memory set contains no remembered cards.
*/
public boolean isMemorySetEmpty(MemorySet set) {
return getMemorySet(set).isEmpty();
}
/**
* Clears the "remembered attackers" memory set stored in this card memory for the given player.
*/

View File

@@ -5,7 +5,6 @@ import forge.game.Game;
import forge.game.GameObject;
import forge.game.ability.AbilityFactory;
import forge.game.ability.AbilityUtils;
import forge.game.ability.ApiType;
import forge.game.card.Card;
import forge.game.card.CardLists;
import forge.game.card.CardPredicates.Presets;
@@ -49,11 +48,6 @@ public class PumpAi extends PumpAiBase {
*/
@Override
protected boolean canPlayAI(Player ai, SpellAbility sa) {
SpellAbility futureSpell = ((PlayerControllerAi)ai.getController()).getAi().predictSpellToCastInMain2(ApiType.Pump);
if (futureSpell != null && futureSpell.getHostCard() != null) {
((PlayerControllerAi)ai.getController()).getAi().reserveManaSourcesForMain2(futureSpell);
}
final Cost cost = sa.getPayCosts();
final Game game = ai.getGame();
final PhaseHandler ph = game.getPhaseHandler();

View File

@@ -3,13 +3,17 @@ package forge.ai.ability;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.Iterables;
import forge.ai.AiCardMemory;
import forge.ai.AiController;
import forge.ai.ComputerUtil;
import forge.ai.ComputerUtilCard;
import forge.ai.ComputerUtilCombat;
import forge.ai.PlayerControllerAi;
import forge.ai.SpellAbilityAi;
import forge.card.MagicColor;
import forge.game.Game;
import forge.game.ability.ApiType;
import forge.game.card.Card;
import forge.game.card.CardFactory;
import forge.game.card.CardLists;
@@ -439,6 +443,16 @@ public abstract class PumpAiBase extends SpellAbilityAi {
return false;
}
// determine if some mana sources need to be held for the future spell to cast in Main 2 before determining whether to pump.
AiController aic = ((PlayerControllerAi)ai.getController()).getAi();
if (aic.getCardMemory().isMemorySetEmpty(AiCardMemory.MemorySet.HELD_MANA_SOURCES)) {
// only hold mana sources once
SpellAbility futureSpell = aic.predictSpellToCastInMain2(ApiType.Pump);
if (futureSpell != null && futureSpell.getHostCard() != null) {
aic.reserveManaSourcesForMain2(futureSpell);
}
}
// will the creature attack (only relevant for sorcery speed)?
if (phase.getPhase().isBefore(PhaseType.COMBAT_DECLARE_ATTACKERS)
&& phase.isPlayerTurn(ai)
@@ -448,7 +462,7 @@ public abstract class PumpAiBase extends SpellAbilityAi {
return true;
}
// buff attacker/blocker using using triggered pump
// buff attacker/blocker using triggered pump
if (sa.isTrigger() && phase.getPhase().isBefore(PhaseType.COMBAT_DECLARE_ATTACKERS)) {
if (phase.isPlayerTurn(ai)) {
if (CombatUtil.canAttack(c)) {