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 };
- struct Card
- {
- CardSuit suit;
- CardRank rank;
- Card* next;
- Card* previous;
- };
- int main()
- {
- bool noCards(Card* head);
- bool Deal(Card*, string[], string[]);
- bool CreateDeck(Card*&, Card*&, Card*&);
- bool Cut(Card*&, Card*&, int);
- bool Shuffle(Card*&, Card*&, int);
- //void Readinput(Card*&, Card*&, Card*, string[], string[], int);
- int Split = 15;
- int ShuffleAmnt = 1;
- 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;
- CreateDeck(head, tail, newNode);
- if (noCards(head) == true)
- {
- cout << "No cards were created";
- return(0);
- }
- //Cut(head, tail, Split);
- CreateDeck(head, tail, newNode);
- //Deal(head, SuitNames, RankNames);
- Shuffle(head, tail, ShuffleAmnt);
- Deal(head, SuitNames, RankNames);
- Cut(head, tail, Split);
- //Readinput(head, tail, newNode, SuitNames, RankNames, Split);
- system("PAUSE");
- }
- bool 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 == 12)
- tail->next = NULL;
- }
- return(true);
- }
- 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);
- }
- bool Cut(Card* &head, Card* &tail, int Split)
- {
- Card* temp_tail = head;
- Card* temp_head = nullptr;
- //Get to our defined split
- for (int i = 1; i < Split; i++)
- temp_tail = temp_tail->next;
- temp_head = temp_tail->next;
- //Split the list
- temp_tail->next = nullptr;
- temp_head->previous = nullptr;
- //appeneding the two parts
- head->previous = tail;
- tail->next = head;
- //back to normal
- head = temp_head;
- tail = temp_tail;
- return(true);
- }
- bool Shuffle(Card* &head, Card* &tail, int ShuffleAmnt)
- {
- Card* temp_tail = nullptr;
- Card* temp_head = head;
- Card* temp_list = new Card;
- for (int i = 1; i < 26; i++)
- temp_head = temp_head->next;
- temp_tail = temp_head->next;
- temp_tail->previous = nullptr;
- temp_head->next = nullptr;
- while (head->next != NULL)
- {
- head = head->next;
- temp_tail = temp_tail->next;
- }
- bool FirstPass = true;
- for (int i = 1; i < 26; i++)
- {
- if (FirstPass == true)
- {
- temp_list = temp_head;
- temp_list->next = nullptr;
- temp_list->previous = temp_tail;
- temp_list->previous->next = temp_head;
- }
- temp_head = temp_head->previous;
- temp_tail = temp_tail->previous;
- }
- return(true);
- }
- bool noCards(Card *head)
- {
- if (head == NULL)
- return (true);
- else
- return false;
- }
- /*
- void Readinput(Card* &head, Card* &tail, Card* &newNode, string SuitNames[], string RankNames[], int Split)
- {
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment