Guest User

Untitled

a guest
Dec 13th, 2014
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.84 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. enum CardSuit { SPADES, HEARTS, CLUBS, DIAMONDS };
  8. enum CardRank { ACE, KING, QUEEN, JACK, TEN, NINE, EIGHT, SEVEN, SIX, FIVE, FOUR, THREE, TWO };
  9.  
  10. struct Card
  11. {
  12.     CardSuit suit;
  13.     CardRank rank;
  14.     Card* next;
  15.     Card* previous;
  16. };
  17.  
  18. int main()
  19. {
  20.  
  21.     bool noCards(Card* head);
  22.     bool Deal(Card*, string[], string[]);
  23.     bool CreateDeck(Card*&, Card*&, Card*&);
  24.     bool Cut(Card*&, Card*&, int);
  25.     bool Shuffle(Card*&, Card*&, int);
  26.     //void Readinput(Card*&, Card*&, Card*, string[], string[], int);
  27.  
  28.  
  29.     int Split = 15;
  30.     int ShuffleAmnt = 1;
  31.  
  32.     const int SuitAmount = 4;
  33.     const int RankAmount = 13;
  34.     string SuitNames[SuitAmount] = { "Spades", "Hearts", "Clubs", "Diamonds" };
  35.     string RankNames[RankAmount] = { "Ace", "King", "Queen", "Jack", "Ten", "Nine", "Eight", "Seven", "Six", "Five", "Four", "Three", "Two" };
  36.  
  37.     Card* head = nullptr;
  38.     Card* tail = nullptr;
  39.     Card* newNode = nullptr;
  40.  
  41.     CreateDeck(head, tail, newNode);
  42.  
  43.     if (noCards(head) == true)
  44.     {
  45.         cout << "No cards were created";
  46.         return(0);
  47.     }
  48.     //Cut(head, tail, Split);
  49.     CreateDeck(head, tail, newNode);
  50.     //Deal(head, SuitNames, RankNames);
  51.     Shuffle(head, tail, ShuffleAmnt);
  52.     Deal(head, SuitNames, RankNames);
  53.     Cut(head, tail, Split);
  54.     //Readinput(head, tail, newNode, SuitNames, RankNames, Split);
  55.     system("PAUSE");
  56. }
  57.  
  58. bool CreateDeck(Card* &head, Card* &tail, Card* &newNode)
  59.  
  60. {
  61.     bool FirstPass = true;
  62.  
  63.     for (int i = 0, SuitCounter = 0, RankCounter = 0; i < 52; i++, RankCounter++)
  64.     {
  65.         if (FirstPass == true)
  66.         {
  67.             newNode = new Card;
  68.             newNode->suit = static_cast<CardSuit>(SuitCounter);
  69.             newNode->rank = static_cast<CardRank>(RankCounter);
  70.             newNode->previous = NULL;
  71.             head = newNode;
  72.             tail = newNode;
  73.             FirstPass = false;
  74.             RankCounter++;
  75.             i++;
  76.         }
  77.         if (RankCounter > 12)
  78.         {
  79.             RankCounter = 0;
  80.             SuitCounter++;
  81.         }
  82.         newNode = new Card;
  83.         newNode->suit = static_cast<CardSuit>(SuitCounter);
  84.         newNode->rank = static_cast<CardRank>(RankCounter);
  85.         newNode->previous = tail;
  86.         tail->next = newNode;
  87.         tail = newNode;
  88.  
  89.         if (SuitCounter == 3 && RankCounter == 12)
  90.             tail->next = NULL;
  91.  
  92.     }
  93.     return(true);
  94.  
  95. }
  96.  
  97. bool Deal(Card* head, string SuitNames[], string RankNames[])
  98. {
  99.  
  100.     if (head == NULL)
  101.         return(false);
  102.  
  103.     while (head != NULL)
  104.     {
  105.         cout << RankNames[head->rank] << " Of " << SuitNames[head->suit] << "\n";
  106.         head = head->next;
  107.     }
  108.  
  109.     return(true);
  110. }
  111.  
  112. bool Cut(Card* &head, Card* &tail, int Split)
  113. {
  114.     Card* temp_tail = head;
  115.     Card* temp_head = nullptr;
  116.  
  117.     //Get to our defined split
  118.     for (int i = 1; i < Split; i++)
  119.         temp_tail = temp_tail->next;
  120.  
  121.     temp_head = temp_tail->next;
  122.  
  123.     //Split the list
  124.     temp_tail->next = nullptr;
  125.     temp_head->previous = nullptr;
  126.  
  127.     //appeneding the two parts
  128.     head->previous = tail;
  129.     tail->next = head;
  130.  
  131.     //back to normal
  132.     head = temp_head;
  133.     tail = temp_tail;
  134.  
  135.  
  136.     return(true);
  137. }
  138.  
  139. bool Shuffle(Card* &head, Card* &tail, int ShuffleAmnt)
  140. {
  141.     Card* temp_tail = nullptr;
  142.     Card* temp_head = head;
  143.     Card* temp_list = new Card;
  144.     for (int i = 1; i < 26; i++)
  145.         temp_head = temp_head->next;
  146.    
  147.     temp_tail = temp_head->next;
  148.  
  149.     temp_tail->previous = nullptr;
  150.  
  151.     temp_head->next = nullptr;
  152.  
  153.     while (head->next != NULL)
  154.     {
  155.         head = head->next;
  156.         temp_tail = temp_tail->next;
  157.     }
  158.     bool FirstPass = true;
  159.     for (int i = 1; i < 26; i++)
  160.     {
  161.         if (FirstPass == true)
  162.         {
  163.             temp_list = temp_head;
  164.             temp_list->next = nullptr;
  165.             temp_list->previous = temp_tail;
  166.             temp_list->previous->next = temp_head;
  167.         }
  168.         temp_head = temp_head->previous;
  169.         temp_tail = temp_tail->previous;
  170.     }
  171.  
  172.     return(true);
  173. }
  174.  
  175.  
  176. bool noCards(Card *head)
  177. {
  178.     if (head == NULL)
  179.         return (true);
  180.     else
  181.         return false;
  182. }
  183.  
  184. /*
  185. void Readinput(Card* &head, Card* &tail, Card* &newNode, string SuitNames[], string RankNames[], int Split)
  186. {
  187.  
  188. }
  189. */
Advertisement
Add Comment
Please, Sign In to add comment