public static double EvaluatePokerHand(Hand hand) { double points = 0; int flush = 1, straight = 1; //flushes and straights for (int i = 1; i < hand.Count; i++) { if (hand[0].Suit == hand[i].Suit) flush++; if (hand[i].FaceValue == hand[0].FaceValue + i) straight++; } if (straight == 5) { points = flush == 5 ? 450 + hand[4].TrueValue : 250 + hand[4].TrueValue; return points; } if (flush == 5) return 300 + EvaluateCards(hand); int numberOfPairs = 0, numberOfTres = 0, cardValue = 0; //check for pairs/threes/fours for (int i = 0; i < hand.Count - 1; i++) { int sameValue = 1; for (int j = i + 1; j < hand.Count; j++) { if (hand[i].FaceValue == hand[j].FaceValue) sameValue++; if (sameValue == 4) return 400 + hand[j].TrueValue; } if (sameValue == 3) { numberOfTres++; numberOfPairs--; cardValue = hand[i].TrueValue; } if (sameValue == 2) numberOfPairs++; } //two pairs if (numberOfPairs == 2) { int pairNumber = 2; int i = hand.Count - 1; while (hand.Count > 1) { if (hand[i - 1].FaceValue == hand[i].FaceValue) { if (pairNumber == 2) { points = 13 * (int)hand[i].FaceValue; pairNumber--; } else points += hand[i].TrueValue; hand.Remove(hand[i]); hand.Remove(hand[i - 1]); i -= 2; } else i--; } return points + EvaluateCards(hand); } //pair if (numberOfPairs == 1 && numberOfTres == 0) { int i = hand.Count - 1; while (hand.Count > 3) { if (hand[i - 1].FaceValue == hand[i].FaceValue) { points += hand[i].TrueValue; hand.Remove(hand[i]); hand.Remove(hand[i - 1]); return points + EvaluateCards(hand); } i--; } } //3 of a kind or house if (numberOfTres == 1) { if (numberOfPairs == 1) return 350 + cardValue; return 200 + cardValue; } //high card return EvaluateCards(hand); }