void Deck::shuffleDeck() { for (int i = 0; i < TOTAL_NUM_CARDS; ++i) { int swap_i = getRandomNumber(0, TOTAL_NUM_CARDS - 1); swapCard(m_deck[i], m_deck.at(swap_i)); } m_top_card_i = 0; }
// Shuffle the deck using a seed void Deck::shuffle(int seed) { static std::mt19937 rng(seed); int n = 52; while ( n > 1 ) { int k = (int) (rng() % n); --n; swapCard(n, k); } }
/** * Shuffles a deck. * @param deck pointer to first card in a deck */ void shuffleDeck(struct card * deck) { srand(time(NULL)); //Generate seed //Fisher-Yates shuffling algorithm int i; for (i = NUMCARDS - 1; i > 0; i--) { //Pick random index from 0 to i int j = rand() % (i + 1); //Swap deck[i] with the element at random index swapCard(&deck[i], &deck[j]); } }
/** * Takes a hand and sorts it by increasing card value. * @param numCards number of cards in each hand * @param cards the cards array */ void sortHand(int numCards, struct card * cards) { int i, j; for (j = 0; j < numCards - 1; j++) { /* assume first is smallest */ int min = j; /* test against next elements */ for (i = j + 1; i < numCards; i++) { /* if element is smaller, set to small */ if (cards[i].value < cards[min].value) { min = i; } } if (min != j) { swapCard(&cards[j], &cards[min]); } } }