From 536dfb5f2da6cbb6da0946fa0d516d2a03b15c26 Mon Sep 17 00:00:00 2001 From: Agetian Date: Sun, 15 Apr 2018 18:29:48 +0300 Subject: [PATCH] - Attempting to improve Haste detection for the AI such that the AI properly casts creatures in main 1 when there's an Avatar or Emblem or something else giving Haste from the command zone, or if the opponent has something on the battlefield that gives Haste to AI's creatures as well (e.g. Mass Hysteria). --- .../src/main/java/forge/ai/ComputerUtil.java | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/forge-ai/src/main/java/forge/ai/ComputerUtil.java b/forge-ai/src/main/java/forge/ai/ComputerUtil.java index 4906e34d6e4..bf4dd6a167b 100644 --- a/forge-ai/src/main/java/forge/ai/ComputerUtil.java +++ b/forge-ai/src/main/java/forge/ai/ComputerUtil.java @@ -951,7 +951,8 @@ public class ComputerUtil { return true; } - if (card.isCreature() && !card.hasKeyword("Defender") && (card.hasKeyword("Haste") || ComputerUtil.hasACardGivingHaste(ai) || sa.isDash())) { + if (card.isCreature() && !card.hasKeyword("Defender") + && (card.hasKeyword("Haste") || ComputerUtil.hasACardGivingHaste(ai, true) || sa.isDash())) { return true; } @@ -1237,9 +1238,9 @@ public class ComputerUtil { return false; } - public static boolean hasACardGivingHaste(final Player ai) { - final CardCollection all = new CardCollection(ai.getCardsIn(ZoneType.Battlefield)); - + public static boolean hasACardGivingHaste(final Player ai, final boolean checkOpponentCards) { + final CardCollection all = new CardCollection(ai.getCardsIn(Lists.newArrayList(ZoneType.Battlefield, ZoneType.Command))); + // Special for Anger if (!ai.getGame().isCardInPlay("Yixlid Jailer") && !ai.getCardsIn(ZoneType.Graveyard, "Anger").isEmpty() @@ -1305,6 +1306,28 @@ public class ComputerUtil { } } } + + if (checkOpponentCards) { + // Check if the opponents have any cards giving Haste to all creatures on the battlefield + CardCollection opp = new CardCollection(); + opp.addAll(ai.getOpponents().getCardsIn(ZoneType.Battlefield)); + opp.addAll(ai.getOpponents().getCardsIn(ZoneType.Command)); + + for (final Card c : opp) { + for (StaticAbility stAb : c.getStaticAbilities()) { + Map params = stAb.getMapParams(); + if ("Continuous".equals(params.get("Mode")) && params.containsKey("AddKeyword") + && params.get("AddKeyword").contains("Haste")) { + + final ArrayList affected = Lists.newArrayList(params.get("Affected").split(",")); + if (affected.contains("Creature")) { + return true; + } + } + } + } + } + return false; }