diff --git a/projects/mtg/bin/Res/test/manual/legendary_ai.txt b/projects/mtg/bin/Res/test/manual/legendary_ai.txt new file mode 100644 index 000000000..fbdbc4534 --- /dev/null +++ b/projects/mtg/bin/Res/test/manual/legendary_ai.txt @@ -0,0 +1,19 @@ +#Bug:Does ai put 2 legends of same name in play ? +[INIT] +SECONDMAIN +[PLAYER1] +inplay:urborg +hand:forest,urborg +[PLAYER2] +[DO] +ai +ai +[ASSERT] +COMBATEND +[PLAYER1] +inplay:Wildslayer Elves,Armadillo Cloak +life:25 +[PLAYER2] +graveyard:grizzly bears +life:17 +[END] \ No newline at end of file diff --git a/projects/mtg/include/MTGGameZones.h b/projects/mtg/include/MTGGameZones.h index c667601c1..b6aac8d37 100644 --- a/projects/mtg/include/MTGGameZones.h +++ b/projects/mtg/include/MTGGameZones.h @@ -79,6 +79,7 @@ class MTGGameZone { MTGCardInstance * hasCard(MTGCardInstance * card); void cleanupPhase(); int countByType(const char * value); + MTGCardInstance * findByName(string name); int hasType(const char * value); void setOwner(Player * player); MTGCardInstance * lastCardDrawn; diff --git a/projects/mtg/src/AIPlayer.cpp b/projects/mtg/src/AIPlayer.cpp index a238db6da..1ba2d40e5 100644 --- a/projects/mtg/src/AIPlayer.cpp +++ b/projects/mtg/src/AIPlayer.cpp @@ -590,6 +590,7 @@ MTGCardInstance * AIPlayerBaka::FindCardToPlay(ManaCost * potentialMana, const c card = NULL; while((card = cd.nextmatch(game->hand, card))){ if (card->hasType("land") && !this->canPutLandsIntoPlay) continue; + if (card->has(Constants::LEGENDARY) && game->inPlay->findByName(card->name)) continue; int currentCost = card->getManaCost()->getConvertedCost(); if (currentCost > maxCost && potentialMana->canAfford(card->getManaCost())){ TargetChooserFactory * tcf = NEW TargetChooserFactory(); @@ -656,17 +657,6 @@ int AIPlayerBaka::computeActions(){ case Constants::MTG_PHASE_FIRSTMAIN: case Constants::MTG_PHASE_SECONDMAIN: { - if (canPutLandsIntoPlay){ - //Attempt to put land into play - cd.init(); - cd.setColor(Constants::MTG_COLOR_LAND); - card = cd.match(game->hand); - if (card){ - AIAction * a = NEW AIAction(card); - clickstream.push(a); - return 1; - } - } //No mana, try to get some SAFE_DELETE(potentialMana); @@ -674,30 +664,26 @@ int AIPlayerBaka::computeActions(){ if (!currentMana->getConvertedCost()){ currentMana = getPotentialMana(); } - if (currentMana->getConvertedCost() > 0){ - - //look for the most expensive creature we can afford - nextCardToPlay = FindCardToPlay(currentMana, "creature"); - //Let's Try an enchantment maybe ? - if (!nextCardToPlay) nextCardToPlay = FindCardToPlay(currentMana, "enchantment"); - if (!nextCardToPlay) nextCardToPlay = FindCardToPlay(currentMana, "artifact"); - if (!nextCardToPlay) nextCardToPlay = FindCardToPlay(currentMana, "instant"); - if (!nextCardToPlay) nextCardToPlay = FindCardToPlay(currentMana, "sorcery"); - if (nextCardToPlay){ + nextCardToPlay = FindCardToPlay(currentMana, "land"); + //look for the most expensive creature we can afford + if (!nextCardToPlay) nextCardToPlay = FindCardToPlay(currentMana, "creature"); + //Let's Try an enchantment maybe ? + if (!nextCardToPlay) nextCardToPlay = FindCardToPlay(currentMana, "enchantment"); + if (!nextCardToPlay) nextCardToPlay = FindCardToPlay(currentMana, "artifact"); + if (!nextCardToPlay) nextCardToPlay = FindCardToPlay(currentMana, "instant"); + if (!nextCardToPlay) nextCardToPlay = FindCardToPlay(currentMana, "sorcery"); + if (nextCardToPlay){ #if defined (WIN32) || defined (LINUX) - char buffe[4096]; - sprintf(buffe, "Putting Card Into Play: %s", nextCardToPlay->getName().c_str()); - OutputDebugString(buffe); + char buffe[4096]; + sprintf(buffe, "Putting Card Into Play: %s", nextCardToPlay->getName().c_str()); + OutputDebugString(buffe); #endif - if (currentMana == potentialMana) tapLandsForMana(currentMana,nextCardToPlay->getManaCost()); - AIAction * a = NEW AIAction(nextCardToPlay); - clickstream.push(a); - return 1; - }else{ - selectAbility(); - } + if (currentMana == potentialMana) tapLandsForMana(currentMana,nextCardToPlay->getManaCost()); + AIAction * a = NEW AIAction(nextCardToPlay); + clickstream.push(a); + return 1; }else{ selectAbility(); } diff --git a/projects/mtg/src/MTGGameZones.cpp b/projects/mtg/src/MTGGameZones.cpp index c7a13fd41..ec61ccb23 100644 --- a/projects/mtg/src/MTGGameZones.cpp +++ b/projects/mtg/src/MTGGameZones.cpp @@ -232,6 +232,15 @@ int MTGGameZone::countByType(const char * value){ } +MTGCardInstance * MTGGameZone::findByName(string name){ + for (int i=0; i<(nb_cards); i++) { + if (cards[i]->name == name){ + return cards[i]; + } + } + return NULL; +} + int MTGGameZone::hasType(const char * value){ for (int i=0; i<(nb_cards); i++) { if (cards[i]->hasType(value)){