blob: 0b09b7ccd179a1d17dc482cae3de876ced273626 (
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
|
/*
* sorthand.cpp
*
*
*/
#include "sorthand.h"
SortHand::SortHand()
{
}
void SortHand::sortFourOfAKind(Card **cards, struct countAndType *maxCount)
{
int i;
/* find the card that is different from other four */
for (i = 0; i < 5; i++)
if (cards[i]->getType()[0] != maxCount->type)
break;
#ifdef DEBUG
cout << ANSI_COLOR_CYAN << "\ndebug: sortFourOfAKind(): " << cards[i]->getType()
<< " is different from other 4 cards" << endl << ANSI_COLOR_RESET;
#endif
/* put that card at the end */
Card *tmp = cards[4];
cards[4] = cards[i];
cards[i] = tmp;
}
void SortHand::sortThreeOfAKind(Card **cards, struct countAndType *threeCount)
{
int i;
/* find 2 cards that are different from other three */
for (i = 0; i < 5; i++)
if (cards[i]->getType()[0] != threeCount->type)
break;
int j;
for (j = 0; j < 5; j++)
if ((cards[j]->getType()[0] != threeCount->type) && (i != j))
break;
#ifdef DEBUG
cout << ANSI_COLOR_CYAN << "\ndebug: sortThreeOfAKind(): card " << cards[i]->getType()
<< " and " << cards[j]->getType() << " are different from other 3 cards"
<< endl << ANSI_COLOR_RESET;
#endif
/* put those cards at the end */
Card *tmp = cards[4];
Card *tmp2 = cards[3];
if (cards[i]->getRank() < cards[j]->getRank())
{
cards[4] = cards[i];
cards[3] = cards[j];
}
else
{
cards[4] = cards[j];
cards[3] = cards[i];
}
cards[i] = tmp;
cards[j] = tmp2;
}
|