Advertisement
mishappp

Untitled

Dec 8th, 2014
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.92 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3.  
  4. using namespace std;
  5.  
  6. enum CardSuit { SPADES, HEARTS, CLUBS, DIAMONDS };
  7. enum CardRank { ACE, KING, QUEEN, JACK, TEN, NINE, EIGHT, SEVEN, SIX, FIVE, FOUR, THREE, TWO };
  8. int Split = 26;
  9.  
  10. struct Card
  11. {
  12.         CardSuit suit;
  13.         CardRank rank;
  14.         Card* next;
  15.         Card* previous;
  16. };
  17.  
  18. bool noCards(Card* head);
  19. bool Deal(Card*, string[], string[]);
  20. Card* CreateDeck(Card*, Card*, Card*);
  21. Card* DeckSplit(Card*, Card*);
  22.  
  23. int main()
  24. {
  25.         // Function prototypes
  26.        
  27.  
  28.         // String arrays to print card suit and rank.
  29.         const int SuitAmount = 4;
  30.         const int RankAmount = 13;
  31.         string SuitNames[SuitAmount] = { "Spades", "Hearts", "Clubs", "Diamonds" };
  32.         string RankNames[RankAmount] = { "Ace", "King", "Queen", "Jack", "Ten", "Nine", "Eight", "Seven", "Six", "Five", "Four", "Three", "Two" };
  33.  
  34.         Card* head = nullptr;
  35.         Card* tail = nullptr;
  36.         Card* newNode = nullptr;
  37.  
  38.         head = CreateDeck(head, tail, newNode);
  39.         Deal(head, SuitNames, RankNames);
  40. }
  41.  
  42. Card* CreateDeck(Card* head, Card* tail, Card* newNode)
  43. {
  44.         bool FirstPass = true;
  45.  
  46.         for (int i = 0, SuitCounter = 0, RankCounter = 0; i < 52; i++, RankCounter++)
  47.         {
  48.                 if (FirstPass == true)
  49.                 {
  50.                         newNode = new Card;
  51.                         newNode->suit = static_cast<CardSuit>(SuitCounter);
  52.                         newNode->rank = static_cast<CardRank>(RankCounter);
  53.                         newNode->previous = NULL;
  54.                         head = newNode;
  55.                         tail = newNode;
  56.                         FirstPass = false;
  57.                         RankCounter++;
  58.                         i++;
  59.                 }
  60.                 if (RankCounter > 12)
  61.                 {
  62.                         RankCounter = 0;
  63.                         SuitCounter++;
  64.                 }
  65.  
  66.  
  67.                 newNode = new Card;
  68.                 newNode->suit = static_cast<CardSuit>(SuitCounter);
  69.                 newNode->rank = static_cast<CardRank>(RankCounter);
  70.                 newNode->previous = tail;
  71.                 tail->next = newNode;
  72.                 tail = newNode;
  73.                 if (SuitCounter == 3 && RankCounter > 11)
  74.                         tail->next = NULL;
  75.  
  76.         }
  77.         DeckSplit(head, tail);
  78.         return(head);
  79.  
  80. }
  81.  
  82. bool Deal(Card* head, string SuitNames[], string RankNames[])
  83. {
  84.  
  85.         if (head == NULL)
  86.                 return(false);
  87.  
  88.         while (head != NULL)
  89.         {
  90.                 cout << RankNames[head->rank] << " Of " << SuitNames[head->suit] << "\n";
  91.                 head = head->next;
  92.         }
  93.  
  94.         return(true);
  95. }
  96.  
  97. Card* DeckSplit(Card* head, Card* tail)
  98. {
  99.         for (int i = 0; i < Split; i++)
  100.                 head = head->next;
  101.  
  102.         head = tail;
  103.         return(head);
  104.        
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement