From aba978da580ad47bf71fe5e227c64e7515d69680 Mon Sep 17 00:00:00 2001 From: Agetian Date: Tue, 24 Jan 2017 19:25:34 +0000 Subject: [PATCH] - Do not tap just animated manlands to animate another manland. --- .../src/main/java/forge/ai/AiCardMemory.java | 19 ++++++++++++++---- .../main/java/forge/ai/ComputerUtilMana.java | 20 +++++++++++++------ .../main/java/forge/ai/ability/AnimateAi.java | 18 ++++++++++++++++- 3 files changed, 46 insertions(+), 11 deletions(-) diff --git a/forge-ai/src/main/java/forge/ai/AiCardMemory.java b/forge-ai/src/main/java/forge/ai/AiCardMemory.java index 002241f638f..27c0720394f 100644 --- a/forge-ai/src/main/java/forge/ai/AiCardMemory.java +++ b/forge-ai/src/main/java/forge/ai/AiCardMemory.java @@ -40,10 +40,17 @@ import java.util.Set; */ public class AiCardMemory { - private Set memMandatoryAttackers = new HashSet(); - private Set memHeldManaSources = new HashSet(); - private Set memAttachedThisTurn = new HashSet(); - //private HashSet memRevealedCards = new HashSet(); + private final Set memMandatoryAttackers; + private final Set memHeldManaSources; + private final Set memAttachedThisTurn; + private final Set 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); } } \ No newline at end of file diff --git a/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java b/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java index bd490a806ac..cafc9377c72 100644 --- a/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java +++ b/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java @@ -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(); diff --git a/forge-ai/src/main/java/forge/ai/ability/AnimateAi.java b/forge-ai/src/main/java/forge/ai/ability/AnimateAi.java index f0158103326..6298dd889ab 100644 --- a/forge-ai/src/main/java/forge/ai/ability/AnimateAi.java +++ b/forge-ai/src/main/java/forge/ai/ability/AnimateAi.java @@ -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); + } }