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];
- card_t hand1[DECKSIZE / 2];
- card_t hand2[DECKSIZE / 2];
- int size1;
- int size2;
- size1 = DECKSIZE / 2;
- size2 = DECKSIZE / 2;
- int battle(hand1[].type, hand2[].type, &size1, &size2)
- {
- if (hand1[1].type > hand2[1].type)
- {
- size1--;
- size2++;
- hand1[size1].type=hand1[size1-1].type
- hand2[size2]=
- }
- }
- 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]);
- }
- for (int i = 0; i < DECKSIZE; i++)
- {
- randomcard = rand() % DECKSIZE;
- if (i % 2 == 0)
- {
- hand1[i / 2] = deck[i];
- }
- else
- {
- hand2[i / 2] = deck[i];
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement