-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dealing.cpp
88 lines (72 loc) · 1.74 KB
/
Dealing.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/************************
Erich Choudhury
Thomas Daughtridge
Grant Caskey
ECGR 2104
April 30, 2018
Dealing.cpp
************************/
#include "Dealing.h"
#include <iostream>
#include <stack>
#include <algorithm>
using namespace std;
//Create the deck of 52 cards, 4 suits, 13 different types of cards
void createDeck(stack<Card>& s, vector<Card>& d) {
for (int x = 1; x <= 4; x++) {
for (int i = 1; i <= 13; i++) {
Card card(i,x);
d.push_back(card);
}
}
random_shuffle( d.begin(), d.end() );
for (int j = 0; j < d.size(); j++) {
s.push(d[j]);
}
}
//Move specific number of cards from stack to vector
void dealToHands(int num, vector<Card>& target, stack<Card>& sender) {
if (sender.size() == 0) {
cout << "Error" << endl;
}
else {
for (int i = 1; i <= num; i++) {
Card x = sender.top();
sender.pop();
target.push_back(x);
}
}
}
//Move specific number of cards from vector to stack
void sendToDraw(stack<Card>& target, vector<Card>& sender) {
if (sender.size() == 0) {
cout << "Error" << endl;
}
else {
for (int i = sender.size(); i >= 1; i--) {
Card x = sender[i];
sender.pop_back();
target.push(x);
}
}
}
//Move specific number of cards from stack <---> stack
void dealToDiscard(int num, stack<Card>& target, stack<Card>& sender) {
if (sender.size() == 0) {
cout << "Error" << endl;
}
else {
for (int i = 1; i <= num; i++) {
Card x = sender.top();
sender.pop();
target.push(x);
}
}
}
//Move all cards back to the draw pile
void reset(vector<Card>& deck, stack<Card>& draw, stack<Card>& discard, vector<Card>& player, vector<Card>& computer) {
int discardSize = discard.size();
sendToDraw(draw, player);
sendToDraw(draw, computer);
dealToDiscard(discardSize, draw, discard);
}