From 1779544d70a3488fbbd6ff5fd7904b0f72aa046f Mon Sep 17 00:00:00 2001 From: Agetian Date: Fri, 1 Sep 2017 05:54:01 +0000 Subject: [PATCH] - Further work on experimental attack/block trade feature (disabled by default). --- forge-ai/src/main/java/forge/ai/AiAttackController.java | 5 ++++- forge-ai/src/main/java/forge/ai/AiBlockController.java | 6 +++--- forge-ai/src/main/java/forge/ai/AiProps.java | 3 ++- forge-gui/res/ai/Cautious.ai | 8 +++++++- forge-gui/res/ai/Default.ai | 8 +++++++- forge-gui/res/ai/Experimental.ai | 8 +++++++- forge-gui/res/ai/Reckless.ai | 8 +++++++- 7 files changed, 37 insertions(+), 9 deletions(-) diff --git a/forge-ai/src/main/java/forge/ai/AiAttackController.java b/forge-ai/src/main/java/forge/ai/AiAttackController.java index 9416c0cfa9f..ccc2df893a6 100644 --- a/forge-ai/src/main/java/forge/ai/AiAttackController.java +++ b/forge-ai/src/main/java/forge/ai/AiAttackController.java @@ -590,10 +590,12 @@ public class AiAttackController { boolean playAggro = false; int chanceToAttackToTrade = 0; + boolean tradeIfTappedOut = false; if (ai.getController().isAI()) { AiController aic = ((PlayerControllerAi) ai.getController()).getAi(); playAggro = aic.getBooleanProperty(AiProps.PLAY_AGGRO); chanceToAttackToTrade = aic.getIntProperty(AiProps.CHANCE_TO_ATTACK_INTO_TRADE); + tradeIfTappedOut = aic.getBooleanProperty(AiProps.ATTACK_INTO_TRADE_WHEN_TAPPED_OUT); } final boolean bAssault = this.doAssault(ai); // TODO: detect Lightmine Field by presence of a card with a specific trigger @@ -921,7 +923,8 @@ public class AiAttackController { } else if (MyRandom.percentTrue(chanceToAttackToTrade) && humanLifeToDamageRatio > 1 && defendingOpponent != null && ComputerUtil.countUsefulCreatures(ai) > ComputerUtil.countUsefulCreatures(defendingOpponent) - && ai.getLife() > defendingOpponent.getLife()) { + && ai.getLife() > defendingOpponent.getLife() + && (ComputerUtilMana.getAvailableManaEstimate(ai) > 0) || tradeIfTappedOut) { this.aiAggression = 4; // random (chance-based) attack expecting to trade or damage player. } else if (ratioDiff >= 0 && this.attackers.size() > 1) { this.aiAggression = 3; // attack expecting to make good trades or damage player. diff --git a/forge-ai/src/main/java/forge/ai/AiBlockController.java b/forge-ai/src/main/java/forge/ai/AiBlockController.java index c11d8a059b8..6721001c35e 100644 --- a/forge-ai/src/main/java/forge/ai/AiBlockController.java +++ b/forge-ai/src/main/java/forge/ai/AiBlockController.java @@ -548,7 +548,7 @@ public class AiBlockController { if (ai.getController().isAI()) { AiController aic = ((PlayerControllerAi) ai.getController()).getAi(); enableRandomTrades = aic.getBooleanProperty(AiProps.ENABLE_RANDOM_FAVORABLE_TRADES_ON_BLOCK); - randomTradeIfBehindOnBoard = aic.getBooleanProperty(AiProps.RANDOMLY_TRADE_EVEN_IF_HAS_LESS_CREATS); + randomTradeIfBehindOnBoard = aic.getBooleanProperty(AiProps.RANDOMLY_TRADE_EVEN_WHEN_HAVE_LESS_CREATS); minRandomTradeChance = aic.getIntProperty(AiProps.MIN_CHANCE_TO_RANDOMLY_TRADE_ON_BLOCK); maxRandomTradeChance = aic.getIntProperty(AiProps.MAX_CHANCE_TO_RANDOMLY_TRADE_ON_BLOCK); } @@ -575,10 +575,10 @@ public class AiBlockController { // Always trade when life in danger doTrade = true; } else if (enableRandomTrades) { - // Randomly trade creatures with lower power and [hopefully] worse abilities + // Randomly trade creatures with lower power and [hopefully] worse abilities, if enabled in profile int numSteps = ai.getStartingLife() - 5; // e.g. 15 steps between 5 life and 20 life float chanceStep = (maxRandomTradeChance - minRandomTradeChance) / numSteps; - int chance = (int)Math.max(minRandomTradeChance, (maxRandomTradeChance - (Math.abs(5 - ai.getLife()) * chanceStep))); + int chance = (int)Math.max(minRandomTradeChance, (maxRandomTradeChance - (Math.max(5, ai.getLife() - 5)) * chanceStep)); if (chance > maxRandomTradeChance) { chance = maxRandomTradeChance; } diff --git a/forge-ai/src/main/java/forge/ai/AiProps.java b/forge-ai/src/main/java/forge/ai/AiProps.java index 6390869e972..ed85ae4b128 100644 --- a/forge-ai/src/main/java/forge/ai/AiProps.java +++ b/forge-ai/src/main/java/forge/ai/AiProps.java @@ -37,8 +37,9 @@ public enum AiProps { /** */ RESERVE_MANA_FOR_MAIN2_CHANCE ("0"), /** */ PLAY_AGGRO ("false"), CHANCE_TO_ATTACK_INTO_TRADE ("100"), /** */ + ATTACK_INTO_TRADE_WHEN_TAPPED_OUT ("false"), /** */ ENABLE_RANDOM_FAVORABLE_TRADES_ON_BLOCK ("false"), /** */ - RANDOMLY_TRADE_EVEN_IF_HAS_LESS_CREATS ("false"), /** */ + RANDOMLY_TRADE_EVEN_WHEN_HAVE_LESS_CREATS ("false"), /** */ MIN_CHANCE_TO_RANDOMLY_TRADE_ON_BLOCK ("20"), /** */ MAX_CHANCE_TO_RANDOMLY_TRADE_ON_BLOCK ("100"), /** */ MIN_SPELL_CMC_TO_COUNTER ("0"), diff --git a/forge-gui/res/ai/Cautious.ai b/forge-gui/res/ai/Cautious.ai index 3328d6cc91a..85bdfc3ae20 100644 --- a/forge-gui/res/ai/Cautious.ai +++ b/forge-gui/res/ai/Cautious.ai @@ -2,10 +2,16 @@ MULLIGAN_THRESHOLD=4 # Aggro preferences (enabling these will generally make the AI attack more aggressively into potential trades) +# If the following option is enabled, the AI will generally play aggressively, seeking trades on offense when possible +# (the following two parameters will then be ignored) PLAY_AGGRO=false # The chance to attack aggressively into a potential trade (works even if not playing all-out aggro, e.g. PLAY_AGGRO disabled, # but only in more favorable conditions in that case - when ahead in life count and in parity or ahead in creature count) CHANCE_TO_ATTACK_INTO_TRADE=0 +# When enabled, the AI will attack into trading options when it's tapped out (note that this flag is ignored if PLAY_AGGRO +# is globally enabled). If disabled, the non-aggro AI will only attack into trades when it has mana open, thus having a chance +# to "bluff" (or use, if available) combat tricks at the same time. +ATTACK_INTO_TRADE_WHEN_TAPPED_OUT=false # When enabled, the AI will use Berserk on offense to try to severely damage the opponent at the expense of the creature USE_BERSERK_AGGRESSIVELY=false @@ -13,7 +19,7 @@ USE_BERSERK_AGGRESSIVELY=false # but only with creatures that are worse in abilities and have lower or the same power as the attacker) ENABLE_RANDOM_FAVORABLE_TRADES_ON_BLOCK=false # If enabled, the AI will consider trade blocking even if its creature count is lower than the opponent's -RANDOMLY_TRADE_EVEN_IF_HAS_LESS_CREATS=false +RANDOMLY_TRADE_EVEN_WHEN_HAVE_LESS_CREATS=false # Min and max chance to randomly aggressively trade when blocking (note that it will become 100 if the AI is in danger) MIN_CHANCE_TO_RANDOMLY_TRADE_ON_BLOCK=20 MAX_CHANCE_TO_RANDOMLY_TRADE_ON_BLOCK=65 diff --git a/forge-gui/res/ai/Default.ai b/forge-gui/res/ai/Default.ai index 40e626fe459..bda634d87be 100644 --- a/forge-gui/res/ai/Default.ai +++ b/forge-gui/res/ai/Default.ai @@ -2,10 +2,16 @@ MULLIGAN_THRESHOLD=4 # Aggro preferences (enabling these will generally make the AI attack more aggressively into potential trades) +# If the following option is enabled, the AI will generally play aggressively, seeking trades on offense when possible +# (the following two parameters will then be ignored) PLAY_AGGRO=false # The chance to attack aggressively into a potential trade (works even if not playing all-out aggro, e.g. PLAY_AGGRO disabled, # but only in more favorable conditions in that case - when ahead in life count and in parity or ahead in creature count) CHANCE_TO_ATTACK_INTO_TRADE=0 +# When enabled, the AI will attack into trading options when it's tapped out (note that this flag is ignored if PLAY_AGGRO +# is globally enabled). If disabled, the non-aggro AI will only attack into trades when it has mana open, thus having a chance +# to "bluff" (or use, if available) combat tricks at the same time. +ATTACK_INTO_TRADE_WHEN_TAPPED_OUT=false # When enabled, the AI will use Berserk on offense to try to severely damage the opponent at the expense of the creature USE_BERSERK_AGGRESSIVELY=false @@ -13,7 +19,7 @@ USE_BERSERK_AGGRESSIVELY=false # but only with creatures that are worse in abilities and have lower or the same power as the attacker) ENABLE_RANDOM_FAVORABLE_TRADES_ON_BLOCK=false # If enabled, the AI will consider trade blocking even if its creature count is lower than the opponent's -RANDOMLY_TRADE_EVEN_IF_HAS_LESS_CREATS=false +RANDOMLY_TRADE_EVEN_WHEN_HAVE_LESS_CREATS=false # Min and max chance to randomly aggressively trade when blocking (note that it will become 100 if the AI is in danger) MIN_CHANCE_TO_RANDOMLY_TRADE_ON_BLOCK=20 MAX_CHANCE_TO_RANDOMLY_TRADE_ON_BLOCK=65 diff --git a/forge-gui/res/ai/Experimental.ai b/forge-gui/res/ai/Experimental.ai index e8ce0e82656..d949c50bd89 100644 --- a/forge-gui/res/ai/Experimental.ai +++ b/forge-gui/res/ai/Experimental.ai @@ -2,10 +2,16 @@ MULLIGAN_THRESHOLD=4 # Aggro preferences (enabling these will generally make the AI attack more aggressively into potential trades) +# If the following option is enabled, the AI will generally play aggressively, seeking trades on offense when possible +# (the following two parameters will then be ignored) PLAY_AGGRO=false # The chance to attack aggressively into a potential trade (works even if not playing all-out aggro, e.g. PLAY_AGGRO disabled, # but only in more favorable conditions in that case - when ahead in life count and in parity or ahead in creature count) CHANCE_TO_ATTACK_INTO_TRADE=20 +# When enabled, the AI will attack into trading options when it's tapped out (note that this flag is ignored if PLAY_AGGRO +# is globally enabled). If disabled, the non-aggro AI will only attack into trades when it has mana open, thus having a chance +# to "bluff" (or use, if available) combat tricks at the same time. +ATTACK_INTO_TRADE_WHEN_TAPPED_OUT=false # When enabled, the AI will use Berserk on offense to try to severely damage the opponent at the expense of the creature USE_BERSERK_AGGRESSIVELY=true @@ -13,7 +19,7 @@ USE_BERSERK_AGGRESSIVELY=true # but only with creatures that are worse in abilities and have lower or the same power as the attacker) ENABLE_RANDOM_FAVORABLE_TRADES_ON_BLOCK=true # If enabled, the AI will consider trade blocking even if its creature count is lower than the opponent's -RANDOMLY_TRADE_EVEN_IF_HAS_LESS_CREATS=true +RANDOMLY_TRADE_EVEN_WHEN_HAVE_LESS_CREATS=true # Min and max chance to randomly aggressively trade when blocking (note that it will become 100 if the AI is in danger) MIN_CHANCE_TO_RANDOMLY_TRADE_ON_BLOCK=20 MAX_CHANCE_TO_RANDOMLY_TRADE_ON_BLOCK=65 diff --git a/forge-gui/res/ai/Reckless.ai b/forge-gui/res/ai/Reckless.ai index 0ca90168f21..68367598582 100644 --- a/forge-gui/res/ai/Reckless.ai +++ b/forge-gui/res/ai/Reckless.ai @@ -2,10 +2,16 @@ MULLIGAN_THRESHOLD=3 # Aggro preferences (enabling these will generally make the AI attack more aggressively) +# If the following option is enabled, the AI will generally play aggressively, seeking trades on offense when possible +# (the following two parameters will then be ignored) PLAY_AGGRO=true # The chance to attack aggressively into a potential trade (works even if not playing all-out aggro, e.g. PLAY_AGGRO disabled, # but only in more favorable conditions in that case - when ahead in life count and in parity or ahead in creature count) CHANCE_TO_ATTACK_INTO_TRADE=100 +# When enabled, the AI will attack into trading options when it's tapped out (note that this flag is ignored if PLAY_AGGRO +# is globally enabled). If disabled, the non-aggro AI will only attack into trades when it has mana open, thus having a chance +# to "bluff" (or use, if available) combat tricks at the same time. +ATTACK_INTO_TRADE_WHEN_TAPPED_OUT=true # When enabled, the AI will use Berserk on offense to try to severely damage the opponent at the expense of the creature USE_BERSERK_AGGRESSIVELY=true @@ -13,7 +19,7 @@ USE_BERSERK_AGGRESSIVELY=true # but only with creatures that are worse in abilities and have lower or the same power as the attacker) ENABLE_RANDOM_FAVORABLE_TRADES_ON_BLOCK=false # If enabled, the AI will consider trade blocking even if its creature count is lower than the opponent's -RANDOMLY_TRADE_EVEN_IF_HAS_LESS_CREATS=false +RANDOMLY_TRADE_EVEN_WHEN_HAVE_LESS_CREATS=false # Min and max chance to randomly aggressively trade when blocking (note that it will become 100 if the AI is in danger) MIN_CHANCE_TO_RANDOMLY_TRADE_ON_BLOCK=20 MAX_CHANCE_TO_RANDOMLY_TRADE_ON_BLOCK=65