From 3c652ebf15c7961b6b352696e840f9f49347869b Mon Sep 17 00:00:00 2001 From: Sloth Date: Fri, 20 Jul 2012 16:30:20 +0000 Subject: [PATCH] - Improved AI handling of Exalted (it now uses all the CombatUtil functions). --- .../java/forge/game/phase/CombatUtil.java | 20 +++++++++++++++---- .../forge/game/player/ComputerUtilAttack.java | 17 +++++++--------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/main/java/forge/game/phase/CombatUtil.java b/src/main/java/forge/game/phase/CombatUtil.java index 82da898ddb3..d8c36af7966 100644 --- a/src/main/java/forge/game/phase/CombatUtil.java +++ b/src/main/java/forge/game/phase/CombatUtil.java @@ -1649,6 +1649,12 @@ public class CombatUtil { int power = 0; power += attacker.getKeywordMagnitude("Bushido"); + //check Exalted only for the first attacker + if (combat != null && combat.getAttackers().isEmpty()) { + for (Card card : attacker.getController().getCardsIn(ZoneType.Battlefield)) { + power += card.getKeywordAmount("Exalted"); + } + } final ArrayList theTriggers = new ArrayList(); for (Card card : AllZoneUtil.getCardsIn(ZoneType.Battlefield)) { @@ -1698,7 +1704,7 @@ public class CombatUtil { final HashMap trigParams = trigger.getMapParams(); final Card source = trigger.getHostCard(); - if (!CombatUtil.combatTriggerWillTrigger(attacker, defender, trigger, null) + if (!CombatUtil.combatTriggerWillTrigger(attacker, defender, trigger, combat) || !trigParams.containsKey("Execute")) { continue; } @@ -1757,7 +1763,7 @@ public class CombatUtil { return power; } - // Predict the Toughness bonus of the blocker if blocking the attacker + // Predict the Toughness bonus of the attacker if blocked by the blocker // (Flanking, Bushido and other triggered abilities) /** *

@@ -1775,6 +1781,13 @@ public class CombatUtil { public static int predictToughnessBonusOfAttacker(final Card attacker, final Card defender, final Combat combat) { int toughness = 0; + //check Exalted only for the first attacker + if (combat != null && combat.getAttackers().isEmpty()) { + for (Card card : attacker.getController().getCardsIn(ZoneType.Battlefield)) { + toughness += card.getKeywordAmount("Exalted"); + } + } + final ArrayList theTriggers = new ArrayList(); for (Card card : AllZoneUtil.getCardsIn(ZoneType.Battlefield)) { theTriggers.addAll(card.getTriggers()); @@ -1816,7 +1829,7 @@ public class CombatUtil { final HashMap trigParams = trigger.getMapParams(); final Card source = trigger.getHostCard(); - if (!CombatUtil.combatTriggerWillTrigger(attacker, defender, trigger, null) + if (!CombatUtil.combatTriggerWillTrigger(attacker, defender, trigger, combat) || !trigParams.containsKey("Execute")) { continue; } @@ -1888,7 +1901,6 @@ public class CombatUtil { bonus = bonus.replace("TriggerCount$NumBlockers", "Number$1"); } toughness += CardFactoryUtil.xCount(source, bonus); - } } return toughness; diff --git a/src/main/java/forge/game/player/ComputerUtilAttack.java b/src/main/java/forge/game/player/ComputerUtilAttack.java index 14345308523..623a25b0a16 100644 --- a/src/main/java/forge/game/player/ComputerUtilAttack.java +++ b/src/main/java/forge/game/player/ComputerUtilAttack.java @@ -548,19 +548,15 @@ public class ComputerUtilAttack { } } if (exalted) { - Card att = CardFactoryUtil.getBestCreatureAI(attackersLeft); CardListUtil.sortAttack(this.attackers); + System.out.println("Exalted"); + this.aiAggression = 3; for (Card attacker : this.attackers) { - if (!CombatUtil.canBeBlocked(attacker, this.blockers)) { - att = attacker; - break; + if (CombatUtil.canAttack(attacker, combat) && this.shouldAttack(attacker, this.blockers, combat)) { + combat.addAttacker(attacker); + return combat; } } - if ((att != null) && CombatUtil.canAttack(att, combat)) { - combat.addAttacker(att); - System.out.println("Exalted"); - return combat; - } } } @@ -894,7 +890,8 @@ public class ComputerUtilAttack { && numberOfPossibleBlockers == 1)) { canBeBlocked = true; } - + /*System.out.println(attacker + " canBeKilledByOne: " + canBeKilledByOne + " canKillAll: " + + canKillAll + " isWorthLessThanAllKillers: " + isWorthLessThanAllKillers + " canBeBlocked: " + canBeBlocked);*/ // decide if the creature should attack based on the prevailing strategy // choice in aiAggression switch (this.aiAggression) {