-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDealer.cpp
122 lines (67 loc) · 1.69 KB
/
Dealer.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
#include "Dealer.h"
#include <utility>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
Dealer::Dealer() {
handValue = 0;
}
void Dealer::add_card(const std::pair<int, std::string>& card) {
hand.emplace_back(card);
}
int Dealer::get_soft_value(){
std::vector<int> countVector;
int sum = 0;
for(auto & i : hand)
{
countVector.emplace_back(i.first);
}
for (auto & i : countVector){
sum += i;
}
return sum;
}
int Dealer::get_value() {
std::vector<int> countVector;
int sum = 0, temp_sum = 0;
for(auto & i : hand)
{
countVector.emplace_back(i.first);
}
for (auto & i : countVector){
temp_sum += i;
}
while (temp_sum < 21){
if(temp_sum + 10 < 21 && std::count(countVector.begin(), countVector.end(), 1)){
auto it = std::find(countVector.begin(), countVector.end(), 1);
if (it != countVector.end()){
countVector[*it - 1] = 11;
}
temp_sum += 10;
}
else {
break;
}
}
sum = temp_sum;
return sum;
}
int Dealer::get_half_value(){
std::vector<int> countVector;
int sum = 0;
sum = countVector.emplace_back(hand[0].first);
return sum;
}
void Dealer::print_hand() {
std::cout << "\nThe dealer's hand is: \n";
for(auto & i : hand)
{
std::cout << "|" << i.second << "| ";
}
std::cout << "\nThe value of their hand is: " << get_value() << "\n";
}
void Dealer::print_half_hand() {
std::cout << "\nThe dealer's hand is: \n";
std::cout << "|" << hand[0].second << "| | FACE DOWN |";
}