You can simplify your setup and shuffling a lot:
To setup your basic deck, consider this:
The rank is sequence % 13, the suit is sequence / 13:
0 % 13 = 0 (rank zero), 0/13 = 0 (suit zero)
. . .
16 % 13 = 3 (rank three), 16/13 = 1 (suit 1)
. . .
51 % 13 = 12 (rank 12), 51/13 = 3 (suit 3)
so your ranks are 0 - 12, your suits are 0 - 3.
You can decide based on what you want, whether ace is zero or 12, depending on how you want to use it (low or high).
To shuffle, all you need to do is step one time, one-by-one, through your deck array, and use
1 2
|
for (i = 0; i < 52; i ++)
std::swap( card(i), card(rand() % 52);
|
(Make sure you srand(time(NULL)) somewhere early to initialize rand()
std::swap has a lot of overloads for a variety of data types; I've used it to swap vectors, int, char, etc. . .
Very handy for sorts, too, of course.