added HINT:alwaysattackwith(targetchooser) and HINT:alwaysblockwith(targetchooser)

This commit is contained in:
omegablast2002@yahoo.com
2013-04-07 00:56:44 +00:00
parent ce656adeba
commit 6727c1af52
3 changed files with 69 additions and 0 deletions

View File

@@ -19,6 +19,8 @@ public:
string mAction;
string mCombatAttackTip;
string mCombatBlockTip;
string mCombatAlwaysBlockTip;
string mCombatAlwaysAttackTip;
vector<string>castOrder;
vector<string>combos;
//for preformance we disect the combo on first run.
@@ -50,7 +52,9 @@ public:
AIHints (AIPlayerBaka * player);
AIAction * suggestAbility(ManaCost * potentialMana);
bool HintSaysDontAttack(GameObserver* observer,MTGCardInstance * card = NULL);
bool HintSaysAlwaysAttack(GameObserver* observer,MTGCardInstance * card = NULL);
bool HintSaysDontBlock(GameObserver* observer,MTGCardInstance * card = NULL);
bool HintSaysAlwaysBlock(GameObserver* observer,MTGCardInstance * card = NULL);
bool HintSaysItsForCombo(GameObserver* observer,MTGCardInstance * card = NULL);
bool canWeCombo(GameObserver* observer,MTGCardInstance * card = NULL,AIPlayerBaka * Ai = NULL);
vector<string> mCastOrder();

View File

@@ -36,12 +36,24 @@ AIHint::AIHint(string _line)
mCombatAttackTip = splitDontAttack[1];
}
vector<string> splitAlwaysAttack = parseBetween(action, "alwaysattackwith(", ")");
if(splitAlwaysAttack.size())
{
mCombatAlwaysAttackTip = splitAlwaysAttack[1];
}
vector<string> splitDontBlock = parseBetween(action, "dontblockwith(", ")");
if(splitDontBlock.size())
{
mCombatBlockTip = splitDontBlock[1];
}
vector<string> splitAlwaysBlock = parseBetween(action, "alwaysblockwith(", ")");
if(splitAlwaysBlock.size())
{
mCombatAlwaysBlockTip = splitAlwaysBlock[1];
}
vector<string> splitCastOrder = parseBetween(action, "castpriority(", ")");
if(splitCastOrder.size())
{
@@ -106,6 +118,26 @@ bool AIHints::HintSaysDontAttack(GameObserver* observer,MTGCardInstance * card)
return false;
}
bool AIHints::HintSaysAlwaysAttack(GameObserver* observer,MTGCardInstance * card)
{
TargetChooserFactory tfc(observer);
TargetChooser * hintTc = NULL;
for(unsigned int i = 0; i < hints.size();i++)
{
if (hints[i]->mCombatAlwaysAttackTip.size())
{
hintTc = tfc.createTargetChooser(hints[i]->mCombatAlwaysAttackTip,card);
if(hintTc && hintTc->canTarget(card,true))
{
SAFE_DELETE(hintTc);
return true;
}
SAFE_DELETE(hintTc);
}
}
return false;
}
bool AIHints::HintSaysDontBlock(GameObserver* observer,MTGCardInstance * card)
{
TargetChooserFactory tfc(observer);
@@ -126,6 +158,26 @@ bool AIHints::HintSaysDontBlock(GameObserver* observer,MTGCardInstance * card)
return false;
}
bool AIHints::HintSaysAlwaysBlock(GameObserver* observer,MTGCardInstance * card)
{
TargetChooserFactory tfc(observer);
TargetChooser * hintTc = NULL;
for(unsigned int i = 0; i < hints.size();i++)
{
if (hints[i]->mCombatAlwaysBlockTip.size())
{
hintTc = tfc.createTargetChooser(hints[i]->mCombatAlwaysBlockTip,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);

View File

@@ -2219,6 +2219,17 @@ int AIPlayerBaka::chooseAttackers()
|| (myForce > opponentForce) || (myForce > opponent()->life);
}
printf("Choose attackers : %i %i %i %i -> %i\n", opponentForce, opponentCreatures, myForce, myCreatures, attack);
CardDescriptor cd;
cd.init();
cd.setType("creature");
MTGCardInstance * card = NULL;
while ((card = cd.nextmatch(game->inPlay, card)))
{
if(hints && hints->HintSaysAlwaysAttack(observer,card))
observer->cardClick(card, MTGAbility::MTG_ATTACK_RULE);
}
if (attack)
{
CardDescriptor cd;
@@ -2238,6 +2249,8 @@ int AIPlayerBaka::chooseAttackers()
/* Can I first strike my oponent and get away with murder ? */
int AIPlayerBaka::canFirstStrikeKill(MTGCardInstance * card, MTGCardInstance *ennemy)
{
if(hints && hints->HintSaysAlwaysBlock(observer,ennemy))
return 1;
if (ennemy->has(Constants::FIRSTSTRIKE) || ennemy->has(Constants::DOUBLESTRIKE))
return 0;
if (!(card->has(Constants::FIRSTSTRIKE) || card->has(Constants::DOUBLESTRIKE)))