Last active
August 1, 2016 14:54
-
-
Save mikebranstein/6a80012d42e00d11b6afd31718013fd4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public HandRank GetHandRank() => | |
IsRoyalFlush() ? HandRank.RoyalFlush : | |
IsStraightFlush() ? HandRank.StraightFlush : | |
IsFourOfAKind() ? HandRank.FourOfAKind : | |
IsFullHouse() ? HandRank.FullHouse : | |
IsFlush() ? HandRank.Flush : | |
IsStraight() ? HandRank.Straight : | |
IsThreeOfAKind() ? HandRank.ThreeOfAKind : | |
IsTwoPair() ? HandRank.TwoPair : | |
IsPair() ? HandRank.Pair : | |
HandRank.HighCard; | |
private bool IsRoyalFlush() => IsFlush() && Cards.All(x => x.Value >= CardValue.Ten); | |
private bool IsStraightFlush() => IsStraight() && IsFlush(); | |
private bool IsFourOfAKind() => | |
Cards.GroupBy(x => x.Value).Any(x => x.Count() == 4); | |
private bool IsFullHouse() => | |
Cards.GroupBy(x => x.Value).Any(x => x.Count() == 3) && | |
Cards.GroupBy(x => x.Value).Any(x => x.Count() == 2); | |
private bool IsFlush() => Cards.All(x => x.Suit == Cards.First().Suit); | |
private bool IsStraight() => | |
Cards.GroupBy(x => x.Value).Count() == 5 && | |
Cards.Max(x => x.Value) - Cards.Min(x => x.Value) == 4; | |
private bool IsThreeOfAKind() => Cards.GroupBy(x => x.Value).Any(x => x.Count() == 3); | |
private bool IsTwoPair() => Cards.GroupBy(x => x.Value).Select(grp => new { grp.Key, Count = grp.Count() }) | |
.GroupBy(x => x.Count).Any(x => x.Count() == 2); | |
private bool IsPair() => Cards.GroupBy(x => x.Value).Any(x => x.Count() == 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment