Example #1
0
 public bool IsOnePair(PokerHand hand)
 {
     return hand.Cards.GroupBy(x => x.Value,
         (y, g) => new { Value = y, Count = g.Count() })
         .Where(z => z.Count == 2)
         .Count() == 1;
 }
        public void IsOnePairFail()
        {
            // Get an instance of a PokerGame
            IPokerRules game = new FunPoker();
            PokerHand hand = new PokerHand();

            // Set the hand
            hand.Cards.Add(new Card(SuitEnum.Heart, ValueEnum.One));
            hand.Cards.Add(new Card(SuitEnum.Spade, ValueEnum.One));
            hand.Cards.Add(new Card(SuitEnum.Club, ValueEnum.One));
            hand.Cards.Add(new Card(SuitEnum.Spade, ValueEnum.King));
            hand.Cards.Add(new Card(SuitEnum.Diamond, ValueEnum.Three));

            // Check if it's true
            Assert.IsFalse(game.IsOnePair(hand));
        }
Example #3
0
        public bool IsOnePair(PokerHand hand)
        {
            Dictionary<ValueEnum, int> counter = new Dictionary<ValueEnum, int>();

            for (int i = 0; i < hand.Cards.Count; i++)
            {
                var value = hand.Cards[i].Value;

                if (!counter.ContainsKey(value))
                    counter[value] = 0;

                counter[value]++;
            }

            return counter.Where(x => x.Value == 2).Count() == 1;
        }
Example #4
0
 public bool IsThreeOfAKind(PokerHand hand)
 {
     throw new NotImplementedException();
 }
Example #5
0
 public bool IsTwoPair(PokerHand hand)
 {
     throw new NotImplementedException();
 }