Originally Posted by
SDH
I am making a poker scoring system. One way I thought of doing it was to be able to identify if each card ( 3h - 3 of hearts, 6c - 6 of clubs etc etc) has matching integers or characters.
I don't know about the rules of poker, but it seems a useful intermediate step would be to represent a hand as you have described and then categorize it based on (1) card values and (2) suits. Based on the results of these categorizations you can determine if it is a flush, etc. I think a hand is 5 cards but for illustration suppose it is 7 for the example and represent card value 10 with character '0', Jack with 'J', and hearts, clubs, diamonds and spades each with their initial small letters).
Code:
char hand[7][2] = {
"6s",
"7h",
"8d",
"9c",
"0s",
"Jh",
"Qd",
}
Then categorizing should based on card value should produce a result something like this:
Code:
aces: 0
twos: 0
threes: 0
fours: 0
fives: 0
sixes: 1
sevens: 1
eights: 1
nines: 1
tens: 1
jacks: 1
queens: 1
kings: 0
Categorizing by suit:
Code:
spades: 2
hearts: 2
diamonds: 2
clubs: 1
Use the result to determine the total value of the hand. Personally I don't see how sorting will help you here so I don't understand the comment about bubble sort. The number of cards to test is no greater than 10. Sorting does not help to solve the problem and it does not improve the efficiency.