From 44de14d070c7965c7a7da0b18072383c485be914 Mon Sep 17 00:00:00 2001 From: Agetian Date: Thu, 8 Nov 2018 08:47:19 +0300 Subject: [PATCH] - Minor improvements in Surveil logic. --- forge-ai/src/main/java/forge/ai/AiProps.java | 1 + .../main/java/forge/ai/ability/SurveilAi.java | 21 ++++++++++++++++++- forge-gui-mobile-dev/src/forge/app/Main.java | 6 +++--- forge-gui/res/ai/Cautious.ai | 3 +++ forge-gui/res/ai/Default.ai | 3 +++ forge-gui/res/ai/Experimental.ai | 3 +++ forge-gui/res/ai/Reckless.ai | 3 +++ .../res/cardsfolder/d/doom_whisperer.txt | 2 +- 8 files changed, 37 insertions(+), 5 deletions(-) diff --git a/forge-ai/src/main/java/forge/ai/AiProps.java b/forge-ai/src/main/java/forge/ai/AiProps.java index 69a6fbddf10..b9ee8d741e7 100644 --- a/forge-ai/src/main/java/forge/ai/AiProps.java +++ b/forge-ai/src/main/java/forge/ai/AiProps.java @@ -96,6 +96,7 @@ public enum AiProps { /** */ SCRY_IMMEDIATELY_UNCASTABLE_TO_BOTTOM ("false"), /** */ SCRY_IMMEDIATELY_UNCASTABLE_CMC_DIFF ("1"), /** */ SURVEIL_NUM_CARDS_IN_LIBRARY_TO_BAIL ("10"), /** */ + SURVEIL_LIFEPERC_AFTER_PAYING_LIFE ("75"), /** */ COMBAT_ASSAULT_ATTACK_EVASION_PREDICTION ("true"), /** */ COMBAT_ATTRITION_ATTACK_EVASION_PREDICTION ("true"), /** */ CONSERVATIVE_ENERGY_PAYMENT_ONLY_IN_COMBAT ("true"), /** */ diff --git a/forge-ai/src/main/java/forge/ai/ability/SurveilAi.java b/forge-ai/src/main/java/forge/ai/ability/SurveilAi.java index fe7b1671e67..ab269e00fe5 100644 --- a/forge-ai/src/main/java/forge/ai/ability/SurveilAi.java +++ b/forge-ai/src/main/java/forge/ai/ability/SurveilAi.java @@ -1,6 +1,9 @@ package forge.ai.ability; -import forge.ai.SpellAbilityAi; +import forge.ai.*; +import forge.game.card.Card; +import forge.game.cost.Cost; +import forge.game.cost.CostPayLife; import forge.game.phase.PhaseHandler; import forge.game.phase.PhaseType; import forge.game.player.Player; @@ -68,8 +71,14 @@ public class SurveilAi extends SpellAbilityAi { */ @Override protected boolean checkAiLogic(final Player ai, final SpellAbility sa, final String aiLogic) { + final Card source = sa.getHostCard(); + if ("Never".equals(aiLogic)) { return false; + } else if ("Once".equals(aiLogic)) { + if (AiCardMemory.isRememberedCard(ai, source, AiCardMemory.MemorySet.ACTIVATED_THIS_TURN)) { + return false; + } } // TODO: add card-specific Surveil AI logic here when/if necessary @@ -84,6 +93,15 @@ public class SurveilAi extends SpellAbilityAi { return false; } + // Only Surveil for life when at decent amount of life remaining + final Cost cost = sa.getPayCosts(); + if (cost != null && cost.hasSpecificCostType(CostPayLife.class)) { + final int maxLife = ((PlayerControllerAi)ai.getController()).getAi().getIntProperty(AiProps.SURVEIL_LIFEPERC_AFTER_PAYING_LIFE); + if (!ComputerUtilCost.checkLifeCost(ai, cost, sa.getHostCard(), ai.getStartingLife() * maxLife / 100, sa)) { + return false; + } + } + double chance = .4; // 40 percent chance for instant speed if (SpellAbilityAi.isSorcerySpeed(sa)) { chance = .667; // 66.7% chance for sorcery speed (since it will never activate EOT) @@ -99,6 +117,7 @@ public class SurveilAi extends SpellAbilityAi { @Override public boolean confirmAction(Player player, SpellAbility sa, PlayerActionConfirmMode mode, String message) { + AiCardMemory.rememberCard(player, sa.getHostCard(), AiCardMemory.MemorySet.ACTIVATED_THIS_TURN); return true; } } diff --git a/forge-gui-mobile-dev/src/forge/app/Main.java b/forge-gui-mobile-dev/src/forge/app/Main.java index d5a932cefda..03ba4bcc8f2 100644 --- a/forge-gui-mobile-dev/src/forge/app/Main.java +++ b/forge-gui-mobile-dev/src/forge/app/Main.java @@ -41,12 +41,12 @@ public class Main { } // Set this to "true" to make the mobile game port run as a full-screen desktop application - boolean desktopMode = cmd.hasOption("fullscreen"); + boolean desktopMode = true;//cmd.hasOption("fullscreen"); // Set this to the location where you want the mobile game port to look for assets when working as a full-screen desktop application // (uncomment the bottom version and comment the top one to load the res folder from the current folder the .jar is in if you would // like to make the game load from a desktop game folder configuration). - String desktopModeAssetsDir = "../forge-gui/"; - //String desktopModeAssetsDir = "./"; + //String desktopModeAssetsDir = "../forge-gui/"; + String desktopModeAssetsDir = "./"; // Assets directory used when the game fully emulates smartphone/tablet mode (desktopMode = false), useful when debugging from IDE String assetsDir = AssetsDownloader.SHARE_DESKTOP_ASSETS ? "../forge-gui/" : "testAssets/"; diff --git a/forge-gui/res/ai/Cautious.ai b/forge-gui/res/ai/Cautious.ai index b2112e06b01..60888c980ef 100644 --- a/forge-gui/res/ai/Cautious.ai +++ b/forge-gui/res/ai/Cautious.ai @@ -171,6 +171,9 @@ SCRY_IMMEDIATELY_UNCASTABLE_CMC_DIFF=3 # If the AI has this many or fewer cards in the library, it will Surveil to the top of the library in order # not to deplete the library. SURVEIL_NUM_CARDS_IN_LIBRARY_TO_BAIL=10 +# If the AI will have less life than the specified percentage as a result of activating a Surveil ability +# that requires a life playment, it will not pay life to activate it (e.g. Doom Whisperer). +SURVEIL_LIFEPERC_AFTER_PAYING_LIFE=75 # Attempt to predict the number of potential blockers with various forms of evasion when # deciding to do an all-in assault attack diff --git a/forge-gui/res/ai/Default.ai b/forge-gui/res/ai/Default.ai index 2f6b99c304e..ba41dc8e5c8 100644 --- a/forge-gui/res/ai/Default.ai +++ b/forge-gui/res/ai/Default.ai @@ -171,6 +171,9 @@ SCRY_IMMEDIATELY_UNCASTABLE_CMC_DIFF=1 # If the AI has this many or fewer cards in the library, it will Surveil to the top of the library in order # not to deplete the library. SURVEIL_NUM_CARDS_IN_LIBRARY_TO_BAIL=10 +# If the AI will have less life than the specified percentage as a result of activating a Surveil ability +# that requires a life playment, it will not pay life to activate it (e.g. Doom Whisperer). +SURVEIL_LIFEPERC_AFTER_PAYING_LIFE=60 # Attempt to predict the number of potential blockers with various forms of evasion when # deciding to do an all-in assault attack diff --git a/forge-gui/res/ai/Experimental.ai b/forge-gui/res/ai/Experimental.ai index d844e5c2925..c48eedbe7c9 100644 --- a/forge-gui/res/ai/Experimental.ai +++ b/forge-gui/res/ai/Experimental.ai @@ -171,6 +171,9 @@ SCRY_IMMEDIATELY_UNCASTABLE_CMC_DIFF=1 # If the AI has this many or fewer cards in the library, it will Surveil to the top of the library in order # not to deplete the library. SURVEIL_NUM_CARDS_IN_LIBRARY_TO_BAIL=8 +# If the AI will have less life than the specified percentage as a result of activating a Surveil ability +# that requires a life playment, it will not pay life to activate it (e.g. Doom Whisperer). +SURVEIL_LIFEPERC_AFTER_PAYING_LIFE=50 # Attempt to predict the number of potential blockers with various forms of evasion when # deciding to do an all-in assault attack (Experimental!) diff --git a/forge-gui/res/ai/Reckless.ai b/forge-gui/res/ai/Reckless.ai index da788df7ce1..57f13150d73 100644 --- a/forge-gui/res/ai/Reckless.ai +++ b/forge-gui/res/ai/Reckless.ai @@ -171,6 +171,9 @@ SCRY_IMMEDIATELY_UNCASTABLE_CMC_DIFF=1 # If the AI has this many or fewer cards in the library, it will Surveil to the top of the library in order # not to deplete the library. SURVEIL_NUM_CARDS_IN_LIBRARY_TO_BAIL=5 +# If the AI will have less life than the specified percentage as a result of activating a Surveil ability +# that requires a life playment, it will not pay life to activate it (e.g. Doom Whisperer). +SURVEIL_LIFEPERC_AFTER_PAYING_LIFE=35 # Attempt to predict the number of potential blockers with various forms of evasion when # deciding to do an all-in assault attack diff --git a/forge-gui/res/cardsfolder/d/doom_whisperer.txt b/forge-gui/res/cardsfolder/d/doom_whisperer.txt index 469af683112..68c92f036d4 100644 --- a/forge-gui/res/cardsfolder/d/doom_whisperer.txt +++ b/forge-gui/res/cardsfolder/d/doom_whisperer.txt @@ -4,6 +4,6 @@ Types:Creature Nightmare Demon PT:6/6 K:Flying K:Trample -A:AB$ Surveil | Cost$ PayLife<2> | Amount$ 2 | SpellDescription$ Surveil 2. (Look at the top two cards of your library, then put any number of them into your graveyard and the rest on the top of your library in any order.) +A:AB$ Surveil | Cost$ PayLife<2> | Amount$ 2 | AILogic$ Once | SpellDescription$ Surveil 2. (Look at the top two cards of your library, then put any number of them into your graveyard and the rest on the top of your library in any order.) DeckHas:Ability$Surveil & Ability$Graveyard Oracle:Flying, trample\nPay 2 life: Surveil 2. (Look at the top two cards of your library, then put any number of them into your graveyard and the rest on the top of your library in any order.)