public static int CompareFullHouses(Hand fullHouse1, Hand fullHouse2) { fullHouse1.Sort(); fullHouse2.Sort(); Card fullHouse1ThreeOfAKind = NFIWhatToCallMethod(fullHouse1, Combination.ThreeOfAKind); Card fullHouse2ThreeOfAKind = NFIWhatToCallMethod(fullHouse2, Combination.ThreeOfAKind); if (fullHouse1ThreeOfAKind == fullHouse2ThreeOfAKind) { Card fullHouse1Pair = NFIWhatToCallMethod(fullHouse1, Combination.OnePair); Card fullHouse2Pair = NFIWhatToCallMethod(fullHouse2, Combination.OnePair); if (fullHouse1Pair.Value == fullHouse2Pair.Value) return 0; else if (fullHouse1Pair > fullHouse2Pair) return 1; else return -1; } else if (fullHouse1ThreeOfAKind > fullHouse2ThreeOfAKind) return 1; else return -1; }
public static Card NFIWhatToCallMethod(Hand fullHouse, Combination type) { // This method is used for finding the highest three-of-a-kind or highest // pair of a fullhouse hand. How would I name this method??..NFI? Exactly! if (fullHouse.BestCombination != Combination.FullHouse) throw new InvalidOperationException("This method is only designed to be used by Full House hands."); fullHouse.Sort(); Card highest = new Card(Rank.Unassigned, Suit.Unassigned); switch (type) { case Combination.ThreeOfAKind: { int count = 0; foreach (Card c in fullHouse) { if (c.Value == highest.Value) count++; else { highest = c; count = 1; } if (count == 3) break; } break; } case Combination.OnePair: { int count = 0; Card ignore = NFIWhatToCallMethod(fullHouse, Combination.ThreeOfAKind); foreach (Card c in fullHouse) { if (c.Value == ignore.Value) continue; else if (c.Value == highest.Value) count++; else { highest = c; count = 1; } if (count == 2) break; } break; } default: throw new InvalidOperationException("This method only accetps 'type' parameters of Combination.OnePair and Combination.ThreeOfAKind."); } return highest; }