private int[] TwoPairs(Card[] hand) { var ordered = hand.OrderBy(c => c.Value).Select(c => c.Value).ToList(); if (ordered.GroupBy(c => c).Count(c => c.Count() > 1) == 2) { IEnumerable<int> result = new[] {3}; return result.Concat( ordered.GroupBy(c => c).Where(c => c.Count() > 1).Select(c => c.Key).OrderByDescending(c => c)) .Concat(ordered.GroupBy(c => c).Where(c => c.Count() == 1).Select(c => c.Key)).ToArray(); } return null; }
int[] ThreeOfAkind(Card[] hand) { var ordered = hand.OrderBy(c => c.Value).Select(c => c.Value).ToList(); if (ordered[0] == ordered[2] || ordered[1] == ordered[3] || ordered[2] == ordered[4]) { var result = new[] { 4, ordered[2] }; return result.Concat(GetOrderedCardValues(hand.Where(c => c.Value != ordered[2]))).ToArray(); } return null; }
private int[] OnePair(Card[] hand) { var ordered = hand.OrderBy(c => c.Value).Select(c => c.Value).ToList(); if (ordered.GroupBy(c => c).Count(c => c.Count() > 1) == 1) { var result = new[] { 2 }; return result.Concat( ordered.GroupBy(c => c).Where(c => c.Count() > 1).Select(c => c.Key).OrderByDescending(c => c)). Concat(ordered.GroupBy(c => c).Where(c => c.Count() == 1).OrderByDescending(c=>c.Key).Select(c=>c.Key)).ToArray(); } return null; }
bool IsStraight(Card[] hand) { var ordered = hand.OrderBy(c => c.Value).Select(c=>c.Value).ToList(); if (ordered[0] + 1 == ordered[1] && ordered[1] + 1 == ordered[2] && ordered[2] + 1 == ordered[3] && ordered[3] + 1 == ordered[4]) { return true; } if (ordered[0] == 2 && ordered[1] == 3 && ordered[2] == 4 && ordered[3] == 5 && ordered[4] == ACE) { return true; } return false; }
int[] FullHouse(Card[] hand) { var ordered = hand.OrderBy(c => c.Value).Select(c => c.Value).ToList(); if (ordered[0] == ordered[2] && ordered[3] == ordered[4]) return new[] { 7, ordered[0], ordered[3] }; if (ordered[0] == ordered[1] && ordered[2] == ordered[4]) return new[] { 7, ordered[2], ordered[0] }; return null; }
int[] FourOfKind(Card[] hand) { var ordered = hand.OrderBy(c => c.Value).Select(c => c.Value).ToList(); if (ordered[0] == ordered[3] || ordered[1] == ordered[4]) return new[] { 8, ordered[1] }; return null; }