- deprecated the following keywords (see list below for new usage)
-- cantcreaturecast => auto=maxCast(creature)0
-- cantspellcast => auto=maxCast(*)0
-- onlyonecast => auto=maxCast(*)1 
-- bothcantcast => auto=maxCast(*)0 auto=maxCast(*)0 opponent
-- bothnocreature => auto=maxCast(creature)0 auto=maxCast(creature)0 opponent
-- oneboth => auto=maxCast(*)1 auto=maxCast(*)1 opponent

Strangely enough, I couldn't find most of these keywords in mtg.txt?

I also removed variables such as "spellCastedThisTurn" and stuff like that... now if you want to know how many spells were cast in one turn by a given player, use player->game->stack->seenThisTurn("*").
seenThisTurn can take a string representing a TargetChooser, or better, a TargetChooser.

I can't guarantee I didn't break anything, but the test suite passes and the AI seems to run ok
This commit is contained in:
wagic.the.homebrew@gmail.com
2011-02-13 11:23:51 +00:00
parent 8eac9c587e
commit 6b89899d1b
10 changed files with 75 additions and 242 deletions

View File

@@ -147,13 +147,13 @@ class Constants
CANTLOSE = 59, CANTLOSE = 59,
CANTLIFELOSE = 60, CANTLIFELOSE = 60,
CANTMILLLOSE = 61, CANTMILLLOSE = 61,
CANTCASTCREATURE = 62, SNOWWALK = 62,
CANTCAST = 63, NONBASICWALK = 63,
CANTCASTTWO = 64, STRONG = 64,
STORM = 65, STORM = 65,
BOTHCANTCAST = 66, PHASING = 66,
BOTHNOCREATURE = 67, SPLITSECOND = 67,
ONLYONEBOTH = 68, WEAK = 68,
AFFINITYARTIFACTS = 69, AFFINITYARTIFACTS = 69,
AFFINITYPLAINS = 70, AFFINITYPLAINS = 70,
AFFINITYFOREST = 71, AFFINITYFOREST = 71,
@@ -176,14 +176,11 @@ SNOWPLAINSWALK = 87,
SNOWMOUNTAINWALK = 88, SNOWMOUNTAINWALK = 88,
SNOWISLANDWALK = 89, SNOWISLANDWALK = 89,
SNOWSWAMPWALK = 90, SNOWSWAMPWALK = 90,
SNOWWALK = 91,
NONBASICWALK = 92,
STRONG = 93,
WEAK = 94,
PHASING = 95,
SPLITSECOND = 96,
NB_BASIC_ABILITIES = 97,
NB_BASIC_ABILITIES = 91,
RARITY_S = 'S', //Special Rarity RARITY_S = 'S', //Special Rarity

View File

@@ -97,7 +97,11 @@ class MTGGameZone {
int hasName(string value); int hasName(string value);
int hasColor(int value); //returns 1 if one of the cards in the zone has the color, 0 otherwise int hasColor(int value); //returns 1 if one of the cards in the zone has the color, 0 otherwise
int hasX(); int hasX();
int seenThisTurn(TargetChooser * tc); //How many cards matching a TargetChooser have been put in this zone during the turn
//How many cards matching a TargetChooser have been put in this zone during the turn
int seenThisTurn(TargetChooser * tc);
int seenThisTurn(string s);
void setOwner(Player * player); void setOwner(Player * player);
MTGCardInstance * lastCardDrawn; MTGCardInstance * lastCardDrawn;
static MTGGameZone * stringToZone(string zoneName, MTGCardInstance * source, MTGCardInstance * target); static MTGGameZone * stringToZone(string zoneName, MTGCardInstance * source, MTGCardInstance * target);

View File

@@ -28,14 +28,6 @@ public:
JQuadPtr mAvatar; JQuadPtr mAvatar;
int playMode; int playMode;
bool nomaxhandsize; bool nomaxhandsize;
int castedspellsthisturn;
bool onlyonecast;
int castcount;
bool castrestrictedcreature;
bool castrestrictedspell;
bool onlyoneboth;
bool bothrestrictedspell;
bool bothrestrictedcreature;
bool isPoisoned; bool isPoisoned;
MTGPlayerCards * game; MTGPlayerCards * game;
string deckFile; string deckFile;

View File

@@ -1211,20 +1211,21 @@ MTGCardInstance * AIPlayerBaka::FindCardToPlay(ManaCost * pMana, const char * ty
{ {
if (!CanHandleCost(card->getManaCost())) if (!CanHandleCost(card->getManaCost()))
continue; continue;
if (card->hasType(Subtypes::TYPE_CREATURE) && this->castrestrictedcreature && this->castrestrictedspell )
continue; if (card->hasType(Subtypes::TYPE_LAND))
if (card->hasType(Subtypes::TYPE_ENCHANTMENT) && this->castrestrictedspell ) {
continue; if (game->playRestrictions->canPutIntoZone(card, game->inPlay) == PlayRestriction::CANT_PLAY)
if (card->hasType(Subtypes::TYPE_ARTIFACT) && this->castrestrictedspell ) continue;
continue; }
if (card->hasType(Subtypes::TYPE_SORCERY) && this->castrestrictedspell ) else
continue; {
if (card->hasType(Subtypes::TYPE_INSTANT) && this->castrestrictedspell ) if (game->playRestrictions->canPutIntoZone(card, game->stack) == PlayRestriction::CANT_PLAY)
continue; continue;
if (card->hasType(Subtypes::TYPE_LAND) && (game->playRestrictions->canPutIntoZone(card, game->inPlay) == PlayRestriction::CANT_PLAY)) }
continue;
if (card->hasType(Subtypes::TYPE_LEGENDARY) && game->inPlay->findByName(card->name)) if (card->hasType(Subtypes::TYPE_LEGENDARY) && game->inPlay->findByName(card->name))
continue; continue;
int currentCost = card->getManaCost()->getConvertedCost(); int currentCost = card->getManaCost()->getConvertedCost();
int hasX = card->getManaCost()->hasX(); int hasX = card->getManaCost()->hasX();
if ((currentCost > maxCost || hasX) && pMana->canAfford(card->getManaCost())) if ((currentCost > maxCost || hasX) && pMana->canAfford(card->getManaCost()))
@@ -1329,22 +1330,19 @@ int AIPlayerBaka::computeActions()
//if theres mana i can use there then potential is true. //if theres mana i can use there then potential is true.
ipotential = true; ipotential = true;
} }
//look for an instant of ability to interupt with
if((castrestrictedspell == false)&&
(onlyonecast == false || castcount < 2))
{
if (!nextCardToPlay)
{ if (!nextCardToPlay)
nextCardToPlay = FindCardToPlay(icurrentMana, "instant"); {
if (game->playRestrictions->canPutIntoZone(nextCardToPlay, game->stack) == PlayRestriction::CANT_PLAY) nextCardToPlay = FindCardToPlay(icurrentMana, "instant");
nextCardToPlay = NULL; if (game->playRestrictions->canPutIntoZone(nextCardToPlay, game->stack) == PlayRestriction::CANT_PLAY)
} nextCardToPlay = NULL;
if (!nextCardToPlay)
{
selectAbility();
}
} }
if (!nextCardToPlay)
{
selectAbility();
}
if (icurrentMana != NULL) if (icurrentMana != NULL)
delete (icurrentMana); delete (icurrentMana);
if (nextCardToPlay) if (nextCardToPlay)
@@ -1380,26 +1378,23 @@ int AIPlayerBaka::computeActions()
} }
nextCardToPlay = FindCardToPlay(currentMana, "land"); nextCardToPlay = FindCardToPlay(currentMana, "land");
selectAbility(); selectAbility();
//look for the most expensive creature we can afford
if((castrestrictedspell == false)&& //look for the most expensive creature we can afford. If not found, try enchantment, then artifact, etc...
(onlyonecast == false || castcount < 2)) const char* types[] = {"creature", "enchantment", "artifact", "sorcery", "instant"};
int count = 0;
while (!nextCardToPlay && count < 5)
{ {
nextCardToPlay = FindCardToPlay(currentMana, types[count]);
const char* types[] = {"creature", "enchantment", "artifact", "sorcery", "instant"}; if (game->playRestrictions->canPutIntoZone(nextCardToPlay, game->stack) == PlayRestriction::CANT_PLAY)
int count = 0; nextCardToPlay = NULL;
while (!nextCardToPlay && count < 5) count++;
{
nextCardToPlay = FindCardToPlay(currentMana, types[count]);
if (game->playRestrictions->canPutIntoZone(nextCardToPlay, game->stack) == PlayRestriction::CANT_PLAY)
nextCardToPlay = NULL;
count++;
}
if (!nextCardToPlay)
{
selectAbility();
}
} }
if (!nextCardToPlay)
{
selectAbility();
}
if (currentMana != NULL) if (currentMana != NULL)
delete (currentMana); delete (currentMana);
if (nextCardToPlay) if (nextCardToPlay)

View File

@@ -108,9 +108,6 @@ void GameObserver::nextGamePhase()
if (currentGamePhase == Constants::MTG_PHASE_BEFORE_BEGIN) if (currentGamePhase == Constants::MTG_PHASE_BEFORE_BEGIN)
{ {
cleanupPhase(); cleanupPhase();
currentPlayer->castedspellsthisturn = 0;
currentPlayer->opponent()->castedspellsthisturn = 0;
currentPlayer->castcount = 0;
currentPlayer->damageCount = 0; currentPlayer->damageCount = 0;
currentPlayer->preventable = 0; currentPlayer->preventable = 0;
currentPlayer->isPoisoned = false; currentPlayer->isPoisoned = false;
@@ -519,8 +516,6 @@ void GameObserver::gameStateBasedEffects()
Player * p = players[i]; Player * p = players[i];
MTGGameZone * z = players[i]->game->inPlay; MTGGameZone * z = players[i]->game->inPlay;
int nbcards = z->nb_cards; int nbcards = z->nb_cards;
p->onlyonecast = false;
p->opponent()->onlyonecast = false;
//------------------------------ //------------------------------
if (z->hasAbility(Constants::NOMAXHAND)) if (z->hasAbility(Constants::NOMAXHAND))
{ {
@@ -530,79 +525,7 @@ void GameObserver::gameStateBasedEffects()
{ {
p->nomaxhandsize = false; p->nomaxhandsize = false;
} }
//------------------------------
if (z->hasAbility(Constants::CANTCASTCREATURE))
{
p->castrestrictedcreature = true;
}
else
{
p->castrestrictedcreature = false;
}
//------------------------------
if (z->hasAbility(Constants::CANTCAST))
{
p->castrestrictedspell = true;
}
else
{
p->castrestrictedspell = false;
}
//------------------------------
if (z->hasAbility(Constants::CANTCASTTWO))
{
p->onlyonecast = true;
}
else
{
p->onlyonecast = false;
}
//--------------------------------
if (z->hasAbility(Constants::BOTHCANTCAST))
{
p->bothrestrictedspell = true;
}
else
{
p->bothrestrictedspell = false;
}
//---------------------------------
if (z->hasAbility(Constants::BOTHNOCREATURE))
{
p->bothrestrictedcreature = true;
}
else
{
p->bothrestrictedcreature = false;
}
//-----------------------------------
if (z->hasAbility(Constants::ONLYONEBOTH))
{
p->onlyoneboth = true;
}
else
{
p->onlyoneboth = false;
}
//------------------------------------
if (players[0]->bothrestrictedcreature)
players[1]->castrestrictedcreature = true;
//------------------------------------
if (players[0]->bothrestrictedspell)
players[1]->castrestrictedspell = true;
//------------------------------------
if (players[0]->onlyoneboth)
players[1]->onlyoneboth = true;
//------------------------------------
if (players[1]->bothrestrictedcreature)
players[0]->castrestrictedcreature = true;
//------------------------------------
if (players[1]->bothrestrictedspell)
players[0]->castrestrictedspell = true;
//------------------------------------
if (players[1]->onlyoneboth)
players[0]->onlyoneboth = true;
//------------------------------------
///////////////////////////////////////////////// /////////////////////////////////////////////////
//handle end of turn effects while we're at it.// //handle end of turn effects while we're at it.//
///////////////////////////////////////////////// /////////////////////////////////////////////////
@@ -627,11 +550,6 @@ void GameObserver::gameStateBasedEffects()
c->wasDealtDamage = false; c->wasDealtDamage = false;
c->damageToController = false; c->damageToController = false;
c->damageToOpponent = false; c->damageToOpponent = false;
if (c->has(Constants::ONLYONEBOTH))
{
c->controller()->castcount = 0;
c->controller()->opponent()->castcount = 0;
}
} }
for (int t = 0; t < nbcards; t++) for (int t = 0; t < nbcards; t++)
@@ -668,11 +586,6 @@ void GameObserver::gameStateBasedEffects()
if (z->nb_cards == 0) if (z->nb_cards == 0)
{ {
p->nomaxhandsize = false; p->nomaxhandsize = false;
if (!p->bothrestrictedcreature && !p->opponent()->bothrestrictedcreature)
p->castrestrictedcreature = false;
if (!p->bothrestrictedspell && !p->opponent()->bothrestrictedspell)
p->castrestrictedspell = false;
p->onlyonecast = false;
} }
////////////////////////// //////////////////////////
// Check auras on a card// // Check auras on a card//

View File

@@ -65,7 +65,7 @@ int MTGAbility::allowedToCast(MTGCardInstance * card,Player * player)
return 0; return 0;
break; break;
case CASTED_A_SPELL: case CASTED_A_SPELL:
if(player->castedspellsthisturn < 1) if(player->game->stack->seenThisTurn("*") < 1)
return 0; return 0;
break; break;
case ONE_OF_AKIND: case ONE_OF_AKIND:

View File

@@ -89,13 +89,13 @@ const char* Constants::MTGBasicAbilities[] = {
"cantlose", "cantlose",
"cantlifelose", "cantlifelose",
"cantmilllose", "cantmilllose",
"cantcreaturecast", "snowlandwalk",
"cantspellcast", "nonbasiclandwalk",
"onlyonecast", "strong",//cant be blocked by creature with less power
"storm", "storm",
"bothcantcast", "phasing",
"bothnocreature", "split second",
"oneboth", "weak",//cant block creatures with more power
"affinityartifacts", "affinityartifacts",
"affinityplains", "affinityplains",
"affinityforests", "affinityforests",
@@ -117,13 +117,7 @@ const char* Constants::MTGBasicAbilities[] = {
"snowplainslandwalk", "snowplainslandwalk",
"snowmountainlandwalk", "snowmountainlandwalk",
"snowislandlandwalk", "snowislandlandwalk",
"snowswamplandwalk", "snowswamplandwalk"
"snowlandwalk",
"nonbasiclandwalk",
"strong",//cant be blocked by creature with less power
"weak",//cant block creatures with more power
"phasing",
"split second",
}; };
map<string,int> Constants::MTGBasicAbilitiesMap; map<string,int> Constants::MTGBasicAbilitiesMap;

View File

@@ -626,6 +626,15 @@ int MTGGameZone::seenThisTurn(TargetChooser * tc)
return count; return count;
} }
int MTGGameZone::seenThisTurn(string targetChooserDefinition)
{
TargetChooserFactory tcf;
TargetChooser *tc = tcf.createTargetChooser(targetChooserDefinition, NULL);
int result = seenThisTurn(tc);
delete(tc);
return result;
}
void MTGGameZone::cleanupPhase() void MTGGameZone::cleanupPhase()
{ {

View File

@@ -64,20 +64,6 @@ int MTGPutInPlayRule::isReactingToClick(MTGCardInstance * card, ManaCost * mana)
#ifdef WIN32 #ifdef WIN32
cost->Dump(); cost->Dump();
#endif #endif
if (player->castrestrictedspell)
{
return 0;
}
if (player->onlyonecast && player->castcount >= 1)
{
return 0;
}
if (player->castrestrictedcreature && card->hasType("creature"))
{
return 0;
}
//cost of card. //cost of card.
if (playerMana->canAfford(cost)) if (playerMana->canAfford(cost))
{ {
@@ -155,27 +141,15 @@ int MTGPutInPlayRule::reactToClick(MTGCardInstance * card)
{ {
spell = game->mLayers->stackLayer()->addSpell(copy, game->targetChooser, spellCost, payResult, 0); spell = game->mLayers->stackLayer()->addSpell(copy, game->targetChooser, spellCost, payResult, 0);
game->targetChooser = NULL; game->targetChooser = NULL;
player->castedspellsthisturn += 1;
player->opponent()->castedspellsthisturn += 1;
if (player->onlyonecast)
{
player->castcount += 1;
}
} }
else else
{ {
spell = game->mLayers->stackLayer()->addSpell(copy, NULL, spellCost, payResult, 0); spell = game->mLayers->stackLayer()->addSpell(copy, NULL, spellCost, payResult, 0);
player->castedspellsthisturn += 1;
player->opponent()->castedspellsthisturn += 1;
if (player->onlyonecast)
{
player->castcount += 1;
}
} }
if (card->has(Constants::STORM)) if (card->has(Constants::STORM))
{ {
int storm = player->castedspellsthisturn; int storm = player->game->stack->seenThisTurn("*");
ManaCost * spellCost = player->getManaPool(); ManaCost * spellCost = player->getManaPool();
for (int i = storm; i > 1; i--) for (int i = storm; i > 1; i--)
{ {
@@ -272,19 +246,6 @@ int MTGAlternativeCostRule::isReactingToClick(MTGCardInstance * card, ManaCost *
ManaCost * cost = card->getManaCost(); ManaCost * cost = card->getManaCost();
cost->Dump(); cost->Dump();
#endif #endif
if (player->castrestrictedspell && !card->hasType("land"))
{
return 0;
}
if (player->onlyonecast && player->castcount >= 1)
{
return 0;
}
if (player->castrestrictedcreature && card->hasType("creature"))
{
return 0;
}
//cost of card. //cost of card.
if (playerMana->canAfford(alternateManaCost)) if (playerMana->canAfford(alternateManaCost))
{ {
@@ -350,14 +311,10 @@ int MTGAlternativeCostRule::reactToClick(MTGCardInstance * card, ManaCost *alter
copy->alternateCostPaid[alternateCostType] = 1; copy->alternateCostPaid[alternateCostType] = 1;
Spell * spell = game->mLayers->stackLayer()->addSpell(copy, game->targetChooser, spellCost, alternateCostType, 0); Spell * spell = game->mLayers->stackLayer()->addSpell(copy, game->targetChooser, spellCost, alternateCostType, 0);
game->targetChooser = NULL; game->targetChooser = NULL;
player->castedspellsthisturn += 1;
player->opponent()->castedspellsthisturn += 1;
if (player->onlyonecast )
player->castcount += 1;
if (card->has(Constants::STORM)) if (card->has(Constants::STORM))
{ {
int storm = player->castedspellsthisturn; int storm = player->game->stack->seenThisTurn("*");
for (int i = storm; i > 1; i--) for (int i = storm; i > 1; i--)
{ {
game->mLayers->stackLayer()->addSpell(copy, NULL, playerMana, alternateCostType, 1); game->mLayers->stackLayer()->addSpell(copy, NULL, playerMana, alternateCostType, 1);
@@ -595,19 +552,6 @@ int MTGMorphCostRule::isReactingToClick(MTGCardInstance * card, ManaCost * mana)
#ifdef WIN32 #ifdef WIN32
cost->Dump(); cost->Dump();
#endif #endif
if (player->castrestrictedspell && !card->hasType("land"))
{
return 0;
}
if (player->onlyonecast && player->castcount >= 1)
{
return 0;
}
if (player->castrestrictedcreature && card->hasType("creature"))
{
return 0;
}
//cost of card. //cost of card.
if (morph && playerMana->canAfford(morph)) if (morph && playerMana->canAfford(morph))
{ {
@@ -672,13 +616,6 @@ int MTGMorphCostRule::reactToClick(MTGCardInstance * card)
copy->isMorphed = true; copy->isMorphed = true;
copy->power = 2; copy->power = 2;
copy->toughness = 2; copy->toughness = 2;
player->castedspellsthisturn += 1;
player->opponent()->castedspellsthisturn += 1;
if (player->onlyonecast)
{
player->castcount += 1;
}
if (!card->has(Constants::STORM)) if (!card->has(Constants::STORM))
{ {
copy->X = spell->computeX(copy); copy->X = spell->computeX(copy);

View File

@@ -13,14 +13,6 @@ Damageable(20)
deckFileSmall = fileSmall; deckFileSmall = fileSmall;
manaPool = NEW ManaPool(this); manaPool = NEW ManaPool(this);
nomaxhandsize = false; nomaxhandsize = false;
castedspellsthisturn = 0;
castrestrictedspell = false;
castrestrictedcreature = false;
bothrestrictedspell = false;
bothrestrictedcreature = false;
onlyoneboth = false;
onlyonecast = false;
castcount = 0;
poisonCount = 0; poisonCount = 0;
damageCount = 0; damageCount = 0;
preventable = 0; preventable = 0;