From 864727b208e64ac9f55ac86652aeba4b8aa281b2 Mon Sep 17 00:00:00 2001 From: "omegablast2002@yahoo.com" Date: Fri, 6 Apr 2012 23:10:11 +0000 Subject: [PATCH] added HINT:castpriority(blah,blah,blah,blah,ect) this is a method to set the order in which ai decides to play cards, you can for example tell ai to look for 2 instants, before trying to find a creature. be sure to list all main types of the deck otherwise ai will pass on stuff this is the current const char* types[] = {"planeswalker","creature", "enchantment", "artifact", "sorcery", "instant"}; so be sure you include them if the decks need them. other the above example would be coded HINT:castpriority(instant,instant,creature,planeswalker,enchantment,artifact,sorcery) as you can see this deck will now look for and play if possible, 2 instants before any of the other types. this will really help with decks which rely on cards like dark ritual to produce mana to cast creature, simply by listing instant before creature. if the deck had dark rituals, in the above example, and it had them in hand, it would then cast dark ritual, dark ritual, then one of the remaining types. this is actually tested not just assumed. --- projects/mtg/include/AIHints.h | 2 ++ projects/mtg/src/AIHints.cpp | 20 +++++++++++++++- projects/mtg/src/AIPlayerBaka.cpp | 38 +++++++++++++++++++++++-------- 3 files changed, 49 insertions(+), 11 deletions(-) diff --git a/projects/mtg/include/AIHints.h b/projects/mtg/include/AIHints.h index bc4123877..e0411b64e 100644 --- a/projects/mtg/include/AIHints.h +++ b/projects/mtg/include/AIHints.h @@ -17,6 +17,7 @@ public: string mCondition; string mAction; string mCombatAttackTip; + vectorcastOrder; int mSourceId; AIHint(string line); }; @@ -38,6 +39,7 @@ public: AIHints (AIPlayerBaka * player); AIAction * suggestAbility(ManaCost * potentialMana); bool HintSaysDontAttack(GameObserver* observer,MTGCardInstance * card = NULL); + vector mCastOrder(); void add(string line); ~AIHints(); }; diff --git a/projects/mtg/src/AIHints.cpp b/projects/mtg/src/AIHints.cpp index c4f98c7e0..b4cc119a2 100644 --- a/projects/mtg/src/AIHints.cpp +++ b/projects/mtg/src/AIHints.cpp @@ -37,6 +37,12 @@ AIHint::AIHint(string _line) { mCombatAttackTip = splitDontAttack[1]; } + + vector splitCastOrder = parseBetween(action, "castpriority(", ")"); + if(splitCastOrder.size()) + { + castOrder = split(splitCastOrder[1],','); + } } AIHints::AIHints(AIPlayerBaka * player): mPlayer(player) @@ -88,6 +94,18 @@ bool AIHints::HintSaysDontAttack(GameObserver* observer,MTGCardInstance * card) return false; } +vectorAIHints::mCastOrder() +{ + for(unsigned int i = 0; i < hints.size();i++) + { + if (hints[i]->castOrder.size()) + { + return hints[i]->castOrder; + } + } + return vector(); +} + //return true if a given ability matches a hint's description //Eventually this will look awfully similar to the parser...any way to merge them somehow ? bool AIHints::abilityMatches(MTGAbility * ability, AIHint * hint) @@ -251,7 +269,7 @@ AIAction * AIHints::findAbilityRecursive(AIHint * hint, ManaCost * potentialMana } string s = constraintsNotFulfilled(a, hint, potentialMana); - if (hint->mCombatAttackTip.size()) + if (hint->mCombatAttackTip.size() || hint->castOrder.size()) return NULL; if (s.size()) { diff --git a/projects/mtg/src/AIPlayerBaka.cpp b/projects/mtg/src/AIPlayerBaka.cpp index f6d38f141..9b7aa5130 100644 --- a/projects/mtg/src/AIPlayerBaka.cpp +++ b/projects/mtg/src/AIPlayerBaka.cpp @@ -1910,19 +1910,37 @@ int AIPlayerBaka::computeActions() nextCardToPlay = FindCardToPlay(currentMana, "land"); //look for the most expensive creature we can afford. If not found, try enchantment, then artifact, etc... - const char* types[] = {"planeswalker","creature", "enchantment", "artifact", "sorcery", "instant"}; - int count = 0; - while (!nextCardToPlay && count < 6) + if(hints && hints->mCastOrder().size()) { - if(clickstream.size()) //don't find cards while we have clicking to do. + vectorfindType = hints->mCastOrder(); + for(unsigned int j = 0;j < findType.size();j++) { - SAFE_DELETE(currentMana); - return 0; + if(clickstream.size()) + { + SAFE_DELETE(currentMana); + return 0; + } + nextCardToPlay = FindCardToPlay(currentMana, findType[j].c_str()); + if (game->playRestrictions->canPutIntoZone(nextCardToPlay, game->stack) == PlayRestriction::CANT_PLAY) + nextCardToPlay = NULL; + } + } + else + { + const char* types[] = {"planeswalker","creature", "enchantment", "artifact", "sorcery", "instant"}; + int count = 0; + while (!nextCardToPlay && count < 6) + { + if(clickstream.size()) //don't find cards while we have clicking to do. + { + SAFE_DELETE(currentMana); + return 0; + } + nextCardToPlay = FindCardToPlay(currentMana, types[count]); + if (game->playRestrictions->canPutIntoZone(nextCardToPlay, game->stack) == PlayRestriction::CANT_PLAY) + nextCardToPlay = NULL; + count++; } - nextCardToPlay = FindCardToPlay(currentMana, types[count]); - if (game->playRestrictions->canPutIntoZone(nextCardToPlay, game->stack) == PlayRestriction::CANT_PLAY) - nextCardToPlay = NULL; - count++; } SAFE_DELETE(currentMana);