public static RoyalFlush TryGetRoyalFlush(Card[] cards) { if (cards.First().CardNomination.Is(MajorCardType.Ace) && TryGetStraightFlush(cards) != null) return new RoyalFlush(); return null; }
public static Flush TryGetFlush(Card[] cards) { var first = cards.First(); return cards.Skip(1).All(c => c.Suit == first.Suit) ? new Flush(cards.Select(c => c.CardNomination).ToArray()) : null; }
public static Flush TryGetFlush(Card[] cards) { return cards.Skip(1).Aggregate( new {Flush = true, cards.First().Suit}, (acc, card) => new { Flush = acc.Flush && acc.Suit == card.Suit, card.Suit } ).Flush ? new Flush(cards.Select(c => c.CardNomination).ToArray()) : null; }
public static Straight TryGetStraight(Card[] cards) { var first = cards.First(); return cards.Skip(1).Aggregate(new {IsStraight = true, Card = first}, (acc, card) => new { IsStraight = acc.IsStraight && acc.Card.CardNomination.Value - card.CardNomination.Value == 1, Card = card }).IsStraight ? new Straight(first.CardNomination) // A,5,4,3,2 : cards.Select(c => c.CardNomination) .Except(new CardNomination[] { new MajorCardNomination(MajorCardType.Ace), new MinorCardNomination(5), new MinorCardNomination(4), new MinorCardNomination(3), new MinorCardNomination(2) }).Any() ? null : new Straight(new MinorCardNomination(5)); }
public static bool IsPlayer1Wins(Card[][] cardSets) { return GetHand(cardSets.First().OrderByDescending(c => c.CardNomination).ToArray()) .CompareTo(GetHand(cardSets.Skip(1).First().OrderByDescending(c => c.CardNomination).ToArray())) == 1; }