Most Common Color

This commit is contained in:
Anthony Calosa
2016-06-16 18:14:48 +08:00
parent eaf7b72dc7
commit 68b632857d
3 changed files with 105 additions and 45 deletions

View File

@@ -425,6 +425,26 @@ private:
{
intValue = card->imprintW;
}
else if (s == "commongreen")
{
intValue = mostCommonColor(Constants::MTG_COLOR_GREEN, card);
}
else if (s == "commonblue")
{
intValue = mostCommonColor(Constants::MTG_COLOR_BLUE, card);
}
else if (s == "commonred")
{
intValue = mostCommonColor(Constants::MTG_COLOR_RED, card);
}
else if (s == "commonblack")
{
intValue = mostCommonColor(Constants::MTG_COLOR_BLACK, card);
}
else if (s == "commonwhite")
{
intValue = mostCommonColor(Constants::MTG_COLOR_WHITE, card);
}
else if (s == "targetedcurses")
{
if(card->playerTarget)
@@ -775,6 +795,36 @@ public:
return count;
}
int countCardsInPlaybyColor(int color, GameObserver * observer)
{
int count = 0;
for (int i = 0; i < 2; i++)
{
for( int j= 0; j < observer->players[i]->inPlay()->nb_cards; j++)
if(observer->players[i]->inPlay()->cards[j]->hasColor(color))
count += 1;
}
return count;
}
int mostCommonColor(int color, MTGCardInstance * card)
{
int maxColor = 0;
vector<int> colors;
for(int i = 1; i < 6; i++)
colors.push_back( countCardsInPlaybyColor(i, card->getObserver()) );
for(int j = 0; j < 5; j++)
if ( colors[j] > maxColor )
maxColor = colors[j];
if (countCardsInPlaybyColor(color, card->getObserver()) >= maxColor && maxColor > 0)
return 1;
return 0;
}
int countCardTypeinZone(string type, MTGGameZone * zone)
{
int count = 0;