-attempt at issue 81. It will do for now
This commit is contained in:
wagic.the.homebrew@gmail.com
2009-10-04 08:39:34 +00:00
parent 6a2f454e64
commit 61cb849d33
3 changed files with 20 additions and 5 deletions

View File

@@ -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();

View File

@@ -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];

View File

@@ -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){