-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.cpp
More file actions
48 lines (44 loc) · 1 KB
/
Copy pathPlayer.cpp
File metadata and controls
48 lines (44 loc) · 1 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
#include "Player.h"
#include <iostream>
#include <algorithm>
Pips Player::hit(Card card) { //hit a card, return a player`s score
if (!stand_status) {
hand.push_back(card);
std::sort(hand.begin(), hand.end(), [](Card a, Card b) {return a.getpip() < b.getpip(); }); //sort from lowest pip (A is considered 11)
if (getscore() >= 21)
stand();
return card.getpip();
}
}
void Player::stand() {
stand_status = 1;
}
short unsigned int Player::getscore() {
short unsigned int score = 0;
for (int i = 0; i < hand.size(); i++) {
if (hand[i].getpip() == Pips::A)
if (score + 11 <= 21)
score += 11;
else score += 1;
else
score += hand[i].getvalue();
}
return score;
};
void Player::clear() {
hand.clear();
stand_status = 0;
}
bool Player::getstand_status() {
return stand_status;
}
void Player::printhand() {
bool counter = 0;
for (int i = 0; i < hand.size(); i++) {
if (counter > 0)
std::cout << ", ";
std::cout << ToString(hand[i].getpip());
counter++;
}
std::cout << "\n";
};