ai simple combo system is finally fully working.

added ai hint dontblockwith(targetchooser)
This commit is contained in:
omegablast2002@yahoo.com
2013-03-16 21:35:10 +00:00
parent c2132ab97f
commit b436550150
4 changed files with 218 additions and 4 deletions
+33 -1
View File
@@ -36,6 +36,12 @@ AIHint::AIHint(string _line)
mCombatAttackTip = splitDontAttack[1];
}
vector<string> splitDontBlock = parseBetween(action, "dontblockwith(", ")");
if(splitDontBlock.size())
{
mCombatBlockTip = splitDontBlock[1];
}
vector<string> splitCastOrder = parseBetween(action, "castpriority(", ")");
if(splitCastOrder.size())
{
@@ -100,6 +106,26 @@ bool AIHints::HintSaysDontAttack(GameObserver* observer,MTGCardInstance * card)
return false;
}
bool AIHints::HintSaysDontBlock(GameObserver* observer,MTGCardInstance * card)
{
TargetChooserFactory tfc(observer);
TargetChooser * hintTc = NULL;
for(unsigned int i = 0; i < hints.size();i++)
{
if (hints[i]->mCombatBlockTip.size())
{
hintTc = tfc.createTargetChooser(hints[i]->mCombatBlockTip,card);
if(hintTc && hintTc->canTarget(card,true))
{
SAFE_DELETE(hintTc);
return true;
}
SAFE_DELETE(hintTc);
}
}
return false;
}
bool AIHints::HintSaysItsForCombo(GameObserver* observer,MTGCardInstance * card)
{
TargetChooserFactory tfc(observer);
@@ -142,6 +168,7 @@ bool AIHints::HintSaysItsForCombo(GameObserver* observer,MTGCardInstance * card)
asTc = parseBetween(hints[i]->partOfCombo[dPart],"cast(",")");
if(asTc.size())
{
hints[i]->casting.push_back(asTc[1]);
vector<string>cht = parseBetween(hints[i]->partOfCombo[dPart],"targeting(",")");
if(cht.size())
hints[i]->cardTargets[asTc[1]] = cht[1];
@@ -353,6 +380,11 @@ string AIHints::constraintsNotFulfilled(AIAction * action, AIHint * hint, ManaCo
out << "to see if this can attack[" << hint->mCombatAttackTip << "]";
return out.str();
}
if (hint->mCombatBlockTip.size())
{
out << "to see if this can block[" << hint->mCombatBlockTip << "]";
return out.str();
}
if (hint->mSourceId && !findSource(hint->mSourceId))
{
out << "needcardinplay[" << hint->mSourceId << "]";
@@ -414,7 +446,7 @@ AIAction * AIHints::findAbilityRecursive(AIHint * hint, ManaCost * potentialMana
}
string s = constraintsNotFulfilled(a, hint, potentialMana);
if (hint->mCombatAttackTip.size() || hint->castOrder.size())
if (hint->mCombatAttackTip.size() || hint->mCombatBlockTip.size() || hint->castOrder.size())
return NULL;
if (s.size())
{
+9 -3
View File
@@ -1851,7 +1851,7 @@ MTGCardInstance * AIPlayerBaka::FindCardToPlay(ManaCost * pMana, const char * ty
if(hints && hints->HintSaysItsForCombo(observer,nextCardToPlay))
{
DebugTrace(" AI wants to play a card that belongs to a combo.")
DebugTrace(" AI wants to play a card that belongs to a combo.");
nextCardToPlay = NULL;
}
@@ -1866,9 +1866,9 @@ MTGCardInstance * AIPlayerBaka::activateCombo()
TargetChooser * hintTc = NULL;
TargetChooserFactory tfc(observer);
ManaCost * totalCost = ManaCost::parseManaCost(comboHint->manaNeeded);
for(unsigned int k = 0;k < comboHint->hold.size(); k++)
for(unsigned int k = 0;k < comboHint->casting.size(); k++)
{
hintTc = tfc.createTargetChooser(comboHint->hold[k],nextCardToPlay);
hintTc = tfc.createTargetChooser(comboHint->casting[k],nextCardToPlay);
int combohand = game->hand->cards.size();
for(int j = 0; j < combohand;j++)
{
@@ -2252,6 +2252,8 @@ int AIPlayerBaka::chooseBlockers()
// We first try to block the major threats, those that are marked in the Top 3 of our stats
while ((card = cd.nextmatch(game->inPlay, card)))
{
if(hints && hints->HintSaysDontBlock(observer,card))
continue;
observer->cardClick(card, MTGAbility::MTG_BLOCK_RULE);
int set = 0;
while (!set)
@@ -2287,6 +2289,8 @@ int AIPlayerBaka::chooseBlockers()
card = NULL;
while ((card = cd.nextmatch(game->inPlay, card)))
{
if(hints && hints->HintSaysDontBlock(observer,card))
continue;
if (card->defenser && opponentsToughness[card->defenser] > 0)
{
while (card->defenser)
@@ -2300,6 +2304,8 @@ int AIPlayerBaka::chooseBlockers()
card = NULL;
while ((card = cd.nextmatch(game->inPlay, card)))
{
if(hints && hints->HintSaysDontBlock(observer,card))
continue;
if (!card->defenser)
{
observer->cardClick(card, MTGAbility::MTG_BLOCK_RULE);