Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- using namespace std;
- enum CardSuit { SPADES, HEARTS, CLUBS, DIAMONDS };
- enum CardRank { ACE, KING, QUEEN, JACK, TEN, NINE, EIGHT, SEVEN, SIX, FIVE, FOUR, THREE, TWO };
- int Split = 26;
- struct Card
- {
- CardSuit suit;
- CardRank rank;
- Card* next;
- Card* previous;
- };
- bool noCards(Card* head);
- bool Deal(Card*, string[], string[]);
- Card* CreateDeck(Card*, Card*, Card*);
- Card* DeckSplit(Card*, Card*);
- int main()
- {
- // Function prototypes
- // String arrays to print card suit and rank.
- const int SuitAmount = 4;
- const int RankAmount = 13;
- string SuitNames[SuitAmount] = { "Spades", "Hearts", "Clubs", "Diamonds" };
- string RankNames[RankAmount] = { "Ace", "King", "Queen", "Jack", "Ten", "Nine", "Eight", "Seven", "Six", "Five", "Four", "Three", "Two" };
- Card* head = nullptr;
- Card* tail = nullptr;
- Card* newNode = nullptr;
- head = CreateDeck(head, tail, newNode);
- Deal(head, SuitNames, RankNames);
- }
- Card* CreateDeck(Card* head, Card* tail, Card* newNode)
- {
- bool FirstPass = true;
- for (int i = 0, SuitCounter = 0, RankCounter = 0; i < 52; i++, RankCounter++)
- {
- if (FirstPass == true)
- {
- newNode = new Card;
- newNode->suit = static_cast<CardSuit>(SuitCounter);
- newNode->rank = static_cast<CardRank>(RankCounter);
- newNode->previous = NULL;
- head = newNode;
- tail = newNode;
- FirstPass = false;
- RankCounter++;
- i++;
- }
- if (RankCounter > 12)
- {
- RankCounter = 0;
- SuitCounter++;
- }
- newNode = new Card;
- newNode->suit = static_cast<CardSuit>(SuitCounter);
- newNode->rank = static_cast<CardRank>(RankCounter);
- newNode->previous = tail;
- tail->next = newNode;
- tail = newNode;
- if (SuitCounter == 3 && RankCounter > 11)
- tail->next = NULL;
- }
- DeckSplit(head, tail);
- return(head);
- }
- bool Deal(Card* head, string SuitNames[], string RankNames[])
- {
- if (head == NULL)
- return(false);
- while (head != NULL)
- {
- cout << RankNames[head->rank] << " Of " << SuitNames[head->suit] << "\n";
- head = head->next;
- }
- return(true);
- }
- Card* DeckSplit(Card* head, Card* tail)
- {
- for (int i = 0; i < Split; i++)
- head = head->next;
- head = tail;
- return(head);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement