-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCard.h
94 lines (80 loc) · 1.37 KB
/
Card.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
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
#pragma once
#include <map>
#include <string>
enum class Suit
{
None = 0,
Spades,
Clubs,
Hearts,
Diamonds
};
enum class Face
{
None = 0,
Ace = 1,
Two,
Three,
Four,
Five,
Six,
Seven,
Eight,
Nine,
Ten,
Jack,
Queen,
King
};
const static std::map<Suit, std::string> allSuits =
{
{Suit::Spades, "Spades"},
{Suit::Clubs, "Clubs"},
{Suit::Hearts, "Hearts"},
{Suit::Diamonds, "Diamonds"}
};
const static std::map<Face, std::string> allFaces =
{
{Face::Ace, "Ace"},
{Face::Two, "Two"},
{Face::Three, "Three"},
{Face::Four, "Four"},
{Face::Five, "Five"},
{Face::Six, "Six"},
{Face::Seven, "Seven"},
{Face::Eight, "Eight"},
{Face::Nine, "Nine"},
{Face::Ten, "Ten"},
{Face::Jack, "Jack"},
{Face::Queen, "Queen"},
{Face::King, "King"}
};
const int defaultCardValue = 10;
const int defaultAceValue = 11;
const int reducedAceValue = 1;
class Card
{
Suit suit_;
Face face_;
public:
Card()
: suit_(Suit::None), face_(Face::None)
{}
Card(Suit suit, Face face)
: suit_(suit), face_(face)
{}
Suit getSuit() const { return suit_; }
Face getFace() const { return face_; }
int getValue() const
{
if (face_ >= Face::Two && face_ <= Face::Ten)
return static_cast<int>(face_);
if (face_ == Face::Ace)
return defaultAceValue;
return defaultCardValue;
}
std::string toString() const
{
return allFaces.at(face_) + " of " + allSuits.at(suit_);
}
};