From db1839c4029a8c7ce4fe6a01d408cbd69173a394 Mon Sep 17 00:00:00 2001 From: Agetian Date: Mon, 2 Oct 2017 04:50:46 +0000 Subject: [PATCH] - A less invasive Thought Lash hack for the AI. --- .../java/forge/ai/PlayerControllerAi.java | 4 +-- .../java/forge/game/cost/CostPayment.java | 29 ++----------------- 2 files changed, 5 insertions(+), 28 deletions(-) diff --git a/forge-ai/src/main/java/forge/ai/PlayerControllerAi.java b/forge-ai/src/main/java/forge/ai/PlayerControllerAi.java index a422c1f19d8..828dc36a4b5 100644 --- a/forge-ai/src/main/java/forge/ai/PlayerControllerAi.java +++ b/forge-ai/src/main/java/forge/ai/PlayerControllerAi.java @@ -465,8 +465,8 @@ public class PlayerControllerAi extends PlayerController { ability.setActivatingPlayer(c.getController()); // FIXME: This is a hack to check if the AI can play the "exile from library" pay costs (Cumulative Upkeep, - // e.g. Thought Lash). We have to do it early since the cost will later be reconsolidated into a single - // payment for the AI, to avoid cheating (otherwise the AI repeatedly "exiles" the same card multiple times) + // e.g. Thought Lash). We have to do it and bail early if the AI can't pay, because otherwise the AI will + // pay the cost partially, which should not be possible int nExileLib = 0; List parts = CostAdjustment.adjust(cost, sa).getCostParts(); for (final CostPart part : parts) { diff --git a/forge-game/src/main/java/forge/game/cost/CostPayment.java b/forge-game/src/main/java/forge/game/cost/CostPayment.java index 6f66362dbba..9785a12a49b 100644 --- a/forge-game/src/main/java/forge/game/cost/CostPayment.java +++ b/forge-game/src/main/java/forge/game/cost/CostPayment.java @@ -170,38 +170,15 @@ public class CostPayment { final Game game = decisionMaker.getPlayer().getGame(); - // FIXME: This is a hack which is necessary to make the AI pay the Cumulative Upkeep with "Exile a card from - // the top of your library" (Thought Lash) without cheating. Otherwise the AI pays only one card, no matter - // the age counters. We need a better solution here. - int nExileLib = 0; - List partsToChange = Lists.newArrayList(); - CostExile primeExile = null; - for (final CostPart part : parts) { - if (part instanceof CostExile) { - CostExile exile = (CostExile) part; - if (exile.from == ZoneType.Library) { - nExileLib += exile.convertAmount(); - if (nExileLib == 1) { - primeExile = exile; - } else { - partsToChange.add(exile); - } - } - } - } - if (nExileLib > 1 && primeExile != null) { - parts.removeAll(partsToChange); - primeExile.setAmount(String.valueOf(nExileLib)); - } - // - End of hack for Cumulative Upkeep: Exile a card from the top of your library - - for (final CostPart part : parts) { PaymentDecision decision = part.accept(decisionMaker); + // the AI will try to exile the same card repeatedly unless it does it immediately + final boolean payImmediately = part instanceof CostExile && ((CostExile) part).from == ZoneType.Library; if (null == decision) return false; // wrap the payment and push onto the cost stack game.costPaymentStack.push(part, this); - if (decisionMaker.paysRightAfterDecision() && !part.payAsDecided(decisionMaker.getPlayer(), decision, ability)) { + if ((decisionMaker.paysRightAfterDecision() || payImmediately) && !part.payAsDecided(decisionMaker.getPlayer(), decision, ability)) { game.costPaymentStack.pop(); // cost is resolved return false; }