-
Notifications
You must be signed in to change notification settings - Fork 13
/
card.cc
54 lines (45 loc) · 1.15 KB
/
card.cc
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
#include "card.h"
#include <cassert>
const std::map<Color, std::string> color_map{
{Color::Heart, "h"},
{Color::Diamond, "d"},
{Color::Club, "c"},
{Color::Spade, "s"},
};
const std::map<Color, RenderColor> render_color_map{
{Color::Heart, RenderColor::Red},
{Color::Diamond, RenderColor::Red},
{Color::Club, RenderColor::Black},
{Color::Spade, RenderColor::Black},
};
const std::vector<Color> colors_list {
Color::Heart,
Color::Diamond,
Color::Club,
Color::Spade,
};
Card::Card(Color col, int val) : color(col), value(val) {
assert(value >= 1 && value <= king_value);
}
std::ostream& operator<< (std::ostream& os, const Card & card) {
if (card.value <= 10) {
os << card.value;
} else if (card.value == 11) {
os << "J";
} else if (card.value == 12) {
os << "Q";
} else if (card.value == 13) {
os << "K";
}
os << color_map.at(card.color);
return os;
}
bool operator==(const Card &a, const Card &b) {
return a.color == b.color && a.value == b.value;
}
bool operator!=(const Card &a, const Card &b) {
return !(a == b);
}
bool operator<(const Card &a, const Card &b) {
return std::tie(a.color, a.value) < std::tie(b.color, b.value);
}