diff --git a/forge-ai/src/main/java/forge/ai/AiProps.java b/forge-ai/src/main/java/forge/ai/AiProps.java index 6b87cd3f60a..b3f37683d78 100644 --- a/forge-ai/src/main/java/forge/ai/AiProps.java +++ b/forge-ai/src/main/java/forge/ai/AiProps.java @@ -103,9 +103,12 @@ public enum AiProps { /** */ BOUNCE_ALL_ELSEWHERE_NONCREAT_EVAL_DIFF ("3"), /** */ INTUITION_ALTERNATIVE_LOGIC ("false"), /** */ EXPLORE_MAX_CMC_DIFF_TO_PUT_IN_GRAVEYARD ("2"), - EXPLORE_NUM_LANDS_TO_STILL_NEED_MORE ("2"); /** */ + EXPLORE_NUM_LANDS_TO_STILL_NEED_MORE("2"), /** */ // Experimental features, must be removed after extensive testing and, ideally, defaulting // <-- There are no experimental options here --> + AI_IN_DANGER_THRESHOLD("4"), + AI_IN_DANGER_MAX_THRESHOLD("4"); + private final String strDefaultVal; diff --git a/forge-ai/src/main/java/forge/ai/ComputerUtilCombat.java b/forge-ai/src/main/java/forge/ai/ComputerUtilCombat.java index e4dfe9fa4a5..0b542206c7c 100644 --- a/forge-ai/src/main/java/forge/ai/ComputerUtilCombat.java +++ b/forge-ai/src/main/java/forge/ai/ComputerUtilCombat.java @@ -19,6 +19,7 @@ package forge.ai; import java.util.List; import java.util.Map; +import java.util.Random; import com.google.common.base.Predicate; import com.google.common.collect.Iterables; @@ -433,7 +434,18 @@ public class ComputerUtilCombat { } } - if (ComputerUtilCombat.lifeThatWouldRemain(ai, combat) - payment < Math.min(4, ai.getLife()) + int threshold = (((PlayerControllerAi) ai.getController()).getAi().getIntProperty(AiProps.AI_IN_DANGER_THRESHOLD)); + int maxTreshold = (((PlayerControllerAi) ai.getController()).getAi().getIntProperty(AiProps.AI_IN_DANGER_MAX_THRESHOLD)) - threshold; + Random rand = new Random(); + int chance = rand.nextInt(80) + 5; + while (maxTreshold > 0) { + if (rand.nextInt(100) < chance) { + threshold++; + } + maxTreshold--; + } + + if (ComputerUtilCombat.lifeThatWouldRemain(ai, combat) - payment < Math.min(threshold, ai.getLife()) && !ai.cantLoseForZeroOrLessLife()) { return true; } diff --git a/forge-gui/res/ai/Experimental.ai b/forge-gui/res/ai/Experimental.ai index b206c3c05a3..9b1e854a6fa 100644 --- a/forge-gui/res/ai/Experimental.ai +++ b/forge-gui/res/ai/Experimental.ai @@ -200,4 +200,11 @@ EXPLORE_NUM_LANDS_TO_STILL_NEED_MORE=3 # -- features is over. These toggles will be removed later, or may be reintroduced under a -- # -- different name if necessary -- +# If AI would drop to this amount of life in combat, it'll try to defend itself more actively +AI_IN_DANGER_THRESHOLD=3 +# If set to the same value, AI will be predictable. If set to higher, AI will randomly pick a value between the two +# for each evaluation, introducing some unpredictability. +AI_IN_DANGER_MAX_THRESHOLD=12 + + # <-- there are no options here at the moment -->