New game modes, bug fixes in primitives, improving AI, new planeswalkers type rule

New rules based on vanguard, 3 new random game modes, one is tribal and one uses any card in the game.

Several corrections and bugs fixes. Cards with x in their cost and that can target any player used to crash the game.

Teaching AI new things and changing values of efficiency.

You can have multiple "Jace" planeswalkers, you can't have two of the exact same name (no two Jace, the mind sculptor).
This commit is contained in:
Eduardo
2019-04-14 19:57:01 -05:00
parent 6eca5bea2f
commit ab1fbaa806
19 changed files with 623 additions and 3894 deletions

View File

@@ -46,14 +46,15 @@ int OrderedAIAction::getEfficiency(AADamager * aad)
return 0;
}
if(p == target->controller())
return 0;
if(p && target)
if(p == target->controller())
return 0;
if (dTarget && aad && (aad->getDamage() >= dTarget->toughness))
return 100;
if (dTarget && dTarget->toughness)
return (50 * aad->getDamage()) / dTarget->toughness;
return (10 * aad->getDamage()) / dTarget->toughness; // Don't waste damage spells
return 0;
}
@@ -129,8 +130,12 @@ int OrderedAIAction::getEfficiency()
{
efficiency = 95;
}
//TODO If the card is the target of a damage spell
break;
//TODO If the card is the target of a damage spell
if (!coreAbilityCardTarget->regenerateTokens && (MTGCardInstance*)target == a->source)
{
efficiency = 95;
}
break;
}
case MTGAbility::STANDARD_PREVENT:
{
@@ -271,7 +276,7 @@ int OrderedAIAction::getEfficiency()
}
case MTGAbility::STANDARD_PUMP:
{
efficiency = 0;
efficiency = 0;
if(!coreAbilityCardTarget)
break;
if(!target && !dynamic_cast<ALord*> (a) && (((MTGCardInstance *)a->source)->hasSubtype(Subtypes::TYPE_AURA) || ((MTGCardInstance *)a->source)->hasSubtype(Subtypes::TYPE_EQUIPMENT)))
@@ -291,9 +296,9 @@ int OrderedAIAction::getEfficiency()
int suggestion = af.abilityEfficiency(a, p, MODE_ABILITY);
//i do not set a starting eff. on this ability, this allows Ai to sometimes randomly do it as it normally does.
int currentPhase = g->getCurrentGamePhase();
if ((currentPhase == MTG_PHASE_COMBATBLOCKERS) || (currentPhase == MTG_PHASE_COMBATATTACKERS))
if (suggestion == BAKA_EFFECT_GOOD && target->controller() == p)
{
if (suggestion == BAKA_EFFECT_GOOD && target->controller() == p)
if ((currentPhase == MTG_PHASE_COMBATBLOCKERS) || (currentPhase == MTG_PHASE_COMBATATTACKERS))
{
if(coreAbilityCardTarget->defenser || coreAbilityCardTarget->blockers.size())
{
@@ -315,6 +320,10 @@ int OrderedAIAction::getEfficiency()
efficiency -= coreAbilityCardTarget->power;//we don't need to go overboard. better to not put all your eggs in a single basket.
}
}
if (currentPhase == MTG_PHASE_FIRSTMAIN)
{
efficiency = 10;
}
}
if (suggestion == BAKA_EFFECT_BAD && target->controller() != p && target->toughness > 0)
{
@@ -326,28 +335,41 @@ int OrderedAIAction::getEfficiency()
{
if(!coreAbilityCardTarget)
break;
// It used to skip most effects, with no other condition efficiency is -1
// Becomes is generally good so setting a value, but don't want to spam it
if (coreAbilityCardTarget && !coreAbilityCardTarget->isLand())
{
// Bonus if almost no cards in hand
if (p->game->hand->nb_cards <= 1)
{
efficiency = 60;
}
else efficiency = 30;
}
//nothing huge here, just ensuring that Ai makes his noncreature becomers into creatures during first main, so it can actually use them in combat.
if (coreAbilityCardTarget && !coreAbilityCardTarget->isCreature() && currentPhase == MTG_PHASE_FIRSTMAIN)
{
efficiency = 100;
}
efficiency = 60;
}
break;
}
case MTGAbility::MANA_PRODUCER://only way to hit this condition is nested manaabilities, ai skips manaproducers by defualt when finding an ability to use.
{
AManaProducer * manamaker = dynamic_cast<AManaProducer*>(a);
GenericActivatedAbility * GAA = dynamic_cast<GenericActivatedAbility*>(ability);
AForeach * forMana = dynamic_cast<AForeach*>(GAA->ability);
if (manamaker && forMana)
{
int outPut = forMana->checkActivation();
if (ability->getCost() && outPut > int(ability->getCost()->getConvertedCost() +1) && currentPhase == MTG_PHASE_FIRSTMAIN && ability->source->controller()->game->hand->nb_cards > 1)
efficiency = 90;//might be a bit random, but better than never using them.
}
else
efficiency = 0;
break;
AManaProducer * manamaker = dynamic_cast<AManaProducer*>(a);
GenericActivatedAbility * GAA = dynamic_cast<GenericActivatedAbility*>(ability);
if(GAA)
{
AForeach * forMana = dynamic_cast<AForeach*>(GAA->ability);
if (manamaker && forMana)
{
int outPut = forMana->checkActivation();
if (ability->getCost() && outPut > int(ability->getCost()->getConvertedCost() +1) && currentPhase == MTG_PHASE_FIRSTMAIN && ability->source->controller()->game->hand->nb_cards > 1)
efficiency = 60;//might be a bit random, but better than never using them.
}
}
else
efficiency = 0;
break;
}
case MTGAbility::STANDARDABILITYGRANT:
{
@@ -426,11 +448,12 @@ int OrderedAIAction::getEfficiency()
case MTGAbility::LIFER:
{
//use life abilities whenever possible.
//use life abilities whenever possible. Well yes, but actually no
//limits mana and in case of Zuran Orb it just sacrifices all lands
AALifer * alife = (AALifer *) a;
Targetable * _t = alife->getTarget();
efficiency = 100;
efficiency = 80;
AbilityFactory af(g);
int suggestion = af.abilityEfficiency(a, p, MODE_ABILITY);
@@ -566,6 +589,12 @@ int OrderedAIAction::getEfficiency()
{
if (z == p->game->hand)
efficiency = 10 + (owner->getRandomGenerator()->random() % 10);//random chance to bounce their own card;
}
// We don't want to return cards in play to own hand, save rare combos
else if(target->currentZone == p->game->inPlay)
{
if (z == p->game->hand || z == p->game->library)
efficiency = (owner->getRandomGenerator()->random() % 10);//random chance to bounce their own card;
}
else
{
@@ -574,7 +603,11 @@ int OrderedAIAction::getEfficiency()
}
else
{
efficiency = 50;
// We don't want to return the ability source cards in play to own hand, save rare combos
// cards like Blinking Spirit use to be auto lose for AI
if(z == p->game->hand || z == p->game->library)
efficiency = 1;
else efficiency = 50;
//may abilities target the source until thier nested ability is activated, so 50% chance to use this
//mover, until we can come up with something more elegent....
}
@@ -639,7 +672,7 @@ int OrderedAIAction::getEfficiency()
{
AIPlayer * chk = (AIPlayer*)p;
if(may->ability && may->ability->getActionTc() && chk->chooseTarget(may->ability->getActionTc(),NULL,NULL,true))
efficiency = 50 + (owner->getRandomGenerator()->random() % 50);
efficiency = 80 + (owner->getRandomGenerator()->random() % 50);
}
if (p->game->hand->nb_cards == 0)
efficiency = (int) ((float) efficiency * 1.3); //increase chance of using ability if hand is empty
@@ -666,13 +699,18 @@ int OrderedAIAction::getEfficiency()
}
else if (dynamic_cast<MTGAlternativeCostRule *>(a))
{
efficiency += 55;
efficiency += 65;
}
else if (dynamic_cast<MTGSuspendRule *>(a))
{
efficiency += 55;
}
SAFE_DELETE(transAbility);
if (ability->source)
if(ability->source->hasType(Subtypes::TYPE_PLANESWALKER))
efficiency += 50;
SAFE_DELETE(transAbility);
return efficiency;
}
@@ -944,7 +982,7 @@ int OrderedAIAction::getRevealedEfficiency(MTGAbility * ability2)
//nothing huge here, just ensuring that Ai makes his noncreature becomers into creatures during first main, so it can actually use them in combat.
if (coreAbilityCardTarget && !coreAbilityCardTarget->isCreature() && currentPhase == MTG_PHASE_FIRSTMAIN)
{
eff2 = 100;
eff2 = 70;
}
break;
}
@@ -957,7 +995,7 @@ int OrderedAIAction::getRevealedEfficiency(MTGAbility * ability2)
{
int outPut = forMana->checkActivation();
if (ability2->getCost() && outPut > int(ability2->getCost()->getConvertedCost() +1) && currentPhase == MTG_PHASE_FIRSTMAIN && ability2->source->controller()->game->hand->nb_cards > 1)
eff2 = 90;//might be a bit random, but better than never using them.
eff2 = 60;//might be a bit random, but better than never using them.
}
else
eff2 = 0;
@@ -2447,11 +2485,10 @@ int AIPlayerBaka::getEfficiency(MTGAbility * ability)
int AIPlayerBaka::selectMenuOption()
{
ActionLayer * object = observer->mLayers->actionLayer();
int doThis = -1;
int doThis = 0; // The AI just passes on things if set to -1, getEfficiency should be improved
if (object->menuObject)
{
int checkedLast = 0;
if(object->abilitiesMenu->isMultipleChoice && object->currentActionCard)
{
MenuAbility * currentMenu = NULL;
@@ -2510,7 +2547,7 @@ MTGCardInstance * AIPlayerBaka::FindCardToPlay(ManaCost * pMana, const char * ty
{
nextCardToPlay = comboCards.back();
gotPayments.clear();
if((!pMana->canAfford(nextCardToPlay->getManaCost()) || nextCardToPlay->getManaCost()->getKicker()))
if((!pMana->canAfford(nextCardToPlay->getManaCost()) || nextCardToPlay->getManaCost()->getKicker() || nextCardToPlay->getManaCost()->getBestow()))
gotPayments = canPayMana(nextCardToPlay,nextCardToPlay->getManaCost());
DebugTrace("ai is doing a combo:" << nextCardToPlay->getName());
comboCards.pop_back();
@@ -2524,11 +2561,26 @@ MTGCardInstance * AIPlayerBaka::FindCardToPlay(ManaCost * pMana, const char * ty
card = NULL;
gotPayments = vector<MTGAbility*>();
//canplayfromgraveyard
while ((card = cd.nextmatch(game->graveyard, card))&& card->has(Constants::CANPLAYFROMGRAVEYARD))
{
while ((card = cd.nextmatch(game->graveyard, card)))
{
bool hasFlashback = false;
if(card->getManaCost())
if(card->getManaCost()->getFlashback())
hasFlashback = true;
if( card->has(Constants::CANPLAYFROMGRAVEYARD) || card->has(Constants::TEMPFLASHBACK) || hasFlashback )
{
if (!CanHandleCost(card->getManaCost(),card))
continue;
if (hasFlashback && !CanHandleCost(card->getManaCost()->getFlashback(),card))
continue;
// Case were manacost is equal to flashback cost, if they are different the AI hangs
if (hasFlashback && (card->getManaCost() != card->getManaCost()->getFlashback()) )
continue;
if (card->hasType(Subtypes::TYPE_LAND))
{
if (game->playRestrictions->canPutIntoZone(card, game->inPlay) == PlayRestriction::CANT_PLAY)
@@ -2619,27 +2671,27 @@ MTGCardInstance * AIPlayerBaka::FindCardToPlay(ManaCost * pMana, const char * ty
}
else
{
int shouldPlay = effectBadOrGood(card);
if (shouldPlay == BAKA_EFFECT_GOOD)
// Refactor to not check effect of lands since it always returned BAKA_EFFECT_DONTKNOW
// If it is a land, play it
if (card->isLand())
{
shouldPlayPercentage = 90;
}
else if (BAKA_EFFECT_DONTKNOW == shouldPlay)
{
//previously shouldPlayPercentage = 80;, I found this a little to high
//for cards which AI had no idea how to use.
shouldPlayPercentage = 60;
}
else if (card->isLand())
{
shouldPlayPercentage = 90;
}
else
{
// shouldPlay == baka_effect_bad giving it a 1 for odd ball lottery chance.
shouldPlayPercentage = 1;
}
}
else {
int shouldPlay = effectBadOrGood(card);
if (shouldPlay == BAKA_EFFECT_GOOD) {
shouldPlayPercentage = 90;
}
else if (BAKA_EFFECT_DONTKNOW == shouldPlay) {
//previously shouldPlayPercentage = 80;, I found this a little to high
//for cards which AI had no idea how to use.
shouldPlayPercentage = 60;
}
else {
// shouldPlay == baka_effect_bad giving it a 10 for odd ball lottery chance.
shouldPlayPercentage = 10;
}
}
}
//Reduce the chances of playing a spell with X cost if available mana is low
if (hasX)
@@ -2677,6 +2729,7 @@ MTGCardInstance * AIPlayerBaka::FindCardToPlay(ManaCost * pMana, const char * ty
if (hasX)
maxCost = pMana->getConvertedCost();
}
}
}
//canplayfromexile
while ((card = cd.nextmatch(game->exile, card))&& card->has(Constants::CANPLAYFROMEXILE))
@@ -2774,27 +2827,27 @@ MTGCardInstance * AIPlayerBaka::FindCardToPlay(ManaCost * pMana, const char * ty
}
else
{
int shouldPlay = effectBadOrGood(card);
if (shouldPlay == BAKA_EFFECT_GOOD)
// Refactor to not check effect of lands since it always returned BAKA_EFFECT_DONTKNOW
// If it is a land, play it
if (card->isLand())
{
shouldPlayPercentage = 90;
}
else if (BAKA_EFFECT_DONTKNOW == shouldPlay)
{
//previously shouldPlayPercentage = 80;, I found this a little to high
//for cards which AI had no idea how to use.
shouldPlayPercentage = 60;
}
else if (card->isLand())
{
shouldPlayPercentage = 90;
}
else
{
// shouldPlay == baka_effect_bad giving it a 1 for odd ball lottery chance.
shouldPlayPercentage = 1;
}
}
else {
int shouldPlay = effectBadOrGood(card);
if (shouldPlay == BAKA_EFFECT_GOOD) {
shouldPlayPercentage = 90;
}
else if (BAKA_EFFECT_DONTKNOW == shouldPlay) {
//previously shouldPlayPercentage = 80;, I found this a little to high
//for cards which AI had no idea how to use.
shouldPlayPercentage = 60;
}
else {
// shouldPlay == baka_effect_bad giving it a 10 for odd ball lottery chance.
shouldPlayPercentage = 10;
}
}
}
//Reduce the chances of playing a spell with X cost if available mana is low
if (hasX)
@@ -2928,27 +2981,27 @@ MTGCardInstance * AIPlayerBaka::FindCardToPlay(ManaCost * pMana, const char * ty
}
else
{
int shouldPlay = effectBadOrGood(card);
if (shouldPlay == BAKA_EFFECT_GOOD)
// Refactor to not check effect of lands since it always returned BAKA_EFFECT_DONTKNOW
// If it is a land, play it
if (card->isLand())
{
shouldPlayPercentage = 90;
}
else if (BAKA_EFFECT_DONTKNOW == shouldPlay)
{
//previously shouldPlayPercentage = 80;, I found this a little to high
//for cards which AI had no idea how to use.
shouldPlayPercentage = 60;
}
else if (card->isLand())
{
shouldPlayPercentage = 90;
}
else
{
// shouldPlay == baka_effect_bad giving it a 1 for odd ball lottery chance.
shouldPlayPercentage = 1;
}
}
else {
int shouldPlay = effectBadOrGood(card);
if (shouldPlay == BAKA_EFFECT_GOOD) {
shouldPlayPercentage = 90;
}
else if (BAKA_EFFECT_DONTKNOW == shouldPlay) {
//previously shouldPlayPercentage = 80;, I found this a little to high
//for cards which AI had no idea how to use.
shouldPlayPercentage = 60;
}
else {
// shouldPlay == baka_effect_bad giving it a 10 for odd ball lottery chance.
shouldPlayPercentage = 10;
}
}
}
//Reduce the chances of playing a spell with X cost if available mana is low
if (hasX)