diff options
-rw-r--r-- | card.cpp | 37 | ||||
-rw-r--r-- | game.cpp | 2 |
2 files changed, 36 insertions, 3 deletions
@@ -80,7 +80,8 @@ void Card::rankCard(void) /* 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 */ + * to the left + */ void Card::specialRank(void) { char c; @@ -171,8 +172,36 @@ void Card::sortCards(Card **cards) return; } - /* reverse bubble sort */ int i, j; + int howManyOfSameCards[5] = { 1,1,1,1,1 }; + char c1, c2; + for (i = 0; i < 5; i++) + { + c1 = cards[i]->getType()[0]; + + for (j = 0; j < 5; j++) + { + /* don't count itself */ + if (j == i) + continue; + + c2 = cards[j]->getType()[0]; + if (c1 == c2) + howManyOfSameCards[i] += 1; + } + } + + /* indices that contain 1 are not associated with any other cards, + * indices that are not 1 have a pair or greater, so we want to give + * them higher rank so they get shown all the way on the left + */ + for (i = 0; i < 5; i++) + { + if (howManyOfSameCards[i] != 1) + cards[i]->specialRank(); + } + + /* reverse bubble sort */ Card *tmp; for (i = 0; i < 5; i++) @@ -185,5 +214,9 @@ void Card::sortCards(Card **cards) cards[j+1] = tmp; } } + + /* reset special rank */ + for (i = 0; i < 5; i++) + cards[i]->rankCard(); } @@ -808,7 +808,7 @@ bool Game::hasTwoPairs(Card **cards) int cnt = 0; int i; - /* if there are 2 pairs, they should be 1 index that contains 1 */ + /* if there are 2 pairs, they should be one index that contains 1 */ for (i = 0; i < 5; i++) if (cardsToDiscard[i] == 1) cnt++; |