From dd2bc70f47a0a1a20eadad608db5bcc728c9c96b Mon Sep 17 00:00:00 2001 From: Agetian Date: Fri, 20 Apr 2018 06:46:13 +0300 Subject: [PATCH] - Some improvements to the Jhoira AI algorithm in MoJhoSto: don't rely on an AI logic (since it's mode-specific). - Fixed a crash related to the AI playing MoJhoSto. --- .../main/java/forge/ai/ComputerUtilMana.java | 4 +++- .../src/main/java/forge/ai/SpecialCardAi.java | 3 ++- .../src/main/java/forge/ai/ability/PlayAi.java | 18 +++++++++--------- .../j/jhoira_of_the_ghitu_avatar.txt | 2 +- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java b/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java index cd890ca1cfb..3011e56ba06 100644 --- a/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java +++ b/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java @@ -1115,7 +1115,9 @@ public class ComputerUtilMana { final String xSvar = card.getSVar("X").startsWith("Count$xPaid") ? "PayX" : "X"; if (!sa.getSVar(xSvar).isEmpty() || card.hasSVar(xSvar)) { if (xSvar.equals("PayX") && card.hasSVar(xSvar)) { - manaToAdd = Integer.parseInt(card.getSVar(xSvar)) * cost.getXcounter(); // X + // X SVar may end up being an empty string when copying a spell with no cost (e.g. Jhoira Avatar) + String xValue = card.getSVar(xSvar); + manaToAdd = xValue.isEmpty() ? 0 : Integer.parseInt(card.getSVar(xSvar)) * cost.getXcounter(); // X } else { manaToAdd = AbilityUtils.calculateAmount(card, xSvar, sa) * cost.getXcounter(); } diff --git a/forge-ai/src/main/java/forge/ai/SpecialCardAi.java b/forge-ai/src/main/java/forge/ai/SpecialCardAi.java index 33cf8e83c4d..26912848459 100644 --- a/forge-ai/src/main/java/forge/ai/SpecialCardAi.java +++ b/forge-ai/src/main/java/forge/ai/SpecialCardAi.java @@ -783,7 +783,8 @@ public class SpecialCardAi { // In MoJhoSto, prefer Jhoira sorcery ability from time to time if (source.getGame().getRules().hasAppliedVariant(GameType.MoJhoSto) - && ai.getLandsInPlay().size() >= 3 && MyRandom.percentTrue(50)) { + && CardLists.filter(ai.getLandsInPlay(), CardPredicates.Presets.UNTAPPED).size() >= 3 + && MyRandom.percentTrue(50)) { return false; } diff --git a/forge-ai/src/main/java/forge/ai/ability/PlayAi.java b/forge-ai/src/main/java/forge/ai/ability/PlayAi.java index 5004d56508e..90896e6f1e5 100644 --- a/forge-ai/src/main/java/forge/ai/ability/PlayAi.java +++ b/forge-ai/src/main/java/forge/ai/ability/PlayAi.java @@ -53,17 +53,17 @@ public class PlayAi extends SpellAbilityAi { return false; } } - + + if (game.getRules().hasAppliedVariant(GameType.MoJhoSto) && source.getName().equals("Jhoira of the Ghitu Avatar")) { + // Some additional logic for MoJhoSto: don't spam activate the Instant copying ability all the time + // Can probably be improved, but as random as MoJhoSto already is, probably not a huge deal for now + if ("Instant".equals(sa.getParam("AnySupportedCard")) && MyRandom.percentTrue(80)) { + return false; + } + } + if ("ReplaySpell".equals(logic)) { return ComputerUtil.targetPlayableSpellCard(ai, cards, sa, sa.hasParam("WithoutManaCost")); - } else if ("JhoiraAvatarInstant".equals(logic)) { - if (game.getRules().hasAppliedVariant(GameType.MoJhoSto)) { - // Some additional logic for MoJhoSto: don't spam activate the Instant copying ability all the time - // Can probably be improved, but as random as MoJhoSto already is, probably not a huge deal for now - if (MyRandom.percentTrue(80)) { - return false; - } - } } if (source != null && source.hasKeyword("Hideaway") && source.hasRemembered()) { diff --git a/forge-gui/res/cardsfolder/j/jhoira_of_the_ghitu_avatar.txt b/forge-gui/res/cardsfolder/j/jhoira_of_the_ghitu_avatar.txt index 5d34abec83b..119e586d395 100644 --- a/forge-gui/res/cardsfolder/j/jhoira_of_the_ghitu_avatar.txt +++ b/forge-gui/res/cardsfolder/j/jhoira_of_the_ghitu_avatar.txt @@ -2,7 +2,7 @@ Name:Jhoira of the Ghitu Avatar ManaCost:no cost Types:Vanguard HandLifeModifier:+1/+0 -A:AB$ Play | Cost$ 3 Discard<1/Card> | ActivationZone$ Command | AnySupportedCard$ Instant | RandomCopied$ True | RandomNum$ 3 | ChoiceNum$ 1 | CopyCard$ True | WithoutManaCost$ True | AILogic$ JhoiraAvatarInstant | SpellDescription$ Copy three instant cards chosen at random. You may cast one of the copies without paying its mana cost. +A:AB$ Play | Cost$ 3 Discard<1/Card> | ActivationZone$ Command | AnySupportedCard$ Instant | RandomCopied$ True | RandomNum$ 3 | ChoiceNum$ 1 | CopyCard$ True | WithoutManaCost$ True | SpellDescription$ Copy three instant cards chosen at random. You may cast one of the copies without paying its mana cost. A:AB$ Play | Cost$ 3 Discard<1/Card> | ActivationZone$ Command | AnySupportedCard$ Sorcery | RandomCopied$ True | RandomNum$ 3 | ChoiceNum$ 1 | CopyCard$ True | WithoutManaCost$ True | SorcerySpeed$ True | SpellDescription$ Copy three sorcery cards chosen at random. You may cast one of the copies without paying its mana cost. Activate this ability only any time you could cast a sorcery. SVar:Picture:https://downloads.cardforge.org/images/cards/VAN/Jhoira of the Ghitu Avatar.full.jpg Oracle:Hand +1, life +0\n{3}, Discard a card: Copy three instant cards chosen at random. You may cast one of the copies without paying its mana cost.\n{3}, Discard a card: Copy three sorcery cards chosen at random. You may cast one of the copies without paying its mana cost. Activate this ability only any time you could cast a sorcery.