- Do not tap just animated manlands to animate another manland.

This commit is contained in:
Agetian
2017-01-24 19:25:34 +00:00
parent 158e7d683e
commit aba978da58
3 changed files with 46 additions and 11 deletions

View File

@@ -40,10 +40,17 @@ import java.util.Set;
*/
public class AiCardMemory {
private Set<Card> memMandatoryAttackers = new HashSet<Card>();
private Set<Card> memHeldManaSources = new HashSet<Card>();
private Set<Card> memAttachedThisTurn = new HashSet<Card>();
//private HashSet<Card> memRevealedCards = new HashSet<Card>();
private final Set<Card> memMandatoryAttackers;
private final Set<Card> memHeldManaSources;
private final Set<Card> memAttachedThisTurn;
private final Set<Card> memAnimatedThisTurn;
public AiCardMemory() {
this.memMandatoryAttackers = new HashSet<>();
this.memHeldManaSources = new HashSet<>();
this.memAttachedThisTurn = new HashSet<>();
this.memAnimatedThisTurn = new HashSet<>();
}
/**
* Defines the memory set in which the card is remembered
@@ -54,6 +61,7 @@ public class AiCardMemory {
MANDATORY_ATTACKERS,
HELD_MANA_SOURCES,
ATTACHED_THIS_TURN,
ANIMATED_THIS_TURN,
//REVEALED_CARDS // stub, not linked to AI code yet
}
@@ -65,6 +73,8 @@ public class AiCardMemory {
return memHeldManaSources;
case ATTACHED_THIS_TURN:
return memAttachedThisTurn;
case ANIMATED_THIS_TURN:
return memAnimatedThisTurn;
//case REVEALED_CARDS:
// return memRevealedCards;
default:
@@ -236,5 +246,6 @@ public class AiCardMemory {
clearMemorySet(MemorySet.MANDATORY_ATTACKERS);
clearMemorySet(MemorySet.HELD_MANA_SOURCES);
clearMemorySet(MemorySet.ATTACHED_THIS_TURN);
clearMemorySet(MemorySet.ANIMATED_THIS_TURN);
}
}

View File

@@ -7,6 +7,7 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import forge.ai.ability.AnimateAi;
import forge.card.ColorSet;
import forge.card.MagicColor;
import forge.card.mana.ManaAtom;
@@ -201,12 +202,19 @@ public class ComputerUtilMana {
continue;
}
// For abilities like Genju of the Cedars, make sure that we're not activating the aura ability by tapping the enchanted card for mana
if (sa.getHostCard() != null && sa.getApi() == ApiType.Animate && sa.getHostCard().isAura()
&& "Enchanted".equals(sa.getParam("Defined"))
&& ma.getHostCard() == sa.getHostCard().getEnchantingCard()
&& ma.getPayCosts().hasTapCost()) {
continue;
if (sa.getHostCard() != null && sa.getApi() == ApiType.Animate) {
// For abilities like Genju of the Cedars, make sure that we're not activating the aura ability by tapping the enchanted card for mana
if (sa.getHostCard().isAura() && "Enchanted".equals(sa.getParam("Defined"))
&& ma.getHostCard() == sa.getHostCard().getEnchantingCard()
&& ma.getPayCosts().hasTapCost()) {
continue;
}
// If a manland was previously animated this turn, do not tap it to animate another manland
if (sa.getHostCard().isLand() && ma.getHostCard().isLand()
&& AnimateAi.isAnimatedThisTurn(ai, ma.getHostCard())) {
continue;
}
}
final String typeRes = cost.getSourceRestriction();

View File

@@ -7,9 +7,11 @@ import java.util.Map;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import forge.ai.AiCardMemory;
import forge.ai.ComputerUtilCard;
import forge.ai.ComputerUtilCost;
import forge.ai.PlayerControllerAi;
import forge.ai.SpellAbilityAi;
import forge.card.CardType;
import forge.game.Game;
@@ -182,6 +184,7 @@ public class AnimateAi extends SpellAbilityAi {
&& !ComputerUtilCard.doesSpecifiedCreatureBlock(aiPlayer, animatedCopy)) {
return false;
}
this.rememberAnimatedThisTurn(aiPlayer, c);
}
}
return bFlag; // All of the defined stuff is animated, not very useful
@@ -221,7 +224,9 @@ public class AnimateAi extends SpellAbilityAi {
if (list.isEmpty()) {
return false;
}
sa.getTargets().add(ComputerUtilCard.getWorstAI(list));
Card toAnimate = ComputerUtilCard.getWorstAI(list);
this.rememberAnimatedThisTurn(aiPlayer, toAnimate);
sa.getTargets().add(toAnimate);
}
return true;
}
@@ -323,6 +328,7 @@ public class AnimateAi extends SpellAbilityAi {
// select the worst of the best
final Card worst = ComputerUtilCard.getWorstAI(maxList);
this.rememberAnimatedThisTurn(ai, worst);
sa.getTargets().add(worst);
return true;
}
@@ -602,4 +608,14 @@ public class AnimateAi extends SpellAbilityAi {
}
ComputerUtilCard.applyStaticContPT(game, card, null);
}
private void rememberAnimatedThisTurn(Player ai, Card c) {
AiCardMemory mem = ((PlayerControllerAi)ai.getController()).getAi().getCardMemory();
mem.rememberCard(c, AiCardMemory.MemorySet.ANIMATED_THIS_TURN);
}
public static boolean isAnimatedThisTurn(Player ai, Card c) {
AiCardMemory mem = ((PlayerControllerAi)ai.getController()).getAi().getCardMemory();
return mem.isRememberedCard(c, AiCardMemory.MemorySet.ANIMATED_THIS_TURN);
}
}