public void SetValue() { Value = findValue(this); }
public ValueDegreePair findValue(Hand hand) { if (Cards.Count == 0) { throw new ArgumentNullException("Hand is empty."); } bool isFlush = isHandFlush(); bool isStraight = isHandStraight(); ValueDegreePair retValue = new ValueDegreePair(); if (isFlush) { if (isHandRoyal()) { retValue.Value = ValueType.RoyalFlush; retValue.Degree = Card.RankType.Ace; return retValue; } else if (isStraight) { retValue.Value = ValueType.StraightFlush; retValue.Degree = hand.HighCards.Max(); return retValue; } } if (isNOfAKind() == 4) { retValue.Value = ValueType.FourOfAKind; retValue.Degree = hand.Counts.First(x => x.Value == 4).Key; return retValue; } if (isFullHouse()) { retValue.Value = ValueType.FullHouse; retValue.Degree = hand.Counts.First(x => x.Value == 3).Key; return retValue; } if (isFlush) { retValue.Value = ValueType.Flush; retValue.Degree = hand.HighCards.Max(); return retValue; } if (isStraight) { retValue.Value = ValueType.Straight; retValue.Degree = hand.HighCards.Max(); return retValue; } if (isNOfAKind() == 3) { retValue.Value = ValueType.ThreeOfAKind; retValue.Degree = hand.Counts.First(x => x.Value == 3).Key; return retValue; } if (isTwoPairs()) { retValue.Value = ValueType.TwoPairs; Dictionary<Card.RankType, int> pairs = new Dictionary<Card.RankType, int>(); foreach (var key in hand.Counts.Keys) { if (hand.Counts[key] == 2) { pairs.Add(key, hand.Counts[key]); } } retValue.Degree = pairs.Keys.Max(); return retValue; } if (isNOfAKind() == 2) { retValue.Value = ValueType.OnePair; retValue.Degree = hand.Counts.First(x => x.Value == 2).Key; return retValue; } retValue.Value = ValueType.HighCard; retValue.Degree = hand.HighCards.Max(); return retValue; }