summaryrefslogtreecommitdiffstats
path: root/sorthand.cpp
blob: e713b7d91d6e1b8da4271bbe44d470ee404fd028 (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
/*
 * sorthand.cpp
 *
 *
 */

#include "sorthand.h"

SortHand::SortHand()
{

}

void SortHand::sortFourOfAKind(Card **cards, struct countAndType *maxCount)
{
#if 0
    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;
#endif

    int k;
    for (k = 0; k < 5; k++)
        if (cards[k]->getType()[0] == maxCount->type)
        {
            cards[k]->specialRank();
#ifdef DEBUG
            cout << ANSI_COLOR_CYAN << "\ndebug: sortFourOfAKind(): "
                 << cards[k]->getType() << " at cards[" << k
                 << "] gets special rank "<< endl << ANSI_COLOR_RESET;
#endif
        }
}

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

    cards[i]->specialRank();
    cards[j]->specialRank();
}