blob: 19d732bc4ceb7845996c33df52e3d56939e0182f (
plain)
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
/*
* card.cpp
*
*
*/
#include "card.h"
Card::Card(void) : type(""), rank(0)
{
}
Card::Card(Card *card)
{
type = card->type;
rank = card->rank;
}
Card::Card(string &str)
{
type = str;
}
string Card::getType(void)
{
return type;
}
void Card::rankCard(void)
{
char c;
c = getType()[0];
switch (c)
{
case 'A':
rank = 13;
break;
case 'K':
rank = 12;
break;
case 'Q':
rank = 11;
break;
case 'J':
rank = 10;
break;
case 'T':
rank = 9;
break;
case '9':
rank = 8;
break;
case '8':
rank = 7;
break;
case '7':
rank = 6;
break;
case '6':
rank = 5;
break;
case '5':
rank = 4;
break;
case '4':
rank = 3;
break;
case '3':
rank = 2;
break;
case '2':
rank = 1;
break;
default:
std::cerr << "something went wrong while ranking a card" << endl;
}
}
/* rank value that will be used by a sorting algorithm to put cards such as a
* pair, two pair, three of a kind, four of a kind, or full house all the way
* to the left, SortHand will set these attributes when necessary and call sort */
void Card::specialRank(void)
{
char c;
c = getType()[0];
switch (c)
{
case 'A':
rank = 26;
break;
case 'K':
rank = 25;
break;
case 'Q':
rank = 24;
break;
case 'J':
rank = 23;
break;
case 'T':
rank = 22;
break;
case '9':
rank = 21;
break;
case '8':
rank = 20;
break;
case '7':
rank = 19;
break;
case '6':
rank = 18;
break;
case '5':
rank = 17;
break;
case '4':
rank = 16;
break;
case '3':
rank = 15;
break;
case '2':
rank = 14;
break;
default:
std::cerr << "something went wrong while special specialRanking a card" << endl;
}
}
int Card::getRank(void)
{
return rank;
}
enum Suit Card::getSuit(void)
{
enum Suit whatSuit = Undef;
char c = type[1];
switch (c)
{
case 'C':
whatSuit = Clubs;
break;
case 'D':
whatSuit = Diamond;
break;
case 'H':
whatSuit = Hearts;
break;
case 'S':
whatSuit = Spades;
break;
default:
std::cerr << "could not determine the suit of the card" << endl;
}
return whatSuit;
}
void Card::sortCards(Card **cards)
{
if (cards == NULL)
{
PRINT_COLOR(ANSI_COLOR_RED, "\nsortCards(): cards parameter is NULL!\n");
return;
}
/* reverse bubble sort */
int i, j;
Card *tmp;
for (i = 0; i < 5; i++)
for (j = 0; j < 5-i-1; j++)
{
if (cards[j]->rank < cards[j+1]->rank)
{
tmp = cards[j];
cards[j] = cards[j+1];
cards[j+1] = tmp;
}
}
}
|