From d5d70cd17da5aa35ebbdbd6221b7f4affe2f02df Mon Sep 17 00:00:00 2001 From: Seravy Date: Tue, 13 Feb 2018 23:23:33 +0100 Subject: [PATCH] When a card that allows "free cast" is in play, do not prefer to discard "unplayable" cards based on CMS, instead discard worst as normal. ...but AI still isn't very eager to actually play them for some reason. --- .../src/main/java/forge/ai/AiController.java | 35 +++++++++++++------ .../main/java/forge/ai/AiCostDecision.java | 14 ++++++++ forge-gui/res/cardsfolder/d/dream_halls.txt | 1 + forge-gui/res/cardsfolder/o/omniscience.txt | 1 + 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/forge-ai/src/main/java/forge/ai/AiController.java b/forge-ai/src/main/java/forge/ai/AiController.java index edab1ee7792..0228faf5a05 100644 --- a/forge-ai/src/main/java/forge/ai/AiController.java +++ b/forge-ai/src/main/java/forge/ai/AiController.java @@ -1046,17 +1046,32 @@ public class AiController { numLandsAvailable++; } - //Discard unplayable card + // Discard unplayable card boolean discardedUnplayable = false; - for (int j = 0; j < validCards.size(); j++) { - if (validCards.get(j).getCMC() > numLandsAvailable && !validCards.get(j).hasSVar("DoNotDiscardIfAble")) { - discardList.add(validCards.get(j)); - validCards.remove(validCards.get(j)); - discardedUnplayable = true; - break; - } else if (validCards.get(j).getCMC() <= numLandsAvailable) { - // cut short to avoid looping over cards which are guaranteed not to fit the criteria - break; + // But check if there is a card in play that allows casting spells for free! + // if yes, nothing is unplayable, at least based on CMC + boolean dreamHalls = false; + for (Card cardInPlay : game.getCardsIn(ZoneType.Battlefield)) { + if (cardInPlay.hasSVar("AllowFreeCast")) { + if ("Everyone".equals((cardInPlay.getSVar("AllowFreeCast")))) { + dreamHalls = true; + } else if (("Owner".equals((cardInPlay.getSVar("AllowFreeCast")))) + && (cardInPlay.getOwner().equals(player))) { + dreamHalls = true; + } + } + } + if (!dreamHalls) { + for (int j = 0; j < validCards.size(); j++) { + if (validCards.get(j).getCMC() > numLandsAvailable && !validCards.get(j).hasSVar("DoNotDiscardIfAble")) { + discardList.add(validCards.get(j)); + validCards.remove(validCards.get(j)); + discardedUnplayable = true; + break; + } else if (validCards.get(j).getCMC() <= numLandsAvailable) { + // cut short to avoid looping over cards which are guaranteed not to fit the criteria + break; + } } } diff --git a/forge-ai/src/main/java/forge/ai/AiCostDecision.java b/forge-ai/src/main/java/forge/ai/AiCostDecision.java index 4c538e5d4d3..68bc9e5f1c8 100644 --- a/forge-ai/src/main/java/forge/ai/AiCostDecision.java +++ b/forge-ai/src/main/java/forge/ai/AiCostDecision.java @@ -65,6 +65,20 @@ public class AiCostDecision extends CostDecisionMakerBase { final String type = cost.getType(); CardCollectionView hand = player.getCardsIn(ZoneType.Hand); +/* // Dream Halls + if (type.equals("Card.SharesColorWith")) { + Card bestfound= null; + for (Card card : hand) { + if ((card.sharesColorWith(source)) + && (!card.equals(source))) { + if (bestfound==null) { bestfound=card; } + if (card.getCMC() | AffectedZone$ Hand,Graveyard,Exile,Library,Command | Description$ Rather than pay the mana cost for a spell, its controller may discard a card that shares a color with that spell. SVar:NonStackingEffect:True AI:RemoveDeck:Random +SVar:AllowFreeCast:Everyone SVar:Picture:http://www.wizards.com/global/images/magic/general/dream_halls.jpg Oracle:Rather than pay the mana cost for a spell, its controller may discard a card that shares a color with that spell. diff --git a/forge-gui/res/cardsfolder/o/omniscience.txt b/forge-gui/res/cardsfolder/o/omniscience.txt index dcbed941b4f..0b308bd636e 100644 --- a/forge-gui/res/cardsfolder/o/omniscience.txt +++ b/forge-gui/res/cardsfolder/o/omniscience.txt @@ -2,6 +2,7 @@ Name:Omniscience ManaCost:7 U U U Types:Enchantment S:Mode$ Continuous | Affected$ Card.nonLand+YouOwn | MayPlay$ True | MayPlayWithoutManaCost$ True | AffectedZone$ Hand | Description$ You may cast spells from your hand without paying their mana costs. +SVar:AllowFreeCast:Owner AI:RemoveDeck:Random SVar:Picture:http://www.wizards.com/global/images/magic/general/omniscience.jpg Oracle:You may cast spells from your hand without paying their mana costs.