From 9ef69149ee2e43a3e11bc0cbcd270ed16bfbe7c7 Mon Sep 17 00:00:00 2001 From: Sloth Date: Fri, 20 Dec 2013 15:45:27 +0000 Subject: [PATCH] - Fixed preventRunAwayActivations to work with temporary abilities. - AI updates and code cleanup. --- forge-gui/res/cardsfolder/s/splinter_twin.txt | 2 +- .../src/main/java/forge/ai/ComputerUtil.java | 12 +++++++++--- .../forge/ai/ability/CopyPermanentAi.java | 19 ++++++------------- .../main/java/forge/ai/ability/TokenAi.java | 9 +++------ 4 files changed, 19 insertions(+), 23 deletions(-) diff --git a/forge-gui/res/cardsfolder/s/splinter_twin.txt b/forge-gui/res/cardsfolder/s/splinter_twin.txt index 26f61d87e00..6422d990bdb 100644 --- a/forge-gui/res/cardsfolder/s/splinter_twin.txt +++ b/forge-gui/res/cardsfolder/s/splinter_twin.txt @@ -4,7 +4,7 @@ Types:Enchantment Aura K:Enchant creature A:SP$ Attach | Cost$ 2 R R | ValidTgts$ Creature | AILogic$ Pump S:Mode$ Continuous | Affected$ Creature.EnchantedBy | AddAbility$ ABCopy | Description$ Enchanted creature has "{T}: Put a token that's a copy of this creature onto the battlefield. That token has haste. Exile it at the beginning of the next end step." -SVar:ABCopy:AB$CopyPermanent | Cost$ T | Defined$ Self | Keywords$ Haste | AtEOT$ Exile | SpellDescription$ Put a token that's a copy of this creature onto the battlefield. That token has haste. Exile it at the beginning of the next end step. +SVar:ABCopy:AB$ CopyPermanent | Cost$ T | Defined$ Self | Keywords$ Haste | AtEOT$ Exile | SpellDescription$ Put a token that's a copy of this creature onto the battlefield. That token has haste. Exile it at the beginning of the next end step. SVar:NonStackingAttachEffect:True SVar:Picture:http://www.wizards.com/global/images/magic/general/splinter_twin.jpg Oracle:Enchant creature\nEnchanted creature has "{T}: Put a token that's a copy of this creature onto the battlefield. That token has haste. Exile it at the beginning of the next end step." \ No newline at end of file diff --git a/forge-gui/src/main/java/forge/ai/ComputerUtil.java b/forge-gui/src/main/java/forge/ai/ComputerUtil.java index aa8eb14bbc8..77d0609be41 100644 --- a/forge-gui/src/main/java/forge/ai/ComputerUtil.java +++ b/forge-gui/src/main/java/forge/ai/ComputerUtil.java @@ -1136,13 +1136,19 @@ public class ComputerUtil { * @return a boolean (returns true if the AI should stop using the ability). */ public static boolean preventRunAwayActivations(final SpellAbility sa) { - final int activations = sa.getRestrictions().getNumberTurnActivations(); + int activations = sa.getRestrictions().getNumberTurnActivations(); + + if (sa.isTemporary()) { + final Random r = MyRandom.getRandom(); + return r.nextFloat() >= .95; // Abilities created by static abilities have no memory + } + if (activations < 10) { //10 activations per turn should still be acceptable return false; } - final Random r = MyRandom.getRandom(); - return r.nextFloat() <= Math.pow(.95, activations); + final Random r = MyRandom.getRandom(); + return r.nextFloat() >= Math.pow(.95, activations); } /** diff --git a/forge-gui/src/main/java/forge/ai/ability/CopyPermanentAi.java b/forge-gui/src/main/java/forge/ai/ability/CopyPermanentAi.java index 6c62aa56371..571e392c581 100644 --- a/forge-gui/src/main/java/forge/ai/ability/CopyPermanentAi.java +++ b/forge-gui/src/main/java/forge/ai/ability/CopyPermanentAi.java @@ -3,10 +3,10 @@ package forge.ai.ability; import java.util.Collection; import java.util.List; import java.util.Map; -import java.util.Random; import com.google.common.base.Predicate; +import forge.ai.ComputerUtil; import forge.ai.ComputerUtilCard; import forge.ai.SpellAbilityAi; import forge.game.card.Card; @@ -18,7 +18,6 @@ import forge.game.player.PlayerActionConfirmMode; import forge.game.spellability.SpellAbility; import forge.game.spellability.TargetRestrictions; import forge.game.zone.ZoneType; -import forge.util.MyRandom; public class CopyPermanentAi extends SpellAbilityAi { @@ -30,20 +29,14 @@ public class CopyPermanentAi extends SpellAbilityAi { // Card source = sa.getSourceCard(); // TODO - I'm sure someone can do this AI better + if (ComputerUtil.preventRunAwayActivations(sa)) { + return false; + } + if (sa.hasParam("AtEOT") && !aiPlayer.getGame().getPhaseHandler().is(PhaseType.MAIN1)) { return false; } else { - double chance = .4; // 40 percent chance with instant speed stuff - if (SpellAbilityAi.isSorcerySpeed(sa)) { - chance = .667; // 66.7% chance for sorcery speed (since it will - // never activate EOT) - } - final Random r = MyRandom.getRandom(); - if (r.nextFloat() <= Math.pow(chance, sa.getActivationsThisTurn() + 1)) { - return this.doTriggerAINoCost(aiPlayer, sa, false); - } else { - return false; - } + return this.doTriggerAINoCost(aiPlayer, sa, false); } } diff --git a/forge-gui/src/main/java/forge/ai/ability/TokenAi.java b/forge-gui/src/main/java/forge/ai/ability/TokenAi.java index 0df4cb6913b..5eb1047460d 100644 --- a/forge-gui/src/main/java/forge/ai/ability/TokenAi.java +++ b/forge-gui/src/main/java/forge/ai/ability/TokenAi.java @@ -118,15 +118,12 @@ public class TokenAi extends SpellAbilityAi { return false; } } - if ((ph.isPlayerTurn(ai) - || ph.getPhase().isBefore( - PhaseType.COMBAT_DECLARE_ATTACKERS)) + if ((ph.isPlayerTurn(ai) || ph.getPhase().isBefore(PhaseType.COMBAT_DECLARE_ATTACKERS)) && !sa.hasParam("ActivationPhases") && !sa.hasParam("PlayerTurn") && !SpellAbilityAi.isSorcerySpeed(sa) && !haste) { return false; } - if ((ph.getPhase().isAfter(PhaseType.COMBAT_BEGIN) || game.getPhaseHandler().isPlayerTurn( - opp)) + if ((ph.getPhase().isAfter(PhaseType.COMBAT_BEGIN) || game.getPhaseHandler().isPlayerTurn(opp)) && oneShot) { return false; } @@ -191,7 +188,7 @@ public class TokenAi extends SpellAbilityAi { return true; } if (sa.isAbility()) { - return (r.nextFloat() < .9); + return true; } return (r.nextFloat() < .8);