Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. using namespace std;
  5. #define COLOR_NUM 4
  6. #define TYPE_NUM 13
  7. #define DECKSIZE 52
  8. #define HANDSIZE 26
  9. typedef enum // enum for colors of cards
  10. {
  11. DIAMONDS,
  12. HEARTS,
  13. SPADES,
  14. CLUBS
  15. }card_color_t;
  16. const card_color_t CARDCOLORS[COLOR_NUM] =
  17. {
  18. DIAMONDS,
  19. HEARTS,
  20. SPADES,
  21. CLUBS
  22. };
  23. typedef enum // enum for types of cards
  24. {
  25. TWO,
  26. THREE,
  27. FOUR,
  28. FIVE,
  29. SIX,
  30. SEVEN,
  31. EIGHT,
  32. NINE,
  33. TEN,
  34. JACK,
  35. QUEEN,
  36. KING,
  37. ACE
  38. }card_type_t;
  39. const card_type_t CARDTYPES[TYPE_NUM] =
  40. {
  41. TWO,
  42. THREE,
  43. FOUR,
  44. FIVE,
  45. SIX,
  46. SEVEN,
  47. EIGHT,
  48. NINE,
  49. TEN,
  50. JACK,
  51. QUEEN,
  52. KING,
  53. ACE
  54. };
  55. typedef struct //structure binding both colors and types together
  56. {
  57. card_type_t type;
  58. card_color_t color;
  59. }card_t;
  60. card_t deck[DECKSIZE];
  61. string cardtypenames[13] = {
  62. "TWO",
  63. "THREE",
  64. "FOUR",
  65. "FIVE",
  66. "SIX",
  67. "SEVEN",
  68. "EIGHT",
  69. "NINE",
  70. "TEN",
  71. "JACK",
  72. "QUEEN",
  73. "KING",
  74. "ACE"
  75. };
  76. string cardcolornames[4] =
  77. {
  78. "DIAMONDS",
  79. "HEARTS",
  80. "SPADES",
  81. "CLUBS"
  82. };
  83. string getcardtypename(card_t card)
  84. {
  85. return cardtypenames[card.type]; //it enables to print out the type instead of the numerical value representing each type.
  86. }
  87. string getcardcolorname(card_t card)
  88. {
  89. return cardcolornames[card.color]; //it enables to print out the color instead of the numerical value representing each color.
  90. }
  91. int main()
  92. {
  93. srand(time(NULL));
  94. int c, t, i;
  95. for (t = 0, i = 0; t < TYPE_NUM; t++) // building the deck
  96. {
  97. for (c = 0; c < COLOR_NUM; c++, i++)
  98. {
  99. deck[i].color = CARDCOLORS[c];
  100. deck[i].type = CARDTYPES[t];
  101. }
  102. }
  103. int randomcard;
  104. for (i = 0; i < DECKSIZE; i++) //shuffling the deck
  105. {
  106. randomcard = rand() % DECKSIZE;
  107. swap(deck[i], deck[randomcard]);
  108. }
  109.  
  110. return 0;
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement