int MTGCardInstance::isInPlay(GameObserver* game) { for (int i = 0; i < 2; i++) { MTGGameZone * zone = game->players[i]->game->inPlay; if (zone->hasCard(this) && !isPhased) return 1; } return 0; }
int DiscardRandomCost::canPay() { MTGGameZone * z = target->controller()->game->hand; int nbcards = z->nb_cards; if (nbcards < 1) return 0; if (nbcards == 1 && z->hasCard(source)) return 0; return 1; }
int AIStats::receiveEvent(WEvent * event) { WEventDamage * e = dynamic_cast<WEventDamage *> (event); if (!e) return 0; //we take only Damage events into accountright now Damage * damage = e->damage; MTGGameZone * opponentZone = player->opponent()->game->inPlay; MTGCardInstance * card = damage->source; updateStatsCard(card, damage); //Auras on damage source can be the cause for (int i = 0; i < opponentZone->nb_cards; ++i) { MTGCardInstance * aura = opponentZone->cards[i]; if (aura->target == card) { updateStatsCard(aura, damage, STATS_AURA_MULTIPLIER); } } GameObserver * g = player->getObserver(); //Lords map<MTGCardInstance *, int> lords; for (size_t i = 1; i < g->mLayers->actionLayer()->mObjects.size(); i++) { //0 is not a mtgability...hackish MTGAbility * a = ((MTGAbility *) g->mLayers->actionLayer()->mObjects[i]); if (ALord * al = dynamic_cast<ALord*>(a)) { if (al->cards.find(card) != al->cards.end() && opponentZone->hasCard(al->source)) { lords[al->source] = 1; } } } if (size_t nb = lords.size()) { for (map<MTGCardInstance *, int>::iterator it = lords.begin(); it != lords.end(); ++it) { updateStatsCard(it->first, damage, STATS_LORD_MULTIPLIER / nb); } } stats.sort(compare_aistats); //this could be slow, if it is, let's run it only at the end of the turn return 1; }
void TestSuiteGame::assertGame() { mMutex.lock(); //compare the game state with the results char result[4096]; sprintf(result, "<h3>%s</h3>", filename.c_str()); Log(result); int error = 0; bool wasAI = false; if (observer->getCurrentGamePhase() != endState.phase) { sprintf(result, "<span class=\"error\">==phase problem. Expected [ %s ](%i), got [ %s ](%i)==</span><br />", Constants::MTGPhaseNames[endState.phase],endState.phase, Constants::MTGPhaseNames[observer->getCurrentGamePhase()], observer->getCurrentGamePhase()); Log(result); error++; } for (int i = 0; i < 2; i++) { TestSuiteAI * p = (TestSuiteAI *) (observer->players[i]); if (p->playMode == Player::MODE_AI) wasAI = true; if (p->life != endState.players[i]->life) { sprintf(result, "<span class=\"error\">==life problem for player %i. Expected %i, got %i==</span><br />", i, endState.players[i]->life, p->life); Log(result); error++; } if (p->poisonCount != endState.players[i]->poisonCount) { sprintf(result, "<span class=\"error\">==poison counter problem for player %i. Expected %i, got %i==</span><br />", i, endState.players[i]->poisonCount, p->poisonCount); Log(result); error++; } if (!p->getManaPool()->canAfford(endState.players[i]->getManaPool())) { sprintf(result, "<span class=\"error\">==Mana problem. Was expecting %i but got %i for player %i==</span><br />", endState.players[i]->getManaPool()->getConvertedCost(), p->getManaPool()->getConvertedCost(), i); Log(result); error++; } if (!endState.players[i]->getManaPool()->canAfford(p->getManaPool())) { sprintf(result, "<span class=\"error\">==Mana problem. Was expecting %i but got %i for player %i==</span><br />", endState.players[i]->getManaPool()->getConvertedCost(), p->getManaPool()->getConvertedCost(), i); Log(result); if ( endState.players[i]->getManaPool()->getConvertedCost() == p->getManaPool()->getConvertedCost()) { sprintf(result, "<span class=\"error\">====(Apparently Mana Color issues since converted cost is the same)==</span><br />"); Log(result); } error++; } MTGGameZone * playerZones[] = { p->game->graveyard, p->game->library, p->game->hand, p->game->inPlay }; MTGGameZone * endstateZones[] = { endState.players[i]->game->graveyard, endState.players[i]->game->library, endState.players[i]->game->hand, endState.players[i]->game->inPlay }; for (int j = 0; j < 4; j++) { MTGGameZone * zone = playerZones[j]; if (zone->nb_cards != endstateZones[j]->nb_cards) { sprintf( result, "<span class=\"error\">==Card number not the same in player %i's %s==, expected %i, got %i</span><br />", i, zone->getName(), endstateZones[j]->nb_cards, zone->nb_cards); Log(result); error++; } for (size_t k = 0; k < (size_t)endstateZones[j]->nb_cards; k++) { MTGCardInstance* cardToCheck = (k<endstateZones[j]->cards.size())?endstateZones[j]->cards[k]:0; if(cardToCheck) { // Can be NULL if used "*" in the testcase. MTGCardInstance* card = Rules::getCardByMTGId(observer, cardToCheck->getId()); if (card != 0 && !zone->hasCard(card)) { sprintf(result, "<span class=\"error\">==Card ID not the same. Didn't find %i</span><br />", card->getId()); Log(result); error++; } } } } } handleResults(wasAI, error); if(!error) Log("<span class=\"success\">==Test Succesful !==</span>"); else Log("<span class=\"error\">==Test Failed !==</span>"); mMutex.unlock(); }