-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHand.cpp
More file actions
46 lines (40 loc) · 758 Bytes
/
Hand.cpp
File metadata and controls
46 lines (40 loc) · 758 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
#include "Hand.h"
#include "Deck.h"
void Hand::dealCard() {
addCard(Deck::deck.getCard());
}
void Hand::addCard(Card card) {
cards.push_back(card);
if(totalValue() > 21) {
for(Card & c : cards) {
if(c.isSoft()) {
c = Card(1);
break;
}
}
}
}
int Hand::totalValue() const {
int tot = 0;
for(Card c : cards) {
tot += c.getValue();
}
return tot;
}
bool Hand::isSoft() const {
for(Card c : cards) {
if(c.isSoft()) {
return true;
}
}
return false;
}
std::ostream & operator<< (std::ostream & os, const Hand & hand) {
const auto & cards = hand.getCards();
os << "[ ";
for(Card c : cards) {
os << c.getValue() << ' ';
}
os << "] = " << hand.totalValue();
return os;
}