-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPack.cpp
57 lines (47 loc) · 1.49 KB
/
Pack.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
#include "Pack.hpp"
using namespace std;
// MODIFIES: Pack vector
// EFFECTS: initializes Pack vector with 52 Cards
Pack::Pack() {
pack.clear();
string current_suit;
string current_rank;
// put every card of every suit + rank into pack
for (int suit = 0; suit < 4; suit++) {
for (int rank = 0; rank < 13; rank++) {
current_suit = SUIT_ARRAY[suit];
current_rank = RANK_ARRAY[rank];
pack.push_back(Card(current_rank, current_suit));
}
}
}
// EFFECTS: returns true if Pack size is equal to 52; returns false otherwise
bool Pack::is_full() {
return pack.size() == FULL_PACK_SIZE;
}
// EFFECTS: returns true if Pack size is equal to 0; returns false otherwise
bool Pack::is_empty() {
return pack.empty();
}
// MODIFIES: order of Cards within Pack vector
// EFFECTS: shuffles Cards in a random order
void Pack::shuffle_pack() {
default_random_engine rng (static_cast<unsigned> (chrono::system_clock::now().time_since_epoch().count()));
shuffle(pack.begin(), pack.end(), default_random_engine(rng));
}
// EFFECTS: returns last card in Pack
Card Pack::deal() {
return pack.back();
}
// REQUIRES: non-empty pack
// MODIFIES: Pack vector (decreases size + removes last card)
// EFFECTS: removes last card in Pack
void Pack::remove_card() {
pack.pop_back();
}
// EFFECTS: prints all cards in Pack
void Pack::print_pack() {
for (int i = 0; i < FULL_PACK_SIZE; i++) {
cout << pack[i] << endl;
}
}