-
Notifications
You must be signed in to change notification settings - Fork 0
/
Deck.cpp
189 lines (176 loc) · 5.71 KB
/
Deck.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#include "Card.h"
#include "Deck.h"
#include "Gameboard.h"
/**
* An object of type Deck represents an ordinary deck of 52 playing cards.
* The deck can be shuffled, and cards can be dealt from the deck.
* @author jsupton
* @author Wilmot Osei-Bonsu
* @version Febuary 16 2019
*/
// An arrayList of the deck of cards
vector<Card> deck;
//A Number of cards for the deck
int NumberOfCards;
/**
* Default constructor. It simply creates a deck of 52 cards
*/
Deck::Deck() {
// Create an unshuffled deck of cards.
deck.clear();
for (int suit = 0; suit <= 3; suit++) {
for (int value = 1; value <= 13; value++) {
deck.push_back(Card(value, suit));
}
}
}
/**
* Shuffles the deck using the Fisher-Yates algorithm
*/
void Deck::shuffle() {
// Put all the used cards back into the deck, and shuffle it into
// a random order.
for (int i = 51; i > 0; i--) {
int random = rand()%(i+1);
Card temp = deck[i];
deck.at(i) = deck[random];
deck.at(random) = temp;
}
}
/**
* Creates a new shuffled deck of cards in an order that guarantees that the
* User will win their solitaire game
*/
void Deck::shuffle_WIN() {
deck.clear();
deck.push_back(Card(1, 0));
deck.push_back(Card(2, 0));
deck.push_back(Card(1, 1));
deck.push_back(Card(4, 0));
deck.push_back(Card(3, 0));
deck.push_back(Card(1, 2));
deck.push_back(Card(5, 0));
deck.push_back(Card(4, 1));
deck.push_back(Card(3, 1));
deck.push_back(Card(1, 3));
deck.push_back(Card(6, 0));
deck.push_back(Card(5, 1));
deck.push_back(Card(4, 2));
deck.push_back(Card(3, 2));
deck.push_back(Card(2, 1));
deck.push_back(Card(7, 0));
deck.push_back(Card(6, 1));
deck.push_back(Card(6, 2));
deck.push_back(Card(5, 2));
deck.push_back(Card(3, 3));
deck.push_back(Card(2, 2));
deck.push_back(Card(7, 1));
deck.push_back(Card(7, 2));
deck.push_back(Card(7, 3));
deck.push_back(Card(6, 3));
deck.push_back(Card(5, 3));
deck.push_back(Card(4, 3));
deck.push_back(Card(2, 3));
for (int value = 8; value <= 13; value++) {
for (int suit = 0; suit <= 3; suit++) {
deck.push_back(Card(value, suit));
}
}
}
/**
* Creates a new shuffled deck of cards in an order that guarantees that the
* User will win their solitaire game
*/
void Deck::shuffle_WIN2() {
deck.clear();
deck.push_back(Card(7, 0));
deck.push_back(Card(5, 0));
deck.push_back(Card(6, 1));
deck.push_back(Card(2, 1));
deck.push_back(Card(3, 0));
deck.push_back(Card(4, 1 ));
deck.push_back(Card(1, 3));
deck.push_back(Card(1, 2));
deck.push_back(Card(1, 1));
deck.push_back(Card(1, 0));
deck.push_back(Card(7, 1));
deck.push_back(Card(2, 0));
deck.push_back(Card(3, 1));
deck.push_back(Card(4, 0));
deck.push_back(Card(5, 1));
deck.push_back(Card(7, 3));
deck.push_back(Card(2, 2));
deck.push_back(Card(3, 3));
deck.push_back(Card(4, 2));
deck.push_back(Card(5, 3));
deck.push_back(Card(6, 0));
deck.push_back(Card(7, 2));
deck.push_back(Card(6, 3));
deck.push_back(Card(5, 2));
deck.push_back(Card(4, 3));
deck.push_back(Card(3, 2));
deck.push_back(Card(2, 3));
deck.push_back(Card(6, 2));
for (int value = 8; value <= 13; value++) {
for (int suit = 0; suit <= 3; suit++) {
deck.push_back(Card(value, suit));
}
}
}
/**
* Creates a new shuffled deck of cards in an order that guarantees that the
* User will lose their solitaire game
*/
void Deck::shuffle_LOSE() {
deck.clear();
deck.push_back(Card(13, 0));
deck.push_back(Card(8, 0));
deck.push_back(Card(13, 1));
deck.push_back(Card(8, 0));
deck.push_back(Card(8, 0));
deck.push_back(Card(13, 2));
deck.push_back(Card(1, 0));
deck.push_back(Card(12, 1));
deck.push_back(Card(10, 1));
deck.push_back(Card(13, 3));
deck.push_back(Card(1, 0));
deck.push_back(Card(12, 1));
deck.push_back(Card(10, 2));
deck.push_back(Card(9, 2));
deck.push_back(Card(11, 1));
deck.push_back(Card(1, 0));
deck.push_back(Card(12, 1));
deck.push_back(Card(10, 2));
deck.push_back(Card(9, 2));
deck.push_back(Card(8, 3));
deck.push_back(Card(11, 2));
deck.push_back(Card(1, 1));
deck.push_back(Card(12, 2));
deck.push_back(Card(10, 3));
deck.push_back(Card(9, 3));
deck.push_back(Card(9, 3));
deck.push_back(Card(11, 3));
deck.push_back(Card(11, 3));
for (int value = 2; value <= 7; value++) {
for (int suit = 0; suit <= 3; suit++) {
deck.push_back(Card(value, suit));
}
}
}
/**
* Gets the deck of cards
* @return ArrayList<Cards> representing the current deck
*/
vector<Card> * Deck::getDeck() {
return &this ->deck;
}
/*
* Generates a normal distribution random number between 0 and 1.
* @return Random double between 0 and 1.
*/
double Deck::random() {
mt19937 generator;
generator.seed(time(0));
uniform_real_distribution<double> cardRand(0, 1);
return cardRand(generator);
}