-
Notifications
You must be signed in to change notification settings - Fork 0
/
Deck.cpp
288 lines (249 loc) · 6.82 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#include "Deck.h"
#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std;
DECK::DECK(int numberOfDecks)
{
char suit[52] = {'S','S','S','S','S','S','S','S','S','S','S','S','S',
'H','H','H','H','H','H','H','H','H','H','H','H','H',
'D','D','D','D','D','D','D','D','D','D','D','D','D',
'C','C','C','C','C','C','C','C','C','C','C','C','C'};
char name[52] = {'A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K',
'A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K',
'A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K',
'A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K'};
int value[52] = {11,2,3,4,5,6,7,8,9,10,10,10,10,
11,2,3,4,5,6,7,8,9,10,10,10,10,
11,2,3,4,5,6,7,8,9,10,10,10,10,
11,2,3,4,5,6,7,8,9,10,10,10,10};
int hilo[52] = {-1,1,1,1,1,1,0,0,0,-1,-1,-1,-1,
-1,1,1,1,1,1,0,0,0,-1,-1,-1,-1,
-1,1,1,1,1,1,0,0,0,-1,-1,-1,-1,
-1,1,1,1,1,1,0,0,0,-1,-1,-1,-1};
int Omega[52] = {0,1,1,2,2,2,1,0,-1,-2,-2,-2,-2,
0,1,1,2,2,2,1,0,-1,-2,-2,-2,-2,
0,1,1,2,2,2,1,0,-1,-2,-2,-2,-2,
0,1,1,2,2,2,1,0,-1,-2,-2,-2,-2};
//int omega[52] = {};
int numberOfCards = (numberOfDecks * 52);
deck = new Card[numberOfCards];
for (int i = 0; i < numberOfCards; i++)
{
deck[i].inDeck = true;
deck[i].value = value[i%52];
deck[i].name = name[i%52];
deck[i].suit = suit[i%52];
deck[i].Count1 = hilo[i%52];
deck[i].Count2 = Omega[i%52];
}
runningCountHiLo = 0;
runningCountOmega = 0;
offerInsurance = false;
}
Card DECK::draw()
{
for (int c = 0; c < numberOfCards; c++)
{
if (deck[c].inDeck)
{
runningCountHiLo += deck[c].Count1;
runningCountOmega += deck[c].Count2;
deck[c].inDeck = false;
deck[c].visible = true;
return deck[c];
}
}
return deck[51];
}
Card DECK::drawHole()
{
/*unsigned choice = 0;
unsigned seed = time(0);
srand(seed);
do
{
//choice = rand() % 52;
choice = rand() % numberOfCards;
}
while (!(deck[choice].inDeck));
runningCountHiLo += deck[choice].Count1;
runningCountOmega += deck[choice].Count2;
deck[choice].inDeck = false;
deck[choice].visible = false;
return deck[choice];*/
for (int c = 0; c < numberOfCards; c++)
{
if (deck[c].inDeck)
{
runningCountHiLo += deck[c].Count1;
runningCountOmega += deck[c].Count2;
deck[c].inDeck = false;
deck[c].visible = false;
return deck[c];
}
}
return deck[51];
}
void DECK::print()
{
for (int s = 0; s < 4; s++)
{
for (int v = 0; v < 13; v++)
{
int a = v + (13*s);
if (deck[a].inDeck)
{
cout << deck[a].name << deck[a].suit << "= " << deck[a].value << ", ";
}
}
cout << endl;
}
cout << endl;
}
double DECK::decks()
{
numInDeck = 0;
for (int i = 0; i < numberOfCards; i++)
{
if (deck[i].inDeck)
{
numInDeck++;
}
}
return numInDeck/52.0;
}
int DECK::trueHiLo()
{
return (runningCountHiLo / decks());
}
int DECK::trueOmega()
{
return (runningCountOmega / decks());
}
int DECK::runCount()
{
return runningCountOmega;
}
void DECK::shuffle(int numberOfDecks)
{
numberOfCards = (numberOfDecks * 52);
for (int i = 0; i < numberOfCards; i++)
{
deck[i].inDeck = true;
}
runningCountHiLo = 0;
runningCountOmega = 0;
copy1 = new Card[numberOfCards];
for (int k = 0; k < numberOfCards; k++)
{
int *addresses = NULL;
// count the number of cards still in the deck
int counter = 0;
for (int c = 0; c < numberOfCards; c++)
{
if (deck[c].inDeck)
counter++;
}
// Create an array only big enough to hold the
// addresses of the cards still in the deck
int index = 0;
addresses = new int[counter];
for (int c = 0; c < numberOfCards; c++)
{
if (deck[c].inDeck)
{
addresses[index] = c;
index++;
}
}
// seed random number
unsigned choice = 0;
unsigned seed = time(0);
srand(seed);
// Select a random number from the address array
choice = (rand() % (counter)); //0 -
// Copy the card from the random address in the deck.
copy1[k] = deck[addresses[choice]];
deck[addresses[choice]].inDeck = false;
// Addresses must be cleared before the next card is selected.
addresses = NULL;
delete [] addresses;
}
for (int k = 0; k < numberOfCards; k++)
{
deck[k] = copy1[k];
deck[k].inDeck = true;
}
delete [] copy1;
}
bool DECK::returnDisplay()
{
return display;
}
void DECK::setDisplay(bool input)
{
display = input;
}
void DECK::reset()
{
for (int i = 0; i < numberOfCards; i++)
{
deck[i].inDeck = true;
}
runningCountHiLo = 0;
runningCountOmega = 0;
}
int DECK::aceAdjusted()
{
// number of aces - number of quarter decks multiplied by 2
// added to true count
int aces = 0;
for (int i = 0; i < numberOfCards; i++)
{
if (deck[i].name == 'A')
{
aces++;
}
}
double quarterDecks = (decks()*4);
return (((aces - quarterDecks)*2) + trueOmega());
}
void DECK::shoeSize()
{
numInDeck = 0;
for (int i = 0; i < numberOfCards; i++)
{
if (deck[i].inDeck)
{
numInDeck++;
}
}
int d = numInDeck/52;
//int full = (quarterDecks / 4);
int partial = (numInDeck % 52)/13;
for (int i = 0; i < d; i++)
{
cout << ". | | | | ";
}
cout << ". ";
for (int i = 0; i < partial; i++)
{
cout << "| ";
}
}
int DECK::extraAces()
{
// number of aces - number of quarter decks multiplied by 2
// added to true count
int aces = 0;
for (int i = 0; i < numberOfCards; i++)
{
if (deck[i].name == 'A')
{
aces++;
}
}
double quarterDecks = (decks()*4);
return (aces - quarterDecks);
}