From 1e6467cf804d7cc03ee7839e1c3075895f86ec24 Mon Sep 17 00:00:00 2001 From: Agetian Date: Mon, 21 Aug 2017 17:29:57 +0000 Subject: [PATCH] - Experimental: attempting to improve the AI choice for attrition attack when predicting possible opponent's forces with evasion (e.g. Flying). Currently enabled only for the Experimental AI profile for the testing period. --- .../java/forge/ai/AiAttackController.java | 22 ++++++++++++++++++- forge-ai/src/main/java/forge/ai/AiProps.java | 3 ++- forge-gui/res/ai/Cautious.ai | 3 +++ forge-gui/res/ai/Default.ai | 3 +++ forge-gui/res/ai/Experimental.ai | 3 +++ forge-gui/res/ai/Reckless.ai | 3 +++ 6 files changed, 35 insertions(+), 2 deletions(-) diff --git a/forge-ai/src/main/java/forge/ai/AiAttackController.java b/forge-ai/src/main/java/forge/ai/AiAttackController.java index 6c471c4287a..1a1a947ae5e 100644 --- a/forge-ai/src/main/java/forge/ai/AiAttackController.java +++ b/forge-ai/src/main/java/forge/ai/AiAttackController.java @@ -243,6 +243,19 @@ public class AiAttackController { return false; } + public final static Card getCardCanBlockAnAttacker(final Card c, final List attackers, final boolean nextTurn) { + final List attackerList = new ArrayList(attackers); + if (!c.isCreature()) { + return null; + } + for (final Card attacker : attackerList) { + if (CombatUtil.canBlock(attacker, c, nextTurn)) { + return attacker; + } + } + return null; + } + // this checks to make sure that the computer player doesn't lose when the human player attacks // this method is used by getAttackers() public final List notNeededAsBlockers(final Player ai, final List attackers) { @@ -734,8 +747,15 @@ public class AiAttackController { humanForces += 1; // player forces they might use to attack } // increment player forces that are relevant to an attritional attack - includes walls - if (canBlockAnAttacker(pCard, candidateAttackers, true)) { + + boolean predictEvasion = (ai.getController().isAI() + && ((PlayerControllerAi)ai.getController()).getAi().getBooleanProperty(AiProps.COMBAT_ATTRITION_ATTACK_EVASION_PREDICTION)); + Card potentialOppBlocker = getCardCanBlockAnAttacker(pCard, candidateAttackers, true); + if (potentialOppBlocker != null) { humanForcesForAttritionalAttack += 1; + if (predictEvasion) { + candidateAttackers.remove(potentialOppBlocker); + } } } diff --git a/forge-ai/src/main/java/forge/ai/AiProps.java b/forge-ai/src/main/java/forge/ai/AiProps.java index fca64f1dc79..892b4816fa4 100644 --- a/forge-ai/src/main/java/forge/ai/AiProps.java +++ b/forge-ai/src/main/java/forge/ai/AiProps.java @@ -54,7 +54,8 @@ public enum AiProps { /** */ TOKEN_GENERATION_ABILITY_CHANCE ("100"), /** */ TOKEN_GENERATION_ALWAYS_IF_FROM_PLANESWALKER ("true"), /** */ TOKEN_GENERATION_ALWAYS_IF_OPP_ATTACKS ("true"), - COMBAT_ASSAULT_ATTACK_EVASION_PREDICTION ("false"); /** */ + COMBAT_ASSAULT_ATTACK_EVASION_PREDICTION ("true"), /** */ + COMBAT_ATTRITION_ATTACK_EVASION_PREDICTION ("true"); /** */ private final String strDefaultVal; diff --git a/forge-gui/res/ai/Cautious.ai b/forge-gui/res/ai/Cautious.ai index 89edfcebe43..5191281376f 100644 --- a/forge-gui/res/ai/Cautious.ai +++ b/forge-gui/res/ai/Cautious.ai @@ -55,3 +55,6 @@ TOKEN_GENERATION_ALWAYS_IF_OPP_ATTACKS=true # Attempt to predict the number of potential blockers with various forms of evasion when # deciding to do an all-in assault attack (Experimental!) COMBAT_ASSAULT_ATTACK_EVASION_PREDICTION=false +# Attempt to predict the number of potential blockers with various forms of evasion when +# deciding to do an attrition race attack (Experimental!) +COMBAT_ATTRITION_ATTACK_EVASION_PREDICTION=false diff --git a/forge-gui/res/ai/Default.ai b/forge-gui/res/ai/Default.ai index 99f52872e9e..26d7ee56bdf 100644 --- a/forge-gui/res/ai/Default.ai +++ b/forge-gui/res/ai/Default.ai @@ -55,3 +55,6 @@ TOKEN_GENERATION_ALWAYS_IF_OPP_ATTACKS=true # Attempt to predict the number of potential blockers with various forms of evasion when # deciding to do an all-in assault attack (Experimental!) COMBAT_ASSAULT_ATTACK_EVASION_PREDICTION=false +# Attempt to predict the number of potential blockers with various forms of evasion when +# deciding to do an attrition race attack (Experimental!) +COMBAT_ATTRITION_ATTACK_EVASION_PREDICTION=false diff --git a/forge-gui/res/ai/Experimental.ai b/forge-gui/res/ai/Experimental.ai index 4a99fdf3134..41b6efb22a6 100644 --- a/forge-gui/res/ai/Experimental.ai +++ b/forge-gui/res/ai/Experimental.ai @@ -55,3 +55,6 @@ TOKEN_GENERATION_ALWAYS_IF_OPP_ATTACKS=true # Attempt to predict the number of potential blockers with various forms of evasion when # deciding to do an all-in assault attack (Experimental!) COMBAT_ASSAULT_ATTACK_EVASION_PREDICTION=true +# Attempt to predict the number of potential blockers with various forms of evasion when +# deciding to do an attrition race attack (Experimental!) +COMBAT_ATTRITION_ATTACK_EVASION_PREDICTION=true diff --git a/forge-gui/res/ai/Reckless.ai b/forge-gui/res/ai/Reckless.ai index d339e65ef31..a7fdc42374c 100644 --- a/forge-gui/res/ai/Reckless.ai +++ b/forge-gui/res/ai/Reckless.ai @@ -55,3 +55,6 @@ TOKEN_GENERATION_ALWAYS_IF_OPP_ATTACKS=true # Attempt to predict the number of potential blockers with various forms of evasion when # deciding to do an all-in assault attack (Experimental!) COMBAT_ASSAULT_ATTACK_EVASION_PREDICTION=false +# Attempt to predict the number of potential blockers with various forms of evasion when +# deciding to do an attrition race attack (Experimental!) +COMBAT_ATTRITION_ATTACK_EVASION_PREDICTION=false