diff options
author | Kyle K <kylek389@gmail.com> | 2011-02-01 18:09:41 -0600 |
---|---|---|
committer | Kamil Kaminski <kamilkss@gmail.com> | 2011-02-01 18:09:41 -0600 |
commit | 56c6c8d0a485768e591a48a18414305ac3452edb (patch) | |
tree | 08b8dd9c4c0836948c4560efcd8dd20cda66de18 /card.cpp | |
parent | 6c30258da6449f9ffae4b42f4aeda587fe4a3111 (diff) | |
download | poker-56c6c8d0a485768e591a48a18414305ac3452edb.tar.gz poker-56c6c8d0a485768e591a48a18414305ac3452edb.tar.bz2 poker-56c6c8d0a485768e591a48a18414305ac3452edb.zip |
got sorting right
Diffstat (limited to 'card.cpp')
-rw-r--r-- | card.cpp | 37 |
1 files changed, 35 insertions, 2 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(); } |