I'm making a poker hand evaluator for some programming practice which i have been submitting to codereview stack exchange. I need to be able to compare hands properly and for this I need to see the value of pairs. My Current check hand for pairs class
private static PokerHandsRank CheckHandForPairs(Hand hand)
{
var faceCount = (from card in hand.Cards
group card by card.Face
into g
let count = g.Count()
orderby count descending
select count).Take(2).ToList(); // take two to check if multiple pairs of pairs, if second in list is 1 there will be two pairs
switch (faceCount[0])
{
case 1: return PokerHandsRank.HighCard;
case 2: return faceCount[1] == 1 ? PokerHandsRank.Pair : PokerHandsRank.TwoPair;
case 3: return faceCount[1] == 1 ? PokerHandsRank.ThreeOfKind : PokerHandsRank.FullHouse;
case 4: return PokerHandsRank.FourOfKind;
default: throw new Exception("something went wrong here");
}
}
As you can see I've used linq to get a list of the most appeared pairing however I'm not sure how to finish it off to get the face value of the card once I've separated them.
This is my current compareto method
public int CompareTo(Hand other)
{
if (HandRank == other.HandRank) //if the hand rank is equal, sort the cards by face value and compare the two biggest
{
sortHandbyFace(this); // sorts cards into order by face
sortHandbyFace(other);
for (int i = 4; 0 <= i; i--)
{
if (Cards[i].Face == other.Cards[i].Face)
{
if (i == 0) return 0;
continue;
}
return Cards[i].Face > other.Cards[i].Face ? 1 : -1;
}
}
return HandRank > other.HandRank ? 1 : -1;
the compare to works perfect for comparing high card issues however i need to add a check if the two hand ranks are equal and then check if their value is a pair, two pair, fullhouse or three of kind (then to find the highest face value of the pair)
If you need more information on my program feel free to check my codereview post https://codereview.stackexchange.com/questions/152857/beginnings-of-a-poker-hand-classifier-part-2?noredirect=1&lq=1