SHARE
TWEET

Untitled

a guest Dec 8th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <iostream>
  3. #include <math.h>
  4. #include <time.h>
  5. #include <stdlib.h>
  6. #include <conio.h>    // to getch
  7. #include <windows.h>  // to use malloc
  8.  
  9. #define SIZE 52
  10. #define HALF_SIZE 26
  11.  
  12. using namespace std;
  13.  
  14. typedef enum Suit { Diamonds, Hearts, Spades, Clubs } Suit_t;
  15. typedef enum Power { Two = 2, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King, Ace } Power_t;
  16.  
  17. typedef struct card {
  18.     Suit_t suit;
  19.     Power_t power;
  20. }cards;
  21.  
  22. typedef struct deck {   // alokacja struktury
  23.     cards* p_deck;
  24.     int size;
  25. }decks;
  26.  
  27. static int x = 1;
  28. int k;                                      // parametr ile górnych kart mają tworzyć
  29. void Deck_Creator(cards* deck) {            // od 5 do 13 == od 20 do 52
  30.     cards temp = {};                        // co 13 jest karta 2 (index 0)
  31.     for (int i = 0; i < SIZE - (4 * k); i++) {
  32.         deck[i].suit = (Suit)(i / (13-k));
  33.         deck[i].power = (Power)(i % (13-k));
  34.     }
  35. /*  for (int i = (SIZE - (4 * k)); i >= 0; i--) {
  36.         deck[i].suit = (Suit)(i / 13);
  37.         deck[i].power = (Power)(i % (13 - k));
  38.     } */
  39.  
  40.  
  41.  
  42.     //  deck[i].power = (Power)(i % 13);
  43.     //  temp.power = deck[i].power;
  44.     //  deck[i].power = deck[13 - i].power;
  45.     //  deck[13 - i].power = temp.power;
  46. }
  47.  
  48. void Display_Deck(cards* deck) {
  49.     for (int i = 0; i < SIZE - (4*k); i++) {
  50.  
  51.         if (deck[i].suit == Diamonds) {
  52.             cout << "Diamond ";
  53.         }
  54.         else if (deck[i].suit == Hearts) {
  55.             cout << "Heart ";
  56.         }
  57.         else if (deck[i].suit == Spades) {
  58.             cout << "Spade ";
  59.         }
  60.         else if (deck[i].suit == Clubs) {
  61.             cout << "Club ";
  62.         }
  63.         //if (deck[i].power >= 3) {
  64.             cout << " " << deck[i].power << " | ";
  65.         //}
  66.         //else cout
  67.     }
  68. }
  69.  
  70. void Deck_Shuffler(cards* deck) {
  71.     int changer = 0;               // Index of changed card
  72.     cards temp = {};             // Temporary holding place for changing
  73.     srand(time(NULL));            // Function to get random numbers with current time
  74.     for (int i = 0; i < SIZE; i++) {
  75.         changer = rand() % SIZE;   // Generating random number from 0 to 51
  76.         temp = deck[i];
  77.         deck[i] = deck[changer];  // if changer = i
  78.         deck[changer] = temp;
  79.     }
  80. }
  81.  
  82. void Deck1_Creator(cards* deck1, cards* deck, decks* q_deck1) {
  83.     for (int i = 0; i < HALF_SIZE; i++) {
  84.         memcpy(&deck1[i], &deck[i], sizeof(cards));  // Copying content using memcpy function
  85.     }
  86.     q_deck1->p_deck = deck1;
  87.     q_deck1->size = HALF_SIZE;
  88. }
  89.  
  90. void Deck2_Creator(cards* deck, cards* deck2, decks* q_deck2) {
  91.     int i = HALF_SIZE;
  92.     for (int i = 26; i < SIZE; i++) {
  93.         deck2[i - HALF_SIZE] = deck[i];   // Simple copying struct array content into another array
  94.     }
  95.     q_deck2->p_deck = deck2;
  96.     q_deck2->size = HALF_SIZE;
  97. }
  98.  
  99. void table_creator(decks* q_deck, cards* array) {
  100.  
  101.     q_deck->p_deck = array;
  102.     q_deck->size = 0;
  103. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top