-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.cpp
More file actions
83 lines (46 loc) · 1.2 KB
/
Player.cpp
File metadata and controls
83 lines (46 loc) · 1.2 KB
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
#include "Player.h"
#include <utility>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
Player::Player(std::string name) {
playerName = std::move(name);
handValue = 0;
}
void Player::add_card(const std::pair<int, std::string>& card) {
hand.emplace_back(card);
}
int Player::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;
}
void Player::print_hand() {
std::cout << "\nYour current hand is: \n";
for(auto & i : hand)
{
std::cout << "|" << i.second << "| ";
}
std::cout << "\nThe value of your hand is: " << get_value() << "\n";
}