Guest User

Untitled

a guest
Dec 12th, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.04 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.     CreateDeck(head, tail, newNode);
  49.     //Deal(head, SuitNames, RankNames);
  50.     Shuffle(head, tail, ShuffleAmnt);
  51.     Deal(head, SuitNames, RankNames);
  52.     Cut(head, tail, Split);
  53.     //Readinput(head, tail, newNode, SuitNames, RankNames, Split);
  54.     system("PAUSE");
  55. }
  56.  
  57. bool CreateDeck(Card* &head, Card* &tail, Card* &newNode)
  58.  
  59. {
  60.     bool FirstPass = true;
  61.  
  62.     for (int i = 0, SuitCounter = 0, RankCounter = 0; i < 52; i++, RankCounter++)
  63.     {
  64.         if (FirstPass == true)
  65.         {
  66.             newNode = new Card;
  67.             newNode->suit = static_cast<CardSuit>(SuitCounter);
  68.             newNode->rank = static_cast<CardRank>(RankCounter);
  69.             newNode->previous = NULL;
  70.             head = newNode;
  71.             tail = newNode;
  72.             FirstPass = false;
  73.             RankCounter++;
  74.             i++;
  75.         }
  76.         if (RankCounter > 12)
  77.         {
  78.             RankCounter = 0;
  79.             SuitCounter++;
  80.         }
  81.         newNode = new Card;
  82.         newNode->suit = static_cast<CardSuit>(SuitCounter);
  83.         newNode->rank = static_cast<CardRank>(RankCounter);
  84.         newNode->previous = tail;
  85.         tail->next = newNode;
  86.         tail = newNode;
  87.  
  88.         if (SuitCounter == 3 && RankCounter == 12)
  89.             tail->next = NULL;
  90.  
  91.     }
  92.     return(true);
  93.  
  94. }
  95.  
  96. bool Deal(Card* head, string SuitNames[], string RankNames[])
  97. {
  98.  
  99.     if (head == NULL)
  100.         return(false);
  101.  
  102.     while (head != NULL)
  103.     {
  104.         cout << RankNames[head->rank] << " Of " << SuitNames[head->suit] << "\n";
  105.         head = head->next;
  106.     }
  107.  
  108.     return(true);
  109. }
  110.  
  111. bool Cut(Card* &head, Card* &tail, int Split)
  112. {
  113.     Card* temp_tail = head;
  114.     Card* temp_head = nullptr;
  115.  
  116.     //Get to our defined split
  117.     for (int i = 1; i < Split; i++)
  118.         temp_tail = temp_tail->next;
  119.  
  120.     temp_head = temp_tail->next;
  121.  
  122.     //Split the list
  123.     temp_tail->next = nullptr;
  124.     temp_head->previous = nullptr;
  125.  
  126.     //appeneding the two parts
  127.     head->previous = tail;
  128.     tail->next = head;
  129.  
  130.     //back to normal
  131.     head = temp_head;
  132.     tail = temp_tail;
  133.  
  134.  
  135.     return(true);
  136. }
  137.  
  138. bool Shuffle(Card* &head, Card* &tail, int ShuffleAmnt)
  139. {
  140.  
  141.     Card* temp_tail = nullptr;
  142.     Card* temp_head = head;
  143.     Card* newNode = nullptr;
  144.     Card* temp_list = new Card;
  145.     //temp_list = head;
  146.     for (int i = 1; i < 26; i++)
  147.         temp_head = temp_head->next;
  148.  
  149.     temp_tail = temp_head->next;
  150.     temp_tail->previous = nullptr;
  151.     temp_head->next = nullptr;
  152.  
  153.     while (temp_head->previous != NULL)
  154.     {
  155.         temp_head = temp_head->previous;
  156.         tail = tail->previous;
  157.     }
  158.     //temp_list = temp_head;
  159.     //temp_list->next = temp_tail;
  160.     //temp_list = temp_head;
  161.     //temp_list->next = temp_tail;
  162.  
  163.         for (int i = 0; i < 26; i++)
  164.         {
  165.             tail = tail->next;
  166.             head = head->next;
  167.             temp_tail = tail;
  168.             temp_head = head;
  169.             temp_tail->next = nullptr;
  170.             temp_tail->previous = nullptr;
  171.             temp_head->previous = nullptr;
  172.             temp_head->next = nullptr;
  173.             temp_list->next = temp_head;
  174.             temp_list->next = temp_tail;
  175.         }
  176.    
  177.  
  178.     head = temp_list;
  179.  
  180.  
  181.  
  182.     return(true);
  183. }
  184.  
  185.  
  186. bool noCards(Card *head)
  187. {
  188.     if (head == NULL)
  189.         return (true);
  190.     else
  191.         return false;
  192. }
  193.  
  194. /*
  195. void Readinput(Card* &head, Card* &tail, Card* &newNode, string SuitNames[], string RankNames[], int Split)
  196. {
  197.  
  198. }
  199. */
Advertisement
Add Comment
Please, Sign In to add comment