Replaced unnecessary custom shuffle methods with std::random_shuffle<>.

This commit is contained in:
wrenczes@gmail.com
2011-02-05 06:25:25 +00:00
parent f6bef26243
commit a0a3c59b29
2 changed files with 2 additions and 32 deletions
+1 -8
View File
@@ -574,14 +574,7 @@ void MTGGameZone::cleanupPhase()
void MTGGameZone::shuffle() void MTGGameZone::shuffle()
{ {
int i; std::random_shuffle(cards.begin(), cards.end());
for (i = 0; i < (nb_cards); i++)
{
int r = i + (WRand() % (nb_cards - i)); // Random remaining position.
MTGCardInstance * temp = cards[i];
cards[i] = cards[r];
cards[r] = temp;
}
} }
void MTGGameZone::addCard(MTGCardInstance * card) void MTGGameZone::addCard(MTGCardInstance * card)
+1 -24
View File
@@ -284,30 +284,7 @@ bool WSrcCards::setOffset(int pos)
void WSrcCards::Shuffle() void WSrcCards::Shuffle()
{ {
vector<MTGCard*> a; std::random_shuffle(cards.begin(), cards.end());
MTGCard * temp;
vector<MTGCard*>::iterator k;
while (cards.size())
{
k = cards.begin();
k += rand() % cards.size();
temp = *k;
cards.erase(k);
a.push_back(temp);
}
#if defined WIN32 || defined LINUX //PC performs a double shuffle for less streaking.
while(a.size())
{
k = a.begin();
k += rand() % a.size();
temp = *k;
a.erase(k);
cards.push_back(temp);
}
#else //PSP does a straight swap for speed.
cards.swap(a);
#endif
validate(); validate();
} }