I am writing a Poker game followed by a Poker playing AI in Java as a college project. In my code, a hand is stored as a 5 element array ordered, firstly, by the "most important" cards and then by card value, as shown in the following examples
3 of a Kind: [4H, 4D, 4S, KH, 8C]
Full House: [7H, 7D, 7C, 9S, 9C]
Pair: [3H, 3C, AS, 4D, 2C]
These hands are also represented using a 24-bit binary string in the form of:
|- 4 bits -| |- 4 bits -| |- 4 bits -| |- 4 bits -| |- 4 bits -| |- 4 bits -|
Hand Type Best Card ... ... ... Worst Card
where Hand Type corresponds to:
High Hand = 0
One Pair = 1
Two Pair = 2
...
Straight Flush = 8
Royal Flsuh = 9
and the 4-bits for each card is its value (0 - 12 as it is card value minus 2).
These binary strings then allow cards to be compared to each other - a higher value is a better hand.
Our next task is to create an algorithm that determines the probability of the hand improving if a given card in the hand is discarded and replaced with the next (random) card in the deck. As of now, we are under the assumption that there are no other players/hands, so there are 47 cards left in the deck and discarded cartds cannot be dealt again. We were given examples such as if we have the hand [9H, 6D, 5C, 3D, 2S] (a broken straight) then what is the probability of exchanging the 9 for a 4 and completing the straight?
We do not, yet, need to determine whether or not we should discard this card based on the probability - we are strictly just finding the probability that the hand will be improved.
Of course, this becomes quite complex when you need an algorithm that can calculate the probability of impoving any given hand into a better one (e.g. certain Straights could be changed to a Flush or a Straight Flush or a Royal Flush).
Since my hands have a binary representation (this was not a requirement for the project - it was a result of one of my posts), is there a more simple approach to solving this problem?