From ebb06b34b0066fb6f98042b8d878ef6af0f708f7 Mon Sep 17 00:00:00 2001 From: Agetian Date: Mon, 4 Sep 2017 12:18:06 +0000 Subject: [PATCH] - Some more work on attack/block trades [experimental]. --- forge-ai/src/main/java/forge/ai/AiAttackController.java | 7 ++++++- forge-ai/src/main/java/forge/ai/AiProps.java | 1 + forge-ai/src/main/java/forge/ai/ComputerUtilCard.java | 1 + forge-gui/res/ai/Cautious.ai | 4 ++++ forge-gui/res/ai/Default.ai | 4 ++++ forge-gui/res/ai/Experimental.ai | 4 ++++ forge-gui/res/ai/Reckless.ai | 4 ++++ 7 files changed, 24 insertions(+), 1 deletion(-) diff --git a/forge-ai/src/main/java/forge/ai/AiAttackController.java b/forge-ai/src/main/java/forge/ai/AiAttackController.java index ccc2df893a6..91857687c10 100644 --- a/forge-ai/src/main/java/forge/ai/AiAttackController.java +++ b/forge-ai/src/main/java/forge/ai/AiAttackController.java @@ -588,15 +588,19 @@ public class AiAttackController { return; } + // Aggro options boolean playAggro = false; int chanceToAttackToTrade = 0; boolean tradeIfTappedOut = false; + int extraChanceIfOppHasMana = 0; 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); + extraChanceIfOppHasMana = aic.getIntProperty(AiProps.CHANCE_TO_ATKTRADE_WHEN_OPP_HAS_MANA); } + final boolean bAssault = this.doAssault(ai); // TODO: detect Lightmine Field by presence of a card with a specific trigger final boolean lightmineField = ComputerUtilCard.isPresentOnBattlefield(ai.getGame(), "Lightmine Field"); @@ -924,7 +928,8 @@ public class AiAttackController { && defendingOpponent != null && ComputerUtil.countUsefulCreatures(ai) > ComputerUtil.countUsefulCreatures(defendingOpponent) && ai.getLife() > defendingOpponent.getLife() - && (ComputerUtilMana.getAvailableManaEstimate(ai) > 0) || tradeIfTappedOut) { + && (ComputerUtilMana.getAvailableManaEstimate(ai) > 0) || tradeIfTappedOut + && (ComputerUtilMana.getAvailableManaEstimate(defendingOpponent) == 0) || MyRandom.percentTrue(extraChanceIfOppHasMana)) { 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/AiProps.java b/forge-ai/src/main/java/forge/ai/AiProps.java index 62866bd5620..7f6a2aaf0aa 100644 --- a/forge-ai/src/main/java/forge/ai/AiProps.java +++ b/forge-ai/src/main/java/forge/ai/AiProps.java @@ -38,6 +38,7 @@ public enum AiProps { /** */ PLAY_AGGRO ("false"), CHANCE_TO_ATTACK_INTO_TRADE ("40"), /** */ ATTACK_INTO_TRADE_WHEN_TAPPED_OUT ("false"), /** */ + CHANCE_TO_ATKTRADE_WHEN_OPP_HAS_MANA ("0"), /** */ TRY_TO_HOLD_COMBAT_TRICKS_UNTIL_BLOCK ("false"), /** */ CHANCE_TO_HOLD_COMBAT_TRICKS_UNTIL_BLOCK ("30"), /** */ ENABLE_RANDOM_FAVORABLE_TRADES_ON_BLOCK ("false"), /** */ diff --git a/forge-ai/src/main/java/forge/ai/ComputerUtilCard.java b/forge-ai/src/main/java/forge/ai/ComputerUtilCard.java index 6350994f835..30bd36ee5ef 100644 --- a/forge-ai/src/main/java/forge/ai/ComputerUtilCard.java +++ b/forge-ai/src/main/java/forge/ai/ComputerUtilCard.java @@ -1236,6 +1236,7 @@ public class ComputerUtilCard { } chance += threat; + // -- Hold combat trick (the AI will try to delay the pump until Declare Blockers) -- // Enable combat trick mode only in case it's a pure buff spell in hand with no keywords or with Trample, // First Strike, or Double Strike, otherwise the AI is unlikely to cast it or it's too late to // cast it during Declare Blockers, thus ruining its attacker diff --git a/forge-gui/res/ai/Cautious.ai b/forge-gui/res/ai/Cautious.ai index c2a5f07a3a2..89988030825 100644 --- a/forge-gui/res/ai/Cautious.ai +++ b/forge-gui/res/ai/Cautious.ai @@ -12,6 +12,10 @@ CHANCE_TO_ATTACK_INTO_TRADE=0 # 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 above zero, the AI will attack into trading options when the opponent is not tapped out, thus risking getting an +# unexpected combat trick or ability activation. Note that this chance is rolled separately after CHANCE_TO_ATTACK_INTO_TRADE +# has already succeeded. +CHANCE_TO_ATKTRADE_WHEN_OPP_HAS_MANA=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 # Try to hold combat tricks until blockers are declared in an attempt to trick the opponent into blocking a weak creature diff --git a/forge-gui/res/ai/Default.ai b/forge-gui/res/ai/Default.ai index 6bf9e1f84bc..d83c0c96831 100644 --- a/forge-gui/res/ai/Default.ai +++ b/forge-gui/res/ai/Default.ai @@ -12,6 +12,10 @@ CHANCE_TO_ATTACK_INTO_TRADE=0 # 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 above zero, the AI will attack into trading options when the opponent is not tapped out, thus risking getting an +# unexpected combat trick or ability activation. Note that this chance is rolled separately after CHANCE_TO_ATTACK_INTO_TRADE +# has already succeeded. +CHANCE_TO_ATKTRADE_WHEN_OPP_HAS_MANA=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 # Try to hold combat tricks until blockers are declared in an attempt to trick the opponent into blocking a weak creature diff --git a/forge-gui/res/ai/Experimental.ai b/forge-gui/res/ai/Experimental.ai index 6369a0aa4b2..6a5309688ff 100644 --- a/forge-gui/res/ai/Experimental.ai +++ b/forge-gui/res/ai/Experimental.ai @@ -12,6 +12,10 @@ CHANCE_TO_ATTACK_INTO_TRADE=40 # 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 above zero, the AI will attack into trading options when the opponent is not tapped out, thus risking getting an +# unexpected combat trick or ability activation. Note that this chance is rolled separately after CHANCE_TO_ATTACK_INTO_TRADE +# has already succeeded. +CHANCE_TO_ATKTRADE_WHEN_OPP_HAS_MANA=10 # 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 # Try to hold combat tricks until blockers are declared in an attempt to trick the opponent into blocking a weak creature diff --git a/forge-gui/res/ai/Reckless.ai b/forge-gui/res/ai/Reckless.ai index a95d0808169..f223e7a2234 100644 --- a/forge-gui/res/ai/Reckless.ai +++ b/forge-gui/res/ai/Reckless.ai @@ -12,6 +12,10 @@ CHANCE_TO_ATTACK_INTO_TRADE=100 # 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 above zero, the AI will attack into trading options when the opponent is not tapped out, thus risking getting an +# unexpected combat trick or ability activation. Note that this chance is rolled separately after CHANCE_TO_ATTACK_INTO_TRADE +# has already succeeded. +CHANCE_TO_ATKTRADE_WHEN_OPP_HAS_MANA=35 # 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 # Try to hold combat tricks until blockers are declared in an attempt to trick the opponent into blocking a weak creature