Hi all,
i am trying to find a way of testing 2 equal poker hands (for example: two hands with two pairs) to determine which one wins according to the highest ranked card.
i have already tested the hands to determine there rank (for example: three of a kind, two pair etc..)
the code i have so far for determining the best hand is as follows.
if (winningHand.Length <= 0)
{
winningHand = myHand;
bestHand = hand;
handRef++;
}
else if (allHandTypes[handRef] < allHandTypes[handRef - 1])
{
winningHand = myHand;
bestHand = hand;
handRef++;
}
else if (allHandTypes[handRef] == allHandTypes[handRef - 1])
{
}
}
which works well up until there are 2 hands of the same rank as explained above.
what i am trying to do is compare the hand in "bestHand" to the hand in "hand" if and when we get to the last "else if" statement, then if the hand in "hand" is better than the hand in "bestHnad" then replace "bestHand" with the hand in "hand" and add "myHand" to "winningHand" any help on this would be massively appreciated or just a point in the right direction.
Thank you in advance Lee.
VulpesPosted Nov 21, 2014, 4:08 PM
Added or altered code has been highlighted.
lee croydonPosted Nov 23, 2014, 4:51 AM
Vithal WadjePosted Nov 21, 2014, 1:10 PM
VulpesPosted Nov 21, 2014, 12:27 PM
As I've got some other stuff to do right now and it needs some careful thought, I'll try and get back later today.
lee croydonPosted Nov 21, 2014, 12:15 PM
as of now the entire code is below ignore the betting methods at the bottom they are a work in progress : )
VulpesPosted Nov 21, 2014, 12:04 PM
lee croydonPosted Nov 21, 2014, 11:47 AM
VulpesPosted Nov 21, 2014, 11:37 AM
lee croydonPosted Nov 21, 2014, 11:31 AM
VulpesPosted Nov 21, 2014, 11:22 AM
This is because if you have the same two pairs, pair or card high, the other cards in the hand will be used to determine which is the better hand. You also have a similar problem with flushes.
So, if two players A and B both have a pair of Aces and a pair of Kings and A's fifth card is a Queen but B's fifth card is a Jack, then A will be the winner.
I think therefore that in the part of your code which determines the ranking of a given hand and it's description, you will need to generate an additional ranking which can be used to distinguish between otherwise equally ranking hands.
You could perhaps use a struct to bind the two rankings together.
As regards the calculation of the second ranking, if we say a deuce has a value of 2, a trey has a value of 3 and so on up to a ten and then a Jack 11, Queen 12, King 13 and Ace 14, you could calculate the ranking as follows:
Straights - the value of the highest card (e.g. AKQJ10 has a ranking of 14).
Flushes (or card high) - multiply the values of all 5 cards together (e.g. AJ972 has a ranking of 14 * 11 * 9 * 7 * 2 = 19404)
Four (or three) of a kind - the value of such card (e.g 3333A has ranking of 3).
Full house - multiply value of 3 of a kind by 14 and add value of pair (e.g. AAAKK has ranking of 14 *14 + 13 = 209).
Two pairs - multiply value of pairs together and add value of fifth card (e.g. AAKK2 has ranking of 14 * 13 + 2 = 184)
Pair - multiply value of pair by 14 * 14 * 14 = 2744 and add the product of the values of the other three cards (e.g.QQ973 has ranking of 2744 *12 + 9 * 7 * 3 = 33117)
Hope these remarks are of some help.