From baf0af3a24fb0c774be5c0f8d9a56c993ef88b03 Mon Sep 17 00:00:00 2001 From: Sloth Date: Sun, 26 Oct 2014 15:24:42 +0000 Subject: [PATCH] - Added the new AI function "hasAFogEffect". --- .../main/java/forge/ai/AiBlockController.java | 122 +++++++++--------- .../src/main/java/forge/ai/ComputerUtil.java | 20 +++ 2 files changed, 83 insertions(+), 59 deletions(-) diff --git a/forge-ai/src/main/java/forge/ai/AiBlockController.java b/forge-ai/src/main/java/forge/ai/AiBlockController.java index 6af962516ee..f8e008bfaf9 100644 --- a/forge-ai/src/main/java/forge/ai/AiBlockController.java +++ b/forge-ai/src/main/java/forge/ai/AiBlockController.java @@ -754,65 +754,69 @@ public class AiBlockController { // == 1. choose best blocks first == makeGoodBlocks(combat); makeGangBlocks(combat); - if (ComputerUtilCombat.lifeInDanger(ai, combat)) { - makeTradeBlocks(combat); // choose necessary trade blocks - } - // if life is in danger - if (ComputerUtilCombat.lifeInDanger(ai, combat)) { - makeChumpBlocks(combat); // choose necessary chump blocks - } - // if life is still in danger - // Reinforce blockers blocking attackers with trample if life is still - // in danger - if (ComputerUtilCombat.lifeInDanger(ai, combat)) { - reinforceBlockersAgainstTrample(combat); - } - // Support blockers not destroying the attacker with more blockers to - // try to kill the attacker - if (!ComputerUtilCombat.lifeInDanger(ai, combat)) { - reinforceBlockersToKill(combat); - } - - // == 2. If the AI life would still be in danger make a safer approach == - if (ComputerUtilCombat.lifeInDanger(ai, combat)) { - lifeInDanger = true; - clearBlockers(combat, possibleBlockers); // reset every block assignment - makeTradeBlocks(combat); // choose necessary trade blocks - // if life is in danger - makeGoodBlocks(combat); - // choose necessary chump blocks if life is still in danger - if (ComputerUtilCombat.lifeInDanger(ai, combat)) { - makeChumpBlocks(combat); - } - // Reinforce blockers blocking attackers with trample if life is - // still in danger - if (ComputerUtilCombat.lifeInDanger(ai, combat)) { - reinforceBlockersAgainstTrample(combat); - } - makeGangBlocks(combat); - reinforceBlockersToKill(combat); - } - - // == 3. If the AI life would be in serious danger make an even safer approach == - if (lifeInDanger && ComputerUtilCombat.lifeInSeriousDanger(ai, combat)) { - clearBlockers(combat, possibleBlockers); // reset every block assignment - makeChumpBlocks(combat); // choose chump blocks - if (ComputerUtilCombat.lifeInDanger(ai, combat)) { - makeTradeBlocks(combat); // choose necessary trade - } - - if (!ComputerUtilCombat.lifeInDanger(ai, combat)) { - makeGoodBlocks(combat); - } - // Reinforce blockers blocking attackers with trample if life is - // still in danger - else { - reinforceBlockersAgainstTrample(combat); - } - makeGangBlocks(combat); - // Support blockers not destroying the attacker with more blockers - // to try to kill the attacker - reinforceBlockersToKill(combat); + + // When the AI holds some Fog effect, don't bother about lifeInDanger + if (!ComputerUtil.hasAFogEffect(ai)) { + if (ComputerUtilCombat.lifeInDanger(ai, combat)) { + makeTradeBlocks(combat); // choose necessary trade blocks + } + // if life is in danger + if (ComputerUtilCombat.lifeInDanger(ai, combat)) { + makeChumpBlocks(combat); // choose necessary chump blocks + } + // if life is still in danger + // Reinforce blockers blocking attackers with trample if life is still + // in danger + if (ComputerUtilCombat.lifeInDanger(ai, combat)) { + reinforceBlockersAgainstTrample(combat); + } + // Support blockers not destroying the attacker with more blockers to + // try to kill the attacker + if (!ComputerUtilCombat.lifeInDanger(ai, combat)) { + reinforceBlockersToKill(combat); + } + + // == 2. If the AI life would still be in danger make a safer approach == + if (ComputerUtilCombat.lifeInDanger(ai, combat)) { + lifeInDanger = true; + clearBlockers(combat, possibleBlockers); // reset every block assignment + makeTradeBlocks(combat); // choose necessary trade blocks + // if life is in danger + makeGoodBlocks(combat); + // choose necessary chump blocks if life is still in danger + if (ComputerUtilCombat.lifeInDanger(ai, combat)) { + makeChumpBlocks(combat); + } + // Reinforce blockers blocking attackers with trample if life is + // still in danger + if (ComputerUtilCombat.lifeInDanger(ai, combat)) { + reinforceBlockersAgainstTrample(combat); + } + makeGangBlocks(combat); + reinforceBlockersToKill(combat); + } + + // == 3. If the AI life would be in serious danger make an even safer approach == + if (lifeInDanger && ComputerUtilCombat.lifeInSeriousDanger(ai, combat)) { + clearBlockers(combat, possibleBlockers); // reset every block assignment + makeChumpBlocks(combat); // choose chump blocks + if (ComputerUtilCombat.lifeInDanger(ai, combat)) { + makeTradeBlocks(combat); // choose necessary trade + } + + if (!ComputerUtilCombat.lifeInDanger(ai, combat)) { + makeGoodBlocks(combat); + } + // Reinforce blockers blocking attackers with trample if life is + // still in danger + else { + reinforceBlockersAgainstTrample(combat); + } + makeGangBlocks(combat); + // Support blockers not destroying the attacker with more blockers + // to try to kill the attacker + reinforceBlockersToKill(combat); + } } // assign blockers that have to block diff --git a/forge-ai/src/main/java/forge/ai/ComputerUtil.java b/forge-ai/src/main/java/forge/ai/ComputerUtil.java index 887cc915cfb..952e5702c07 100644 --- a/forge-ai/src/main/java/forge/ai/ComputerUtil.java +++ b/forge-ai/src/main/java/forge/ai/ComputerUtil.java @@ -999,6 +999,26 @@ public class ComputerUtil { return false; } + public static boolean hasAFogEffect(final Player ai) { + final CardCollection all = new CardCollection(ai.getCardsIn(ZoneType.Battlefield)); + + all.addAll(ai.getCardsActivableInExternalZones(true)); + all.addAll(ai.getCardsIn(ZoneType.Hand)); + + for (final Card c : all) { + for (final SpellAbility sa : c.getSpellAbilities()) { + if (sa.getApi() != ApiType.Fog) { + continue; + } + if (!ComputerUtilCost.canPayCost(sa, ai)) { + continue; + } + return true; + } + } + return false; + } + public static int possibleNonCombatDamage(Player ai) { int damage = 0; final CardCollection all = new CardCollection(ai.getCardsIn(ZoneType.Battlefield));