From 0f419144b5d48bafb0af6265ed5b1ffa84536a38 Mon Sep 17 00:00:00 2001 From: "omegablast2002@yahoo.com" Date: Thu, 2 Dec 2010 21:30:14 +0000 Subject: [PATCH] Fixed a bug where Ai was able to do actions such as sacrifice Mogg fanatic 3 time in a row by tripping over its own clickstream, added gaurds to selectAbility() function calls to prevent Ai from running multiple instences of selectAbility before its completed running another which occurs when Ai is offered an interupt after player cast/does an action. this also fixes the spamming of Abilities like Ai atempting to untap something more then once, or Ai uses regenerate ability multiple times on the same creature. there will be no noticible difference in Ai game play except now it actually doesnt do the above mentioned bugs. --- projects/mtg/include/AIPlayer.h | 1 + projects/mtg/src/AIMomirPlayer.cpp | 12 +++++++-- projects/mtg/src/AIPlayer.cpp | 41 +++++++++++++++++++++++++----- 3 files changed, 46 insertions(+), 8 deletions(-) diff --git a/projects/mtg/include/AIPlayer.h b/projects/mtg/include/AIPlayer.h index 3f9492130..5f5eebe24 100644 --- a/projects/mtg/include/AIPlayer.h +++ b/projects/mtg/include/AIPlayer.h @@ -59,6 +59,7 @@ protected: //Variables used by Test suite MTGCardInstance * nextCardToPlay; queue clickstream; + bool findingAbility; void tapLandsForMana(ManaCost * cost, MTGCardInstance * card = NULL); int orderBlockers(); int combatDamages(); diff --git a/projects/mtg/src/AIMomirPlayer.cpp b/projects/mtg/src/AIMomirPlayer.cpp index a5ca2bdc5..952e771ba 100644 --- a/projects/mtg/src/AIMomirPlayer.cpp +++ b/projects/mtg/src/AIMomirPlayer.cpp @@ -95,7 +95,11 @@ int AIMomirPlayer::computeActions() int currentGamePhase = g->getCurrentGamePhase(); if (g->isInterrupting == this) { // interrupting - selectAbility(); + if(!findingAbility) + { + AIPlayer::findingAbility = true; + selectAbility(); + } return 1; } else if (p == this && g->mLayers->stackLayer()->count(0, NOT_RESOLVED) == 0) @@ -129,7 +133,11 @@ int AIMomirPlayer::computeActions() break; } case Constants::MTG_PHASE_SECONDMAIN: - selectAbility(); + if(!findingAbility) + { + AIPlayer::findingAbility = true; + selectAbility(); + } return 1; break; default: diff --git a/projects/mtg/src/AIPlayer.cpp b/projects/mtg/src/AIPlayer.cpp index b58f34329..7c9e5620f 100644 --- a/projects/mtg/src/AIPlayer.cpp +++ b/projects/mtg/src/AIPlayer.cpp @@ -629,17 +629,25 @@ int AIPlayer::selectAbility() } else { + if(!clickstream.size()) + { DebugTrace("AIPlayer:Using Activated ability"); tapLandsForMana(a->ability->cost, a->click); - clickstream.push(a); + clickstream.push(a); + } + else + { + a = NULL; + } } map::iterator it2; for (it2 = ranking.begin(); it2 != ranking.end(); it2++) { - if (a != it2->first) + if (a && a != it2->first) delete (it2->first); } } + AIPlayer::findingAbility = false; return 1; } @@ -1145,6 +1153,7 @@ int AIPlayerBaka::computeActions() { GameObserver * g = GameObserver::GetInstance(); Player * p = g->currentPlayer; + AIPlayer::findingAbility = false; if (!(g->currentlyActing() == this)) return 0; if (g->mLayers->actionLayer()->menuObject) @@ -1157,7 +1166,11 @@ int AIPlayerBaka::computeActions() int currentGamePhase = g->getCurrentGamePhase(); if (g->isInterrupting == this) { // interrupting - selectAbility(); + if(!findingAbility) + { + AIPlayer::findingAbility = true; + selectAbility(); + } return 1; } else if (p == this && g->mLayers->stackLayer()->count(0, NOT_RESOLVED) == 0) @@ -1178,7 +1191,11 @@ int AIPlayerBaka::computeActions() potential = true; } nextCardToPlay = FindCardToPlay(currentMana, "land"); + if(!findingAbility) + { + AIPlayer::findingAbility = true; selectAbility(); + } //look for the most expensive creature we can afford if (castrestrictedspell == 0 && nospellinstant == 0) { @@ -1212,7 +1229,11 @@ int AIPlayerBaka::computeActions() } if (!nextCardToPlay) { - selectAbility(); + if(!findingAbility) + { + AIPlayer::findingAbility = true; + selectAbility(); + } } } } @@ -1261,7 +1282,11 @@ int AIPlayerBaka::computeActions() } else { - selectAbility(); + if(!findingAbility) + { + AIPlayer::findingAbility = true; + selectAbility(); + } } if (p->getManaPool()->getConvertedCost() > 0 && Checked == false)//not the best thing ever, but allows the Ai a chance to double check if its mana pool has something before moving on, atleast one time. { @@ -1277,7 +1302,11 @@ int AIPlayerBaka::computeActions() Checked = false; break; default: - selectAbility(); + if(!findingAbility) + { + AIPlayer::findingAbility = true; + selectAbility(); + } break; } }