Implemented Fisher–Yates shuffle. Assumes RNG function is in form getNumber(min,max), with min and max inclusive (Did not find documentation on function)

This commit is contained in:
Musty Mustelidae 2014-03-07 09:09:56 -05:00 committed by Name
parent ed5f02bf7a
commit 2ad09399f4

View file

@ -43,14 +43,14 @@ Server_CardZone::~Server_CardZone()
void Server_CardZone::shuffle()
{
QList<Server_Card *> temp;
for (int i = cards.size(); i; i--)
temp.append(cards.takeAt(rng->getNumber(0, i - 1)));
cards = temp;
for (int i = cards.size() - 1; i > 0; i--){
int j = rng->getNumber(0, i);//Assuming i is inclusive, i + 1 if exclusive (end result should be a number between 0 and i [0 and i included])
cards.swap(j,i)
}
playersWithWritePermission.clear();
}
void Server_CardZone::removeCardFromCoordMap(Server_Card *card, int oldX, int oldY)
{
if (oldX < 0)