From a1461851eeddb401c9b7001b7cdcf13f37f9ea30 Mon Sep 17 00:00:00 2001 From: Agetian Date: Fri, 1 Sep 2017 03:19:24 +0000 Subject: [PATCH] - Some further work on the experimental attack/block trading options (disabled by default in all profiles except Experimental). --- forge-ai/src/main/java/forge/ai/AiAttackController.java | 6 ++++-- forge-ai/src/main/java/forge/ai/AiBlockController.java | 7 ++++--- forge-gui/res/ai/Cautious.ai | 7 ++++--- forge-gui/res/ai/Default.ai | 7 ++++--- forge-gui/res/ai/Experimental.ai | 7 ++++--- forge-gui/res/ai/Reckless.ai | 7 ++++--- 6 files changed, 24 insertions(+), 17 deletions(-) diff --git a/forge-ai/src/main/java/forge/ai/AiAttackController.java b/forge-ai/src/main/java/forge/ai/AiAttackController.java index d725abae188..9416c0cfa9f 100644 --- a/forge-ai/src/main/java/forge/ai/AiAttackController.java +++ b/forge-ai/src/main/java/forge/ai/AiAttackController.java @@ -916,10 +916,12 @@ public class AiAttackController { if (ratioDiff > 0 && doAttritionalAttack) { this.aiAggression = 5; // attack at all costs } else if ((ratioDiff >= 1 && this.attackers.size() > 1 && (humanLifeToDamageRatio < 2 || outNumber > 0)) - || (playAggro && humanLifeToDamageRatio > 1)) { + || (playAggro && MyRandom.percentTrue(chanceToAttackToTrade) && humanLifeToDamageRatio > 1)) { this.aiAggression = 4; // attack expecting to trade or damage player. } else if (MyRandom.percentTrue(chanceToAttackToTrade) && humanLifeToDamageRatio > 1 - && ComputerUtil.countUsefulCreatures(ai) > ComputerUtil.countUsefulCreatures(defendingOpponent)) { + && defendingOpponent != null + && ComputerUtil.countUsefulCreatures(ai) > ComputerUtil.countUsefulCreatures(defendingOpponent) + && ai.getLife() > defendingOpponent.getLife()) { 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 3c40109f0f1..9aadbdccc16 100644 --- a/forge-ai/src/main/java/forge/ai/AiBlockController.java +++ b/forge-ai/src/main/java/forge/ai/AiBlockController.java @@ -575,9 +575,10 @@ public class AiBlockController { // Always trade when life in danger doTrade = true; } else if (enableRandomTrades) { - // Randomly trade creatures with lower power and worse abilities - float chanceStep = (100 - minRandomTradeChance) / 15; // 15 steps between 5 life and 20+ life - int chance = (int)Math.max(minRandomTradeChance, (100 - (Math.abs(5 - ai.getLife()) * chanceStep))); + // Randomly trade creatures with lower power and [hopefully] worse abilities + 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))); if (chance > maxRandomTradeChance) { chance = maxRandomTradeChance; } diff --git a/forge-gui/res/ai/Cautious.ai b/forge-gui/res/ai/Cautious.ai index 22993d2ae82..3328d6cc91a 100644 --- a/forge-gui/res/ai/Cautious.ai +++ b/forge-gui/res/ai/Cautious.ai @@ -3,7 +3,8 @@ MULLIGAN_THRESHOLD=4 # Aggro preferences (enabling these will generally make the AI attack more aggressively into potential trades) PLAY_AGGRO=false -# The chance to attack aggressively into a potential trade even if not playing all-out aggro (PLAY_AGGRO disabled) +# 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 use Berserk on offense to try to severely damage the opponent at the expense of the creature USE_BERSERK_AGGRESSIVELY=false @@ -13,9 +14,9 @@ USE_BERSERK_AGGRESSIVELY=false 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 -# Min and max chance to randomly aggressively trade when blocking +# 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=100 +MAX_CHANCE_TO_RANDOMLY_TRADE_ON_BLOCK=65 # Only works when AI cheating is enabled in preferences, otherwise does nothing CHEAT_WITH_MANA_ON_SHUFFLE=true diff --git a/forge-gui/res/ai/Default.ai b/forge-gui/res/ai/Default.ai index 18d41e6caf7..40e626fe459 100644 --- a/forge-gui/res/ai/Default.ai +++ b/forge-gui/res/ai/Default.ai @@ -3,7 +3,8 @@ MULLIGAN_THRESHOLD=4 # Aggro preferences (enabling these will generally make the AI attack more aggressively into potential trades) PLAY_AGGRO=false -# The chance to attack aggressively into a potential trade even if not playing all-out aggro (PLAY_AGGRO disabled) +# 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 use Berserk on offense to try to severely damage the opponent at the expense of the creature USE_BERSERK_AGGRESSIVELY=false @@ -13,9 +14,9 @@ USE_BERSERK_AGGRESSIVELY=false 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 -# Min and max chance to randomly aggressively trade when blocking +# 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=100 +MAX_CHANCE_TO_RANDOMLY_TRADE_ON_BLOCK=65 # Only works when AI cheating is enabled in preferences, otherwise does nothing CHEAT_WITH_MANA_ON_SHUFFLE=true diff --git a/forge-gui/res/ai/Experimental.ai b/forge-gui/res/ai/Experimental.ai index 354926ded04..e8ce0e82656 100644 --- a/forge-gui/res/ai/Experimental.ai +++ b/forge-gui/res/ai/Experimental.ai @@ -3,7 +3,8 @@ MULLIGAN_THRESHOLD=4 # Aggro preferences (enabling these will generally make the AI attack more aggressively into potential trades) PLAY_AGGRO=false -# The chance to attack aggressively into a potential trade even if not playing all-out aggro (PLAY_AGGRO disabled) +# 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 use Berserk on offense to try to severely damage the opponent at the expense of the creature USE_BERSERK_AGGRESSIVELY=true @@ -13,9 +14,9 @@ USE_BERSERK_AGGRESSIVELY=true 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 -# Min and max chance to randomly aggressively trade when blocking +# 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=100 +MAX_CHANCE_TO_RANDOMLY_TRADE_ON_BLOCK=65 # Only works when AI cheating is enabled in preferences, otherwise does nothing CHEAT_WITH_MANA_ON_SHUFFLE=true diff --git a/forge-gui/res/ai/Reckless.ai b/forge-gui/res/ai/Reckless.ai index 0d8309b7e01..0ca90168f21 100644 --- a/forge-gui/res/ai/Reckless.ai +++ b/forge-gui/res/ai/Reckless.ai @@ -3,7 +3,8 @@ MULLIGAN_THRESHOLD=3 # Aggro preferences (enabling these will generally make the AI attack more aggressively) PLAY_AGGRO=true -# The chance to attack aggressively into a potential trade even if not playing all-out aggro (PLAY_AGGRO disabled) +# 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 use Berserk on offense to try to severely damage the opponent at the expense of the creature USE_BERSERK_AGGRESSIVELY=true @@ -13,9 +14,9 @@ USE_BERSERK_AGGRESSIVELY=true 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 -# Min and max chance to randomly aggressively trade when blocking +# 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=100 +MAX_CHANCE_TO_RANDOMLY_TRADE_ON_BLOCK=65 # Only works when AI cheating is enabled in preferences, otherwise does nothing CHEAT_WITH_MANA_ON_SHUFFLE=true