diff --git a/projects/mtg/include/ManaCost.h b/projects/mtg/include/ManaCost.h index 5ce447dce..531cb8ce3 100644 --- a/projects/mtg/include/ManaCost.h +++ b/projects/mtg/include/ManaCost.h @@ -29,6 +29,7 @@ class ManaCost{ static ManaCost * parseManaCost(string value, ManaCost * _manacost = NULL, MTGCardInstance * c = NULL); virtual void init(); void x(); + int hasX(); ManaCost(int _cost[], int nb_elems = 1); ManaCost(); ~ManaCost(); diff --git a/projects/mtg/src/AIPlayer.cpp b/projects/mtg/src/AIPlayer.cpp index 1ba2d40e5..95454aa46 100644 --- a/projects/mtg/src/AIPlayer.cpp +++ b/projects/mtg/src/AIPlayer.cpp @@ -592,26 +592,36 @@ MTGCardInstance * AIPlayerBaka::FindCardToPlay(ManaCost * potentialMana, const c 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())){ + int hasX = card->getManaCost()->hasX(); + if ((currentCost > maxCost || hasX) && potentialMana->canAfford(card->getManaCost())){ TargetChooserFactory * tcf = NEW TargetChooserFactory(); TargetChooser * tc = tcf->createTargetChooser(card); delete tcf; + int shouldPlayPercentage = 10; if (tc){ int hasTarget = (chooseTarget(tc)); delete tc; if (!hasTarget)continue; + shouldPlayPercentage = 90; }else{ - int shouldPlayPercentage = 10; int shouldPlay = effectBadOrGood(card); if (shouldPlay == BAKA_EFFECT_GOOD){ shouldPlayPercentage = 90; }else if(BAKA_EFFECT_DONTKNOW == shouldPlay){ shouldPlayPercentage = 80; } - if (rand() % 100 > shouldPlayPercentage) continue; } + //Reduce the chances of playing a spell with X cost if available mana is low + if (hasX){ + int xDiff = potentialMana->getConvertedCost() - currentCost; + if (xDiff < 0) xDiff = 0; + shouldPlayPercentage = shouldPlayPercentage - ((shouldPlayPercentage * 1.9) / (1 + xDiff)); + } + + if (rand() % 100 > shouldPlayPercentage) continue; nextCardToPlay = card; maxCost = currentCost; + if(hasX) maxCost = potentialMana->getConvertedCost(); } } return nextCardToPlay; @@ -671,8 +681,8 @@ int AIPlayerBaka::computeActions(){ //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, "instant"); if (nextCardToPlay){ #if defined (WIN32) || defined (LINUX) char buffe[4096]; diff --git a/projects/mtg/src/ManaCost.cpp b/projects/mtg/src/ManaCost.cpp index 3358cf10f..834241cd8 100644 --- a/projects/mtg/src/ManaCost.cpp +++ b/projects/mtg/src/ManaCost.cpp @@ -136,6 +136,10 @@ void ManaCost::x(){ cost[Constants::MTG_NB_COLORS] = 1; } +int ManaCost::hasX(){ + return cost[Constants::MTG_NB_COLORS]; +} + void ManaCost::init(){ int i; for (i=0; i<= Constants::MTG_NB_COLORS; i++){ @@ -379,7 +383,7 @@ ManaCost * ManaCost::Diff(ManaCost * _cost){ } //Cost X - if (_cost->getCost(Constants::MTG_NB_COLORS)){ + if (_cost->hasX()){ diff[Constants::MTG_NB_COLORS * 2 + 1] = 0; for (int i=0; i < Constants::MTG_NB_COLORS; i++){ if (diff[i*2 + 1] > 0){