I am developing a poker game as college project and our current assignment is to write an algorithm to score a hand of 5 cards, so that the scores of two hands can be compar
As you have found, if you add together the values of the cards in the way you have proposed then you can get ambiguities.
100000 + 4^1 + 6^2 + 11^1 + 13^1 = 100064
100000 + 3^1 + 4^1 + 7^2 + 8^1 = 100064
However, addition is not quite the right tool here. You are already using ^
which means you're partway there. Use multiplication instead and you can avoid ambiguities. Consider:
100000 + (4^1 * 6^2 * 11^1 * 13^1)
100000 + (3^1 * 4^1 * 7^2 * 8^1)
This is nearly correct, but there are still ambiguities (for example 2^4 = 4^2
). So, reassign new (prime!) values to each card:
Ace => 2
3 => 3
4 => 5
5 => 7
6 => 11
...
Then, you can multiply the special prime values of each card together to produce a unique value for every possible hand. Add in your value for type of hand (pair, full house, flush, etc) and use that. You may need to increase the magnitude of your hand type values so they stay out of the way of the card value composite.