From cf70a969b1c4aa5072ca4e81e1af1d5ae5582777 Mon Sep 17 00:00:00 2001 From: Agetian Date: Thu, 18 Sep 2014 11:47:45 +0000 Subject: [PATCH] - At least for now, added an AI profile property RESERVE_MANA_FOR_MAIN2_CHANCE that indicates a chance that the AI would want to reserve mana for a main 2 phase spell. Currently set to 0 for all profiles (the AI will not reserve mana). - The AI will obey mana reservations either if the spell ability is explicitly marked as low priority with SVar LowPriorityAI or, if it's not marked as low priority, depending on the random chance as specified in RESERVE_MANA_FOR_MAIN2_CHANCE. --- forge-ai/src/main/java/forge/ai/AiProps.java | 3 ++- .../src/main/java/forge/ai/ComputerUtilMana.java | 16 ++++++++++++---- forge-gui/res/ai/Default.ai | 2 ++ forge-gui/res/ai/Reckless.ai | 1 + 4 files changed, 17 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 e90fa5a5866..7d231e0aa3e 100644 --- a/forge-ai/src/main/java/forge/ai/AiProps.java +++ b/forge-ai/src/main/java/forge/ai/AiProps.java @@ -30,7 +30,8 @@ public enum AiProps { /** */ MULLIGAN_THRESHOLD ("5"), /** */ PLANAR_DIE_ROLL_HESITATION_CHANCE ("10"), CHEAT_WITH_MANA_ON_SHUFFLE ("false"), - MOVE_EQUIPMENT_TO_BETTER_CREATURES ("always"); /** */ + MOVE_EQUIPMENT_TO_BETTER_CREATURES ("from_useless_only"), + RESERVE_MANA_FOR_MAIN2_CHANCE ("0"); /** */ private final String strDefaultVal; diff --git a/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java b/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java index 58d9ecf78ed..b297c4410cf 100644 --- a/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java +++ b/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java @@ -30,6 +30,7 @@ import forge.game.spellability.AbilityManaPart; import forge.game.spellability.AbilitySub; import forge.game.spellability.SpellAbility; import forge.game.zone.ZoneType; +import forge.util.MyRandom; import forge.util.TextUtil; import org.apache.commons.lang3.StringUtils; @@ -661,17 +662,24 @@ public class ComputerUtilMana { return false; } - // LowPriorityAI SVar should be set to 'low' elsewhere to indicate that it is a low priority spell ability + AiController aic = ((PlayerControllerAi)ai.getController()).getAi(); + int chanceToReserve = aic.getIntProperty(AiProps.RESERVE_MANA_FOR_MAIN2_CHANCE); + + // If it's a low priority spell (it's explicitly marked so elsewhere in the AI with a SVar), always + // obey mana reservations; otherwise, obey mana reservations depending on the "chance to reserve" + // AI profile variable. if (sa.getSVar("LowPriorityAI").equals("")) { - return false; + if (chanceToReserve == 0 || MyRandom.getRandom().nextInt(100) >= chanceToReserve) { + return false; + } } PhaseType curPhase = ai.getGame().getPhaseHandler().getPhase(); if (curPhase == PhaseType.MAIN2 || curPhase == PhaseType.CLEANUP) { - ((PlayerControllerAi)ai.getController()).getAi().getCardMemory().clearMemorySet(AiCardMemory.MemorySet.HELD_MANA_SOURCES); + aic.getCardMemory().clearMemorySet(AiCardMemory.MemorySet.HELD_MANA_SOURCES); } else { - if (((PlayerControllerAi)ai.getController()).getAi().getCardMemory().isRememberedCard(sourceCard, AiCardMemory.MemorySet.HELD_MANA_SOURCES)) { + if (aic.getCardMemory().isRememberedCard(sourceCard, AiCardMemory.MemorySet.HELD_MANA_SOURCES)) { // This mana source is held elsewhere for a Main Phase 2 spell. return true; } diff --git a/forge-gui/res/ai/Default.ai b/forge-gui/res/ai/Default.ai index 8e38572c431..9c32870dcea 100644 --- a/forge-gui/res/ai/Default.ai +++ b/forge-gui/res/ai/Default.ai @@ -5,3 +5,5 @@ DEFAULT_PLANAR_DIE_ROLL_CHANCE=50 MULLIGAN_THRESHOLD=5 PLANAR_DIE_ROLL_HESITATION_CHANCE=10 MOVE_EQUIPMENT_TO_BETTER_CREATURES=from_useless_only +RESERVE_MANA_FOR_MAIN2_CHANCE=0 + diff --git a/forge-gui/res/ai/Reckless.ai b/forge-gui/res/ai/Reckless.ai index e342edee2f7..c3055c7b5fa 100644 --- a/forge-gui/res/ai/Reckless.ai +++ b/forge-gui/res/ai/Reckless.ai @@ -5,3 +5,4 @@ DEFAULT_PLANAR_DIE_ROLL_CHANCE=100 MULLIGAN_THRESHOLD=3 PLANAR_DIE_ROLL_HESITATION_CHANCE=0 MOVE_EQUIPMENT_TO_BETTER_CREATURES=always +RESERVE_MANA_FOR_MAIN2_CHANCE=0