internal static bool IsFlush(Hand hand) { var firstSuit = hand.Cards.First().Suit; bool allAreOfTheSameSuit = hand.Cards.All(card => card.Suit == firstSuit); return allAreOfTheSameSuit; }
internal override void Evaluate(Hand hand) { var uniqueCardValues = hand.Cards.Select(card => card.Value).Distinct().ToArray(); bool isFourOfAKindOrAFullHouse = uniqueCardValues.Length == NeededUniqueCardsCount; if (!isFourOfAKindOrAFullHouse) { this.Successor.Evaluate(hand); return; } var uniqueCardValueToCheck = uniqueCardValues[0]; int cardValueFrequency = 0; foreach (var card in hand.Cards) { var currentCardValue = card.Value; if (uniqueCardValueToCheck == currentCardValue) { cardValueFrequency += 1; } } bool isFourOfAKind = (cardValueFrequency == 1) || (cardValueFrequency == 4); Console.WriteLine("It is {0}!", isFourOfAKind == true ? "Four Of A Kind" : "Full House"); }
public static void Main() { var cardsFormingRoyalFlush = new List<Card> { new Card(CardValue.King, CardSuit.Club), new Card(CardValue.Jack, CardSuit.Club), new Card(CardValue.Ten, CardSuit.Club), new Card(CardValue.Ace, CardSuit.Club), new Card(CardValue.Queen, CardSuit.Club) }; var handWithRoyalFlush = new Hand(cardsFormingRoyalFlush); var royalFlushChecker = new RoyalFlush(); royalFlushChecker.Evaluate(handWithRoyalFlush); var cardsFormingStraightFlush = new List<Card> { new Card(CardValue.Three, CardSuit.Club), new Card(CardValue.Five, CardSuit.Club), new Card(CardValue.Four, CardSuit.Club), new Card(CardValue.Seven, CardSuit.Club), new Card(CardValue.Six, CardSuit.Club) }; var handWithStraightFlush = new Hand(cardsFormingStraightFlush); royalFlushChecker.Evaluate(handWithStraightFlush); var cardsFormingFourOfAKind = new List<Card> { new Card(CardValue.Jack, CardSuit.Heart), new Card(CardValue.Five, CardSuit.Club), new Card(CardValue.Jack, CardSuit.Diamond), new Card(CardValue.Jack, CardSuit.Spade), new Card(CardValue.Jack, CardSuit.Club) }; var handWithFourOfAKind = new Hand(cardsFormingFourOfAKind); royalFlushChecker.Evaluate(handWithFourOfAKind); var cardsFormingFullHouse = new List<Card> { new Card(CardValue.Jack, CardSuit.Heart), new Card(CardValue.Five, CardSuit.Club), new Card(CardValue.Jack, CardSuit.Diamond), new Card(CardValue.Five, CardSuit.Spade), new Card(CardValue.Jack, CardSuit.Club) }; var handWithFullHouse = new Hand(cardsFormingFullHouse); royalFlushChecker.Evaluate(handWithFullHouse); var cardsFormingFlush = new List<Card> { new Card(CardValue.Jack, CardSuit.Heart), new Card(CardValue.Five, CardSuit.Heart), new Card(CardValue.Two, CardSuit.Heart), new Card(CardValue.King, CardSuit.Heart), new Card(CardValue.Eight, CardSuit.Heart) }; var handWithFlush = new Hand(cardsFormingFlush); royalFlushChecker.Evaluate(handWithFlush); }
private bool IsRoyalFlush(Hand hand) { bool isFlush = HandEvaluatorHelper.IsFlush(hand); if (!isFlush) { return false; } var cardsValues = new HashSet<CardValue>(hand.Cards.Select(card => card.Value)); return cardsValues.SetEquals(this.NeededCardValues); }
internal override void Evaluate(Hand hand) { bool isFlush = HandEvaluatorHelper.IsFlush(hand); if (isFlush) { Console.WriteLine("It is Flush!"); } else { this.Successor.Evaluate(hand); } }
internal override void Evaluate(Hand hand) { bool isStraight = HandEvaluatorHelper.IsStraight(hand); if (isStraight) { Console.WriteLine("It is Straight!"); } else { // since there is no successor yet Console.WriteLine("It is lower than Straight!"); } }
internal static bool IsStraight(Hand hand) { var values = hand.Cards.Select(card => (int)card.Value).ToArray(); Array.Sort(values); for (int i = 0; i < values.Length - 1; i++) { int currentValue = values[i]; int nextValue = values[i + 1]; bool areSequental = (currentValue + 1) == nextValue; if (!areSequental) { return false; } } return true; }