Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- #include <time.h>
- using namespace std;
- #define COLOR_NUM 4
- #define TYPE_NUM 13
- #define DECKSIZE 52
- #define HANDSIZE 26
- typedef enum // enum for colors of cards
- {
- DIAMONDS,
- HEARTS,
- SPADES,
- CLUBS
- }card_color_t;
- const card_color_t CARDCOLORS[COLOR_NUM] =
- {
- DIAMONDS,
- HEARTS,
- SPADES,
- CLUBS
- };
- typedef enum // enum for types of cards
- {
- TWO,
- THREE,
- FOUR,
- FIVE,
- SIX,
- SEVEN,
- EIGHT,
- NINE,
- TEN,
- JACK,
- QUEEN,
- KING,
- ACE
- }card_type_t;
- const card_type_t CARDTYPES[TYPE_NUM] =
- {
- TWO,
- THREE,
- FOUR,
- FIVE,
- SIX,
- SEVEN,
- EIGHT,
- NINE,
- TEN,
- JACK,
- QUEEN,
- KING,
- ACE
- };
- typedef struct //structure binding both colors and types together
- {
- card_type_t type;
- card_color_t color;
- }card_t;
- card_t deck[DECKSIZE];
- string cardtypenames[13] = {
- "TWO",
- "THREE",
- "FOUR",
- "FIVE",
- "SIX",
- "SEVEN",
- "EIGHT",
- "NINE",
- "TEN",
- "JACK",
- "QUEEN",
- "KING",
- "ACE"
- };
- string cardcolornames[4] =
- {
- "DIAMONDS",
- "HEARTS",
- "SPADES",
- "CLUBS"
- };
- string getcardtypename(card_t card)
- {
- return cardtypenames[card.type]; //it enables to print out the type instead of the numerical value representing each type.
- }
- string getcardcolorname(card_t card)
- {
- return cardcolornames[card.color]; //it enables to print out the color instead of the numerical value representing each color.
- }
- int main()
- {
- srand(time(NULL));
- int c, t, i;
- for (t = 0, i = 0; t < TYPE_NUM; t++) // building the deck
- {
- for (c = 0; c < COLOR_NUM; c++, i++)
- {
- deck[i].color = CARDCOLORS[c];
- deck[i].type = CARDTYPES[t];
- }
- }
- int randomcard;
- for (i = 0; i < DECKSIZE; i++) //shuffling the deck
- {
- randomcard = rand() % DECKSIZE;
- swap(deck[i], deck[randomcard]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement