-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshoe.cpp
More file actions
54 lines (42 loc) · 854 Bytes
/
shoe.cpp
File metadata and controls
54 lines (42 loc) · 854 Bytes
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
#include "shoe.h"
#define ACE -1
Shoe::Shoe() {
int card;
for (unsigned k = 0; k < 8; ++k) {
for (unsigned i = 2; i <= 14; ++i) {
if (i == 14)
card = ACE;
else if (i > 10)
card = 10;
else
card = i;
for (unsigned j = 0; j < 4; ++j) {
cards_.push_back(card);
}
}
}
cards_.shrink_to_fit();
for (unsigned i = 0; i < 7; ++i) {
shuffle();
}
cards_[125] = -2;
}
Shoe::~Shoe() {}
int Shoe::hit() {
if (cards_.empty())
std::cout << "EmptyShoe";
int card = cards_.back();
cards_.pop_back();
return card;
}
bool Shoe::isLastHand() {
return (cards_.back() == -2);
}
void Shoe::shuffle() {
for (unsigned i = cards_.size() - 1; i > 0; --i) {
int index = rand() % i;
int temp = cards_[index];
cards_[index] = cards_[i];
cards_[i] = temp;
}
}