I'm currently making a hand evaluator for poker (5 card). Firstly I deal the hands (not from the same deck) and then I check if each has a pair, three of a kind etc, once a match is found lets say a pair of aces, the hands rank will be set to 2 (1-10, 10 being best) and the value of the card will also be set so 14 for ace (1-14, ace highest).
My problem is trying to sort the suckers, I've tried to overload the operator and then I tried to use sort and made a bool func that checks rank. Am I at least on the right path? Using sort didnt actually seem to sort them it just printed them out hand1,hand2,hand3 etc without any indication of even checking handrank and value (I used the bool func as the 3rd parameter..
I have looked around for an hour or so and this is my last resort so any help whatsoever would be much appreciated.
Also Hand is a class that generates a vector of 5 cards, checking if pair etc is done within the hand upon generation and hand rank and value are private class members.
Thanks!
bool operator > (const Hand &h1) const
{
return !((*this) < h1.handRank);
}
bool operator < (const Hand &h1) const
{
if(handRank < h1.handRank)
{
return handRank < h1.handRank;
}
if(handRank == h1.handRank)
{
return highestValue < h1.highestValue;
}
}
Hands are created in main as hand1, 2 etc.
Each hand containsa vector of 5 cards, each card has a value and a suit.
within each hand int handrank and int highestvalue(value of the highestcard in the current winning hand, eg 2 pair containing aces and 6's, aces would be the highest value)
I have found whether a hand has a pair or a flush etc I just need to sort all of the hands in order of which would win, I'm stuck on how to compare all of the hands at once and see whether one wins or whether for example two have a royal flush