-
Notifications
You must be signed in to change notification settings - Fork 0
/
rank.cpp
111 lines (104 loc) · 2.3 KB
/
rank.cpp
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/**
* @file rank.cpp
* @brief Defines functions pertaining to a card's rank.
*
*/
#include "rank.h"
/**
* @details
* - The character representations of ranks 2 to 9 are the number itself in quotes.
* - Eg: A card with rank \c rank_5 has the character representation: '5'.
* - The representations of the remaining ranks are listed below:
* - \c rank_10: 'T'
* - \c rank_jack: 'J'
* - \c rank_king: 'K'
* - \c rank_queen: 'Q'
* - \c rank_ace: 'A'
* - The default representation is '?'.
*/
char getName(const CardRank rank)
{
switch (rank)
{
case rank_2:
return '2';
case rank_3:
return '3';
case rank_4:
return '4';
case rank_5:
return '5';
case rank_6:
return '6';
case rank_7:
return '7';
case rank_8:
return '8';
case rank_9:
return '9';
case rank_10:
return 'T';
case rank_jack:
return 'J';
case rank_king:
return 'K';
case rank_queen:
return 'Q';
case rank_ace:
return 'A';
default:
return '?';
}
}
/**
* @details Type-cast \c rank to \c CardRank
*
*/
CardRank getRank(std::size_t rank)
{
return static_cast<CardRank>(rank);
}
/**
* @details
* - The numeric value of ranks 2 to 9 are their straightforward numeric equivalents.
* - Eg: value of a card with rank 3 is 3.
* - The value of cards with the remaining ranks are listed below:
* - Ranks 10, J, K, Q: 10
* - Rank A: 11
*/
int getValue(const CardRank rank)
{
switch (rank)
{
case rank_2:
case rank_3:
case rank_4:
case rank_5:
case rank_6:
case rank_7:
case rank_8:
case rank_9:
return static_cast<int>(rank) + 2;
case rank_10:
case rank_jack:
case rank_king:
case rank_queen:
return static_cast<int>(rank_10) + 2;
case rank_ace:
return static_cast<int>(rank_10) + 3;
default:
return -1;
}
}
/**
* @details
* - \c max_ranks is of type \c CardRank; You've to typecast it to \c std::size_t.
*/
std::size_t getNumRanks()
{
return static_cast<std::size_t>(CardRank::max_ranks);
}
std::ostream& operator<<(std::ostream& out, const CardRank& rank)
{
return out << getName(rank);
}