From badf68b80adebfc6aaab2f6b24d2381d4cbac86b Mon Sep 17 00:00:00 2001 From: Agetian Date: Fri, 1 Sep 2017 14:53:44 +0000 Subject: [PATCH] - Further work on random trades (experimental, disabled by default.) --- .../main/java/forge/ai/AiBlockController.java | 21 ++++++++++++++++--- forge-ai/src/main/java/forge/ai/AiProps.java | 1 + forge-gui/res/ai/Cautious.ai | 6 +++++- forge-gui/res/ai/Default.ai | 6 +++++- forge-gui/res/ai/Experimental.ai | 6 +++++- forge-gui/res/ai/Reckless.ai | 6 +++++- 6 files changed, 39 insertions(+), 7 deletions(-) diff --git a/forge-ai/src/main/java/forge/ai/AiBlockController.java b/forge-ai/src/main/java/forge/ai/AiBlockController.java index 57026c8498d..26eec34f37b 100644 --- a/forge-ai/src/main/java/forge/ai/AiBlockController.java +++ b/forge-ai/src/main/java/forge/ai/AiBlockController.java @@ -545,12 +545,27 @@ public class AiBlockController { boolean randomTradeIfBehindOnBoard = false; int minRandomTradeChance = 0; int maxRandomTradeChance = 0; + int maxCreatDiff = 0; + int aiCreatureCount = 0; + int oppCreatureCount = 0; 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_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); + maxCreatDiff = aic.getIntProperty(AiProps.MAX_DIFF_IN_CREATURE_COUNT_TO_TRADE); + } + + if (enableRandomTrades) { + aiCreatureCount = ComputerUtil.countUsefulCreatures(ai); + if (randomTradeIfBehindOnBoard) { + aiCreatureCount += maxCreatDiff; + } + + if (!attackersLeft.isEmpty()) { + oppCreatureCount = ComputerUtil.countUsefulCreatures(attackersLeft.get(0).getController()); + } } for (final Card attacker : attackersLeft) { @@ -586,11 +601,11 @@ public class AiBlockController { int evalAtk = ComputerUtilCard.evaluateCreature(attacker, false, false); int evalBlk = ComputerUtilCard.evaluateCreature(blocker, false, false); boolean powerParityOrHigher = blocker.getNetPower() >= attacker.getNetPower(); - boolean creatureParityOrHigher = ComputerUtil.countUsefulCreatures(ai) >= ComputerUtil.countUsefulCreatures(attacker.getController()); + boolean creatureParityOrAllowedDiff = aiCreatureCount >= oppCreatureCount; - if (evalBlk <= evalAtk + if (evalBlk <= evalAtk + 1 // "1" accounts for tapped. Maybe increase to 3 or 5 for higher tolerance? && powerParityOrHigher - && (creatureParityOrHigher || randomTradeIfBehindOnBoard) + && creatureParityOrAllowedDiff && MyRandom.percentTrue(chance)) { doTrade = true; } diff --git a/forge-ai/src/main/java/forge/ai/AiProps.java b/forge-ai/src/main/java/forge/ai/AiProps.java index ed85ae4b128..0997a363a75 100644 --- a/forge-ai/src/main/java/forge/ai/AiProps.java +++ b/forge-ai/src/main/java/forge/ai/AiProps.java @@ -40,6 +40,7 @@ public enum AiProps { /** */ ATTACK_INTO_TRADE_WHEN_TAPPED_OUT ("false"), /** */ ENABLE_RANDOM_FAVORABLE_TRADES_ON_BLOCK ("false"), /** */ RANDOMLY_TRADE_EVEN_WHEN_HAVE_LESS_CREATS ("false"), /** */ + MAX_DIFF_IN_CREATURE_COUNT_TO_TRADE ("1"), /** */ 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 85bdfc3ae20..1384f88b75d 100644 --- a/forge-gui/res/ai/Cautious.ai +++ b/forge-gui/res/ai/Cautious.ai @@ -16,10 +16,14 @@ ATTACK_INTO_TRADE_WHEN_TAPPED_OUT=false USE_BERSERK_AGGRESSIVELY=false # Trade blocking preferences (enabling these will make the AI trade more aggressively when considering blocks, -# but only with creatures that are worse in abilities and have lower or the same power as the attacker) +# but only with creatures that are worse in abilities and have lower or the same power as the attacker). Note +# that the first option serves as a master toggle. If it is disabled, the following related options have no effect. 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_WHEN_HAVE_LESS_CREATS=false +# If the previous option is enabled, then the next option controls how big of a handicap in creature count the AI +# is allowed to have to still decide to trade +MAX_DIFF_IN_CREATURE_COUNT_TO_TRADE=1 # 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 bda634d87be..f1dabad6a4d 100644 --- a/forge-gui/res/ai/Default.ai +++ b/forge-gui/res/ai/Default.ai @@ -16,10 +16,14 @@ ATTACK_INTO_TRADE_WHEN_TAPPED_OUT=false USE_BERSERK_AGGRESSIVELY=false # Trade blocking preferences (enabling these will make the AI trade more aggressively when considering blocks, -# but only with creatures that are worse in abilities and have lower or the same power as the attacker) +# but only with creatures that are worse in abilities and have lower or the same power as the attacker). Note +# that the first option serves as a master toggle. If it is disabled, the following related options have no effect. 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_WHEN_HAVE_LESS_CREATS=false +# If the previous option is enabled, then the next option controls how big of a handicap in creature count the AI +# is allowed to have to still decide to trade +MAX_DIFF_IN_CREATURE_COUNT_TO_TRADE=1 # 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 d949c50bd89..791dd01ce92 100644 --- a/forge-gui/res/ai/Experimental.ai +++ b/forge-gui/res/ai/Experimental.ai @@ -16,10 +16,14 @@ ATTACK_INTO_TRADE_WHEN_TAPPED_OUT=false USE_BERSERK_AGGRESSIVELY=true # Trade blocking preferences (enabling these will make the AI trade more aggressively when considering blocks, -# but only with creatures that are worse in abilities and have lower or the same power as the attacker) +# but only with creatures that are worse in abilities and have lower or the same power as the attacker). Note +# that the first option serves as a master toggle. If it is disabled, the following related options have no effect. 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_WHEN_HAVE_LESS_CREATS=true +# If the previous option is enabled, then the next option controls how big of a handicap in creature count the AI +# is allowed to have to still decide to trade +MAX_DIFF_IN_CREATURE_COUNT_TO_TRADE=1 # 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 68367598582..a44d65366c7 100644 --- a/forge-gui/res/ai/Reckless.ai +++ b/forge-gui/res/ai/Reckless.ai @@ -16,10 +16,14 @@ ATTACK_INTO_TRADE_WHEN_TAPPED_OUT=true USE_BERSERK_AGGRESSIVELY=true # Trade blocking preferences (enabling these will make the AI trade more aggressively when considering blocks, -# but only with creatures that are worse in abilities and have lower or the same power as the attacker) +# but only with creatures that are worse in abilities and have lower or the same power as the attacker). Note +# that the first option serves as a master toggle. If it is disabled, the following related options have no effect. 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_WHEN_HAVE_LESS_CREATS=false +# If the previous option is enabled, then the next option controls how big of a handicap in creature count the AI +# is allowed to have to still decide to trade +MAX_DIFF_IN_CREATURE_COUNT_TO_TRADE=1 # 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