From bce5b9e54bee22571549d5f67fe6f4dd4a108cb1 Mon Sep 17 00:00:00 2001 From: "omegablast2002@yahoo.com" Date: Tue, 23 Nov 2010 16:52:46 +0000 Subject: [PATCH] Ai training: some Foreach training, optimizted the equip training to have Ai better use equipment, it should no longer leave equipment sitting around, enticed Ai into paying upcost on cards YAY! no more summon now and lose it next turn! :) enjoy. --- projects/mtg/include/MTGAbility.h | 1 + projects/mtg/src/AIPlayer.cpp | 67 ++++++++++++++++++++++++++----- projects/mtg/src/AllAbilities.cpp | 1 + 3 files changed, 59 insertions(+), 10 deletions(-) diff --git a/projects/mtg/include/MTGAbility.h b/projects/mtg/include/MTGAbility.h index a00cdd516..ecad92e36 100644 --- a/projects/mtg/include/MTGAbility.h +++ b/projects/mtg/include/MTGAbility.h @@ -99,6 +99,7 @@ class MTGAbility: public ActionElement{ STANDARD_DRAW = 17, STANDARD_PUMP = 18, STANDARD_BECOMES = 19, + UPCOST = 20, }; diff --git a/projects/mtg/src/AIPlayer.cpp b/projects/mtg/src/AIPlayer.cpp index 3505d1fe8..c83b8a003 100644 --- a/projects/mtg/src/AIPlayer.cpp +++ b/projects/mtg/src/AIPlayer.cpp @@ -172,9 +172,10 @@ int AIPlayer::CanHandleCost(ManaCost * cost) for (size_t i = 0; i < ec->costs.size(); ++i) { if (ec->costs[i]->tc) + { return 0; + } } - return 1; } @@ -279,6 +280,12 @@ int AIAction::getEfficiency() { MTGCardInstance * _target = (MTGCardInstance *) (a->target); efficiency = 0; + int equips = 0; + equips = p->game->battlefield->countByType("Equipment"); + int myArmy = 0; + myArmy = p->game->battlefield->countByType("Creature"); + int equilized = 0; + equilized = abs(equips/myArmy); if (p == target->controller() && target->equipment <= 1 && !a->source->target) { efficiency = 20 * (target->DangerRanking()); @@ -287,9 +294,10 @@ int AIAction::getEfficiency() if (target->power == 1 && target->toughness == 1 && target->isToken == 0) efficiency += 10; //small bonus to encourage equipping nontoken 1/1 creatures. } - if (p == target->controller() && target->equipment > 2 && !a->source->target) + if (p == target->controller() && !a->source->target && target->equipment < equilized) { efficiency = 15 * (target->DangerRanking()); + efficiency -= 5 * (target->equipment); } break; } @@ -348,6 +356,36 @@ int AIAction::getEfficiency() efficiency = 100; } break; + } + case MTGAbility::UPCOST: + { + MTGCardInstance * _target = (MTGCardInstance *) (a->target); + //hello, Ai pay your upcost please :P, this entices Ai into paying upcost, the conditional isAi() is required strangely ai is able to pay upcost during YOUR upkeep. + if (g->getCurrentGamePhase() == Constants::MTG_PHASE_UPKEEP && g->currentPlayer->isAI()) + { + efficiency = 100; + } + break; + } + case MTGAbility::FOREACH: + { + MTGCardInstance * _target = (MTGCardInstance *) (a->target); + //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) + { + efficiency = 100; + } + 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())) + { + efficiency = 0; + } + } + break; } case MTGAbility::MANA_PRODUCER: //can't use mana producers right now :/ efficiency = 0; @@ -877,17 +915,17 @@ MTGCardInstance * AIPlayerBaka::FindCardToPlay(ManaCost * pMana, const char * ty card = NULL; while ((card = cd.nextmatch(game->hand, card))) { - if (!CanHandleCost(card->getManaCost())) + if (!CanHandleCost(card->getManaCost())) continue; - if (card->hasType(Subtypes::TYPE_CREATURE) && this->castrestrictedcreature < 0 && this->castrestrictedspell < 0) + if (card->hasType(Subtypes::TYPE_CREATURE) && this->castrestrictedcreature > 0 && this->castrestrictedspell > 0) continue; - if (card->hasType(Subtypes::TYPE_ENCHANTMENT) && this->castrestrictedspell < 0) + if (card->hasType(Subtypes::TYPE_ENCHANTMENT) && this->castrestrictedspell > 0) continue; - if (card->hasType(Subtypes::TYPE_ARTIFACT) && this->castrestrictedspell < 0) + if (card->hasType(Subtypes::TYPE_ARTIFACT) && this->castrestrictedspell > 0) continue; - if (card->hasType(Subtypes::TYPE_SORCERY) && this->castrestrictedspell < 0) + if (card->hasType(Subtypes::TYPE_SORCERY) && this->castrestrictedspell > 0) continue; - if (card->hasType(Subtypes::TYPE_INSTANT) && this->castrestrictedspell < 0) + if (card->hasType(Subtypes::TYPE_INSTANT) && this->castrestrictedspell > 0) continue; if (card->hasType(Subtypes::TYPE_LAND) && !this->canPutLandsIntoPlay) continue; @@ -1012,21 +1050,30 @@ int AIPlayerBaka::computeActions() if (castrestrictedcreature == 0 && nocreatureinstant == 0) { 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, "sorcery"); + } if (!nextCardToPlay) + { nextCardToPlay = FindCardToPlay(currentMana, "instant"); - + } + } } } - } if (potential) delete (currentMana); if (nextCardToPlay) diff --git a/projects/mtg/src/AllAbilities.cpp b/projects/mtg/src/AllAbilities.cpp index ab58a0efb..5ecf77ff9 100644 --- a/projects/mtg/src/AllAbilities.cpp +++ b/projects/mtg/src/AllAbilities.cpp @@ -1930,6 +1930,7 @@ AUpkeep::AUpkeep(int _id, MTGCardInstance * card, MTGAbility * a, ManaCost * _co ActivatedAbility(_id, card, _cost, restrictions, _tap), NestedAbility(a), phase(_phase), once(_once) { paidThisTurn = 0; + aType = MTGAbility::UPCOST; } void AUpkeep::Update(float dt)