dimanche 3 mai 2015

Rearranging objects in array in C++

I'm making a card shuffling function for the card game. I created an array of Card objects. Then I tried to rearrange the objects in the array using random_shuffle. But it doesn't work. What am I doing wrong?

char faces[13] = { '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A' };
char suits[4] = { char(3), char(4), char(5), char(6) };
int values[13] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 11 };

Card** deck = new Card*[52];

for (int row = 0; row <= 3; row++)
{
    for (int column = 0; column <= 12; column++)
    {
        deck[Card::getCounter()] = new Card(suits[row], faces[column], values[column], true);
    }
}
int size = sizeof(deck) / sizeof(deck[0]);
random_shuffle(*deck, *deck + size);




Aucun commentaire:

Enregistrer un commentaire