Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 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. card_t hand1[DECKSIZE / 2];
  62. card_t hand2[DECKSIZE / 2];
  63. int size1;
  64. int size2;
  65. size1 = DECKSIZE / 2;
  66. size2 = DECKSIZE / 2;
  67. int battle(hand1[].type, hand2[].type, &size1, &size2)
  68. {
  69. if (hand1[1].type > hand2[1].type)
  70. {
  71. size1--;
  72. size2++;
  73. hand1[size1].type=hand1[size1-1].type
  74. hand2[size2]=
  75.  
  76.  
  77. }
  78.  
  79. }
  80.  
  81. int main()
  82. {
  83. srand(time(NULL));
  84. int c, t, i;
  85. for (t = 0, i = 0; t < TYPE_NUM; t++) // building the deck
  86. {
  87. for (c = 0; c < COLOR_NUM; c++, i++)
  88. {
  89. deck[i].color = CARDCOLORS[c];
  90. deck[i].type = CARDTYPES[t];
  91. }
  92. }
  93.  
  94. int randomcard;
  95.  
  96. for (i = 0; i < DECKSIZE; i++) //shuffling the deck
  97. {
  98. randomcard = rand() % DECKSIZE;
  99. swap(deck[i], deck[randomcard]);
  100. }
  101.  
  102. for (int i = 0; i < DECKSIZE; i++)
  103. {
  104. randomcard = rand() % DECKSIZE;
  105. if (i % 2 == 0)
  106. {
  107. hand1[i / 2] = deck[i];
  108. }
  109. else
  110. {
  111. hand2[i / 2] = deck[i];
  112. }
  113. }
  114.  
  115.  
  116. return 0;
  117.  
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement