-
Notifications
You must be signed in to change notification settings - Fork 0
/
shoe.h
162 lines (140 loc) · 2.83 KB
/
shoe.h
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
#ifndef SHOE_H
#define SHOE_H
#include <iostream>
#include <ctime>
#include <list>
#include "mersenne.h"
#include "card.h"
#include "hilowcount.h"
using namespace std;
class Shoe
{
public:
Shoe(unsigned int numDecks) : numDecks(numDecks), numCards(numDecks*52), cardsDealt(0)
{
cards = new char[numCards];
for(unsigned int i=0;i<numCards;i++)
{
cards[i] = (i%52);
}
//set up the RNG
randgen.srand((unsigned)time(NULL));
for(unsigned int i=0;i<1000;i++)
{
//avoid zero excess initial state
randgen.rand();
}
}
~Shoe()
{
delete cards;
}
void shuffle()
{
//KFY shuffle
for(unsigned int i = numCards-1; i > 0; i--)
{
char temp;
int n;
n = randgen.rand()%numCards;
if(n != i)
{
temp = cards[i];
cards[i] = cards[n];
cards[n] = temp;
}
}
cardsDealt = 0;
count.resetCount();
}
/* this function "removes" the cards in play from the shuffled deck so
its as if only the cards in the discard pile were shuffled. it scans the
freshly shuffled shoe for instances of cards that are on the table, and
moves them before the index cardsDealt. there is no actual discard pile that
is maintained, and therefore you cannot trace back to see what order the
cards were dealt in previous hands */
void adjustShuffle(list<char> &cardsInPlay)
{
char temp;
cardsDealt = cardsInPlay.size();
unsigned int i, j;
for(i=0;i<cardsDealt;i++)
{
for(j=0;j<numCards;j++)
{
if(cards[j] == cardsInPlay.back())
{
temp = cards[j];
cards[j] = cards[i];
cards[i] = temp;
cardsInPlay.pop_back();
break;
}
}
}
}
char drawCard()
{
//TODO - shuffle instead of terminating
if(cardsDealt == numCards)
exit(187); //deck is empty
count.count(cards[cardsDealt]);
cardsDealt++;
return cards[cardsDealt-1];
}
int trueCount() const
{
//upcast these to double; still may be errors
return static_cast<double>(count.getCount()) / (static_cast<double>((numCards - cardsDealt)) / 52.0);
}
int runningCount() const
{
return count.getCount();
}
unsigned int totalNumCards() const
{
return numCards;
}
unsigned int numCardsDealt() const
{
return cardsDealt;
}
void printDebug() const
{
for(unsigned int i=0;i<numCards;i++)
{
cout << (int)cards[i] << " ";
}
}
void printNamesDebug() const
{
for(unsigned int i=0;i<numCards;i++)
{
printName(cards[i]);
cout << " ";
}
}
//how often does the first card appear at the start of the deck?
void debugStatCount(int iterations = 10000000)
{
int count = 0;
for(int i=0;i<iterations;i++)
{
shuffle();
if(cards[0] == 1)
{
count++;
}
}
double total = (double)count/iterations*52;
cout << total << endl;
}
private:
Mersenne randgen;
HiLowCount count;
unsigned int numDecks;
unsigned int numCards;
char *cards;
unsigned int cardsDealt;
};
#endif