-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHand.h
67 lines (52 loc) · 813 Bytes
/
Hand.h
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
#pragma once
#include <random>
#include <vector>
#include "Card.h"
#include "Deck.h"
const int maxCardsInDeck = 5;
const int maxValidHandValue = 21;
class Hand
{
public:
Hand()
{}
size_t size() const
{
return cards.size();
}
bool isEmpty() const
{
return size() == 0;
}
void addCard(const Card& card)
{
if (size() < maxCardsInDeck)
{
cards.push_back(card);
}
}
void discardCards()
{
cards.clear();
}
int getHandValue() const
{
int sum = 0;
int aceCount = 0;
for (const Card& card : cards)
{
sum += card.getValue();
if (card.getFace() == Face::Ace)
++aceCount;
}
while (sum > maxValidHandValue && aceCount > 0)
{
sum -= defaultAceValue;
sum += reducedAceValue;
--aceCount;
}
return sum;
}
private:
std::vector<Card> cards;
};