date:1.2
Use Srand () before Rand ()?
Use: Different random numbers per generation
Not used: The same random number generated each time
- #include "stdafx.h"
- #include <time.h>
- #include <stdlib.h>
- #define SUITS 4
- #define FACES
- #define CARDS
- void Shuffle (unsigned int wdeck[][faces]) // Shuffle Deck represents a Deck of Cards
- {
- For (size_t card = 1; card <= CARDS; card++)
- {
- size_t Row;
- size_t column;
- Do {
- row = rand ()% suits;
- column = rand ()% FACES;
- } while (wdeck[row][column]! = 0);
- Wdeck[row][column] = card;
- }
- }
- void deal (unsigned int wdeck[][faces], const char *wface[], const char *wsuit[])
- {
- For (size_t card = 1; card < CARDS; card++)
- {
- For (size_t row = 0; row < suits; row++)
- {
- For (size_t column = 0; column < FACES; column++)
- {
- if (wdeck[row][column] = = Card) {
- printf ("%5s of%-8s%c", Wface[column], Wsuit[row], card% 2 = = 0? ' \ n ' : ' \ t ');
- }
- }
- }
- }
- }
- int Main ()
- {
- unsigned int deck[suits][faces];
- memset (deck, 0, sizeof(deck));
- Srand (Time (NULL));
- Shuffle (deck); // Shuffle
- const char *suit[suits] = { " Red Peach ", " square " ," plum "," Span style= "font-family: Arial" > spades " };
- const char *face[faces] = { "Ace" , "Deuce" ," three " ," Four " ," Five " , "Six" , "Seven" , "Eight" , < Span style= "COLOR: #5c5c5c" >
- "Nine","Ten","Jack","Queen","King" };
- deal (deck, face, suit); // Licensing
- GetChar ();
- return 0;
- }
The algorithm is defective (deal () function if there is a wdeck[row][column] = = Card loop will continue), and then improved.
Array of pointers and shuffle and licensing of poker