diff --git a/projects/mtg/include/AIPlayer.h b/projects/mtg/include/AIPlayer.h index 384a33041..3f9492130 100644 --- a/projects/mtg/include/AIPlayer.h +++ b/projects/mtg/include/AIPlayer.h @@ -45,8 +45,10 @@ public: class CmpAbilities { // compares Abilities efficiency public: bool operator()(AIAction * a1, AIAction * a2) const { - int e1 = a1->getEfficiency(); - int e2 = a2->getEfficiency(); + int e1 = 0; + e1 = a1->getEfficiency(); + int e2 = 0; + e2 = a2->getEfficiency(); if (e1 == e2) return a1->id < a2->id; return (e1 > e2); } diff --git a/projects/mtg/include/MTGGameZones.h b/projects/mtg/include/MTGGameZones.h index 8aca04c9a..3d5e8604d 100644 --- a/projects/mtg/include/MTGGameZones.h +++ b/projects/mtg/include/MTGGameZones.h @@ -83,6 +83,8 @@ class MTGGameZone { MTGCardInstance * findByName(string name); int hasAbility(int ability); //returns 1 if one of the cards in the zone has the ability, 0 otherwise int hasType(const char * value); //returns 1 if one of the cards in the zone has the type, 0 otherwise + int hasColor(int value); //returns 1 if one of the cards in the zone has the color, 0 otherwise + int hasX(); void setOwner(Player * player); MTGCardInstance * lastCardDrawn; static MTGGameZone * stringToZone(string zoneName, MTGCardInstance * source, MTGCardInstance * target); diff --git a/projects/mtg/src/AIPlayer.cpp b/projects/mtg/src/AIPlayer.cpp index c83b8a003..8917d1a30 100644 --- a/projects/mtg/src/AIPlayer.cpp +++ b/projects/mtg/src/AIPlayer.cpp @@ -322,6 +322,16 @@ int AIAction::getEfficiency() //increase the efficeincy of leveling up by a small amount equal to current level. efficiency += currentlevel; } + if(p->game->hand->nb_cards > 0 && p->isAI()) + { + efficiency -= (10 * p->game->hand->nb_cards);//reduce the eff if by 10 times the amount of cards in Ais hand. + //it should always try playing more cards before deciding + } + if(g->getCurrentGamePhase() == Constants::MTG_PHASE_SECONDMAIN) + { + efficiency = 100; + //in 2nd main, go all out and try to max stuff. + } break; } case MTGAbility::STANDARD_PUMP: @@ -370,20 +380,49 @@ int AIAction::getEfficiency() case MTGAbility::FOREACH: { MTGCardInstance * _target = (MTGCardInstance *) (a->target); + MTGAbility * a = AbilityFactory::getCoreAbility(ability); + AManaProducer * amp = dynamic_cast (a); //trying to encourage Ai to use his foreach manaproducers in first main - if ((g->getCurrentGamePhase() == Constants::MTG_PHASE_FIRSTMAIN || g->getCurrentGamePhase() == Constants::MTG_PHASE_SECONDMAIN ) && _target->controller()->game->hand->nb_cards > 0) + if (a->naType == MTGAbility::MANA_PRODUCER && (g->getCurrentGamePhase() == Constants::MTG_PHASE_FIRSTMAIN || g->getCurrentGamePhase() == Constants::MTG_PHASE_SECONDMAIN ) + && _target->controller()->game->hand->nb_cards > 0) { - efficiency = 100; - } + for (int i = Constants::MTG_NB_COLORS - 1; i > 0; i--) + { + if((p->game->hand->hasColor(i) || p->game->hand->hasColor(0) ) + && (dynamic_cast(( dynamic_cast( a )->ability))->output->hasColor(i))) + { + efficiency = 100; + } + else + { + efficiency = 0; + } + } + if(p->game->hand->hasX()) + { + efficiency = 100; + } + } + else + { AbilityFactory af; int suggestion = af.abilityEfficiency(a, p, MODE_ABILITY); if (target) { - if ((suggestion == BAKA_EFFECT_BAD && p == target->controller()) || (suggestion == BAKA_EFFECT_GOOD && p - != target->controller())) + if (a->naType != MTGAbility::MANA_PRODUCER && ((suggestion == BAKA_EFFECT_BAD && p == target->controller()) || (suggestion == BAKA_EFFECT_GOOD && p + != target->controller()))) { efficiency = 0; } + else if (a->naType != MTGAbility::MANA_PRODUCER) + { + efficiency = 90; + } + else + { + efficiency = 0; + } + } } break; } @@ -1038,8 +1077,8 @@ int AIPlayerBaka::computeActions() currentMana = getPotentialMana(); potential = true; } - nextCardToPlay = FindCardToPlay(currentMana, "land"); + selectAbility(); //look for the most expensive creature we can afford if (castrestrictedspell == 0 && nospellinstant == 0) { @@ -1071,9 +1110,14 @@ int AIPlayerBaka::computeActions() { nextCardToPlay = FindCardToPlay(currentMana, "instant"); } + if (!nextCardToPlay) + { + selectAbility(); + } } - } - } + } + + } if (potential) delete (currentMana); if (nextCardToPlay) diff --git a/projects/mtg/src/MTGGameZones.cpp b/projects/mtg/src/MTGGameZones.cpp index d8e96798f..0f419a75a 100644 --- a/projects/mtg/src/MTGGameZones.cpp +++ b/projects/mtg/src/MTGGameZones.cpp @@ -538,6 +538,30 @@ int MTGGameZone::hasType(const char * value) return 0; } +int MTGGameZone::hasColor(int value) +{ + for (int i = 0; i < (nb_cards); i++) + { + if (cards[i]->getManaCost()->hasColor(value)) + { + return 1; + } + } + return 0; +} + +int MTGGameZone::hasX() +{ + for (int i = 0; i < (nb_cards); i++) + { + if (cards[i]->getManaCost()->hasX()) + { + return true; + } + } + return false; +} + int MTGGameZone::hasAbility(int ability) { for (int i = 0; i < (nb_cards); i++)