From 56a1c70bc518ab4b2ad4074023499c99a1426fa6 Mon Sep 17 00:00:00 2001 From: Sloth Date: Tue, 21 Jul 2015 11:59:53 +0000 Subject: [PATCH] - Improvements in AiBlockController. --- .../main/java/forge/ai/AiBlockController.java | 54 +++++++++++-------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/forge-ai/src/main/java/forge/ai/AiBlockController.java b/forge-ai/src/main/java/forge/ai/AiBlockController.java index 5cc21d60f48..324f17c68ea 100644 --- a/forge-ai/src/main/java/forge/ai/AiBlockController.java +++ b/forge-ai/src/main/java/forge/ai/AiBlockController.java @@ -622,18 +622,20 @@ public class AiBlockController { blockers.removeAll(combat.getBlockers(attacker)); // Try to use safe blockers first - safeBlockers = getSafeBlockers(combat, attacker, blockers); - for (final Card blocker : safeBlockers) { - final int damageNeeded = ComputerUtilCombat.getDamageToKill(attacker) - + ComputerUtilCombat.predictToughnessBonusOfAttacker(attacker, blocker, combat, false); - // Add an additional blocker if the current blockers are not - // enough and the new one would deal additional damage - if (damageNeeded > ComputerUtilCombat.totalDamageOfBlockers(attacker, combat.getBlockers(attacker)) - && ComputerUtilCombat.dealsDamageAsBlocker(attacker, blocker) > 0 - && CombatUtil.canBlock(attacker, blocker, combat)) { - combat.addBlocker(attacker, blocker); - } - blockers.remove(blocker); // Don't check them again next + if (blockers.size() > 1) { + safeBlockers = getSafeBlockers(combat, attacker, blockers); + for (final Card blocker : safeBlockers) { + final int damageNeeded = ComputerUtilCombat.getDamageToKill(attacker) + + ComputerUtilCombat.predictToughnessBonusOfAttacker(attacker, blocker, combat, false); + // Add an additional blocker if the current blockers are not + // enough and the new one would deal additional damage + if (damageNeeded > ComputerUtilCombat.totalDamageOfBlockers(attacker, combat.getBlockers(attacker)) + && ComputerUtilCombat.dealsDamageAsBlocker(attacker, blocker) > 0 + && CombatUtil.canBlock(attacker, blocker, combat)) { + combat.addBlocker(attacker, blocker); + } + blockers.remove(blocker); // Don't check them again next + } } // Try to add blockers that could be destroyed, but are worth less than the attacker @@ -755,28 +757,32 @@ public class AiBlockController { // When the AI holds some Fog effect, don't bother about lifeInDanger if (!ComputerUtil.hasAFogEffect(ai)) { - if (ComputerUtilCombat.lifeInDanger(ai, combat)) { + lifeInDanger = ComputerUtilCombat.lifeInDanger(ai, combat); + if (lifeInDanger) { makeTradeBlocks(combat); // choose necessary trade blocks } - // if life is in danger - if (ComputerUtilCombat.lifeInDanger(ai, combat)) { + // if life is still in danger + if (lifeInDanger && ComputerUtilCombat.lifeInDanger(ai, combat)) { makeChumpBlocks(combat); // choose necessary chump blocks - } + } else { + lifeInDanger = false; + } // if life is still in danger // Reinforce blockers blocking attackers with trample if life is still // in danger - if (ComputerUtilCombat.lifeInDanger(ai, combat)) { + if (lifeInDanger && ComputerUtilCombat.lifeInDanger(ai, combat)) { reinforceBlockersAgainstTrample(combat); - } + } else { + lifeInDanger = false; + } // Support blockers not destroying the attacker with more blockers to // try to kill the attacker - if (!ComputerUtilCombat.lifeInDanger(ai, combat)) { + if (!lifeInDanger) { reinforceBlockersToKill(combat); } // == 2. If the AI life would still be in danger make a safer approach == - if (ComputerUtilCombat.lifeInDanger(ai, combat)) { - lifeInDanger = true; + if (lifeInDanger && ComputerUtilCombat.lifeInDanger(ai, combat)) { clearBlockers(combat, possibleBlockers); // reset every block assignment makeTradeBlocks(combat); // choose necessary trade blocks // if life is in danger @@ -784,11 +790,15 @@ public class AiBlockController { // choose necessary chump blocks if life is still in danger if (ComputerUtilCombat.lifeInDanger(ai, combat)) { makeChumpBlocks(combat); + } else { + lifeInDanger = false; } // Reinforce blockers blocking attackers with trample if life is // still in danger - if (ComputerUtilCombat.lifeInDanger(ai, combat)) { + if (lifeInDanger && ComputerUtilCombat.lifeInDanger(ai, combat)) { reinforceBlockersAgainstTrample(combat); + } else { + lifeInDanger = false; } makeGangBlocks(combat); reinforceBlockersToKill(combat);