Esempio n. 1
0
        public bool Analyze(IEnumerable <HandHistories.Objects.Cards.Card> playerCards, BoardCards boardCards)
        {
            if (playerCards == null || boardCards == null || playerCards.Count() != 2 || boardCards.Count() < 2)
            {
                return(false);
            }

            if (HandAnalyzerHelpers.IsPair(playerCards, 1))
            {
                return(false);
            }

            var allCards = HandAnalyzerHelpers.CombineCardLists(boardCards, playerCards);

            if (HandAnalyzerHelpers.IsNofKind(allCards, 3) || HandAnalyzerHelpers.IsNofKind(allCards, 4))
            {
                return(false);
            }

            var topTwo = boardCards.OrderByDescending(x => x.RankNumericValue).Take(2).Distinct();

            if (topTwo != null && topTwo.Count() == 2)
            {
                return(playerCards.All(x => topTwo.Any(t => t.RankNumericValue == x.RankNumericValue)));
            }

            return(false);
        }
Esempio n. 2
0
        public bool Analyze(IEnumerable <HandHistories.Objects.Cards.Card> playerCards, BoardCards boardCards)
        {
            if (playerCards == null || boardCards == null || playerCards.Count() != 2 || boardCards.Count() == 0)
            {
                return(false);
            }

            if (!HandAnalyzerHelpers.IsPair(playerCards, 1))
            {
                return(false);
            }

            var allCards = HandAnalyzerHelpers.CombineCardLists(playerCards, boardCards);

            if (HandAnalyzerHelpers.IsNofKind(allCards, 4))
            {
                return(false);
            }

            var groupedCards = allCards.GroupBy(x => x.RankNumericValue).OrderByDescending(x => x.Key);

            var trips = groupedCards.FirstOrDefault(x => x.Count() == 3);

            if (trips != null)
            {
                var pair = groupedCards.Where(x => x.Key != trips.Key).FirstOrDefault(x => x.Count() >= 2);
                if (pair != null && pair.Key == playerCards.First().RankNumericValue)
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 3
0
        public bool Analyze(IEnumerable <HandHistories.Objects.Cards.Card> playerCards, BoardCards boardCards)
        {
            if (playerCards == null || boardCards == null || playerCards.Count() != 2 || boardCards.Count() < 2)
            {
                return(false);
            }

            if (HandAnalyzerHelpers.IsPair(playerCards, 1))
            {
                return(false);
            }

            var allCards = HandAnalyzerHelpers.CombineCardLists(boardCards, playerCards);

            if (HandAnalyzerHelpers.IsNofKind(allCards, 3) || HandAnalyzerHelpers.IsNofKind(allCards, 4))
            {
                return(false);
            }

            var pairs = allCards.GroupBy(x => x.RankNumericValue).Where(x => x.Count() == 2);

            if (pairs != null && pairs.Count() > 1)
            {
                var bottomPair = boardCards.Min(x => x.RankNumericValue);
                return(pairs.ElementAt(1).Key == bottomPair &&
                       playerCards.Any(x => x.RankNumericValue == bottomPair) &&
                       !playerCards.Any(x => pairs.First().Key == x.RankNumericValue));
            }

            return(false);
        }
Esempio n. 4
0
        public bool Analyze(IEnumerable <HandHistories.Objects.Cards.Card> playerCards, BoardCards boardCards)
        {
            if (playerCards == null || boardCards == null || playerCards.Count() != 2 || boardCards.Count() < 2)
            {
                return(false);
            }

            var allCards = HandAnalyzerHelpers.CombineCardLists(boardCards, playerCards);

            if (HandAnalyzerHelpers.IsNofKind(allCards, 3) || HandAnalyzerHelpers.IsNofKind(allCards, 4))
            {
                return(false);
            }

            var pairs = allCards.GroupBy(x => x.RankNumericValue).OrderByDescending(x => x.Key).Where(x => x.Count() == 2);

            if (pairs != null && pairs.Count() > 1)
            {
                var bottomTwo = boardCards.OrderBy(x => x.RankNumericValue).Take(2).Distinct();
                if (bottomTwo != null && bottomTwo.Count() == 2)
                {
                    return(pairs.Take(2).All(p => bottomTwo.Any(t => t.RankNumericValue == p.Key)) &&
                           playerCards.All(x => bottomTwo.Any(t => t.RankNumericValue == x.RankNumericValue)));
                }
            }

            return(false);
        }
Esempio n. 5
0
        public bool Analyze(IEnumerable <HandHistories.Objects.Cards.Card> playerCards, BoardCards boardCards)
        {
            if (playerCards == null || boardCards == null || playerCards.Count() != 2 || boardCards.Count() == 0)
            {
                return(false);
            }

            var allCards = HandAnalyzerHelpers.CombineCardLists(boardCards, playerCards);

            var pairs = allCards.GroupBy(x => x.RankNumericValue).Where(x => x.Count() > 1);

            if (pairs.Count() == 0)
            {
                return(true);
            }

            if (pairs.Count() == 1)
            {
                var midIndex = boardCards.Count / 2;
                if (midIndex < boardCards.Count)
                {
                    var midCard = boardCards.OrderByDescending(x => x.RankNumericValue).ElementAt(midIndex).RankNumericValue;
                    return(pairs.First().Key < midIndex);
                }
            }

            return(false);
        }
        public bool Analyze(IEnumerable <HandHistories.Objects.Cards.Card> playerCards, BoardCards boardCards)
        {
            if (playerCards == null || boardCards == null || playerCards.Count() != 2 || boardCards.Count() < 3)
            {
                return(false);
            }

            if (playerCards.Any(p => boardCards.Any(b => b.RankNumericValue == p.RankNumericValue)))
            {
                return(false);
            }

            var allCards = HandAnalyzerHelpers.CombineCardLists(playerCards, boardCards);
            var rankList = allCards.Select(x => x.RankNumericValue).Distinct().ToList();

            if (allCards.Any(x => x.Rank == Cards.Card.PossibleRanksHighCardFirst.First()))
            {
                rankList.Add(1);
            }
            rankList.Sort();

            List <int> straightDraw = new List <int>();

            for (int i = 0; i < rankList.Count; i++)
            {
                if (!straightDraw.Any() || (rankList[i] == straightDraw.Last() + 1))
                {
                    straightDraw.Add(rankList[i]);
                    continue;
                }

                if (straightDraw.Count == 3)
                {
                    if (HandAnalyzerHelpers.IsStraight(straightDraw))
                    {
                        if (rankList.Any(x => x == straightDraw.Max() + 2) && rankList.Any(x => x == straightDraw.Min() - 2))
                        {
                            straightDraw.Add(straightDraw.Max() + 2);
                            straightDraw.Add(straightDraw.Min() - 2);

                            if (straightDraw.Contains(1))
                            {
                                straightDraw[straightDraw.IndexOf(1)] = Cards.Card.GetRankNumericValue(Cards.Card.PossibleRanksHighCardFirst.First());
                            }

                            if (playerCards.All(x => straightDraw.Contains(x.RankNumericValue)))
                            {
                                return(true);
                            }
                        }
                    }
                }

                straightDraw.Clear();
                straightDraw.Add(rankList[i]);
            }

            return(false);
        }
Esempio n. 7
0
        internal static bool IsFlushDraw(IEnumerable <Cards.Card> playerCards, BoardCards boardCards, int amountOfPlayersCardsInDraw, bool isBackdoor = false)
        {
            if (playerCards == null || boardCards == null || playerCards.Count() != 2 || boardCards.Count() < 3)
            {
                return(false);
            }

            var allCards   = HandAnalyzerHelpers.CombineCardLists(playerCards, boardCards);
            var suitGroups = allCards.GroupBy(x => x.Suit);
            var drawGroup  = suitGroups.FirstOrDefault(x => x.Count() == (isBackdoor ? 3 : 4));

            if (drawGroup == null || suitGroups.Any(x => x.Count() > drawGroup.Count()) || playerCards.Count(x => drawGroup.Any(d => d.CardStringValue == x.CardStringValue)) != amountOfPlayersCardsInDraw)
            {
                return(false);
            }

            return(true);
        }
Esempio n. 8
0
        public bool Analyze(IEnumerable <HandHistories.Objects.Cards.Card> playerCards, BoardCards boardCards)
        {
            if (playerCards == null || boardCards == null || playerCards.Count() != 2 || boardCards.Count() == 0)
            {
                return(false);
            }

            var allCards = HandAnalyzerHelpers.CombineCardLists(boardCards, playerCards);

            if (HandAnalyzerHelpers.IsPair(playerCards, 1) && HandAnalyzerHelpers.IsPair(allCards, 1))
            {
                if (boardCards.All(x => x.RankNumericValue < playerCards.First().RankNumericValue))
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 9
0
        public bool Analyze(IEnumerable <HandHistories.Objects.Cards.Card> playerCards, BoardCards boardCards)
        {
            if (boardCards == null || playerCards == null || playerCards.Count() == 0 || boardCards.Count == 0)
            {
                return(false);
            }

            var allCards = HandAnalyzerHelpers.CombineCardLists(boardCards, playerCards);

            if (HandAnalyzerHelpers.IsNofKind(allCards, 3) || HandAnalyzerHelpers.IsNofKind(allCards, 4))
            {
                return(false);
            }

            return(!HandAnalyzerHelpers.IsPair(playerCards, 1) &&
                   !playerCards.Any(p => boardCards.Any(b => b.Rank == p.Rank)) &&
                   HandAnalyzerHelpers.IsPair(boardCards, 2));
        }
Esempio n. 10
0
        public bool Analyze(IEnumerable <Cards.Card> playerCards, BoardCards boardCards)
        {
            if (playerCards == null || boardCards == null || playerCards.Count() != 2 || boardCards.Count() < 3)
            {
                return(false);
            }

            if (playerCards.Any(p => boardCards.Any(b => b.RankNumericValue == p.RankNumericValue)))
            {
                return(false);
            }

            var rankList = HandAnalyzerHelpers.CombineCardLists(playerCards, boardCards).Where(x => x.Rank != Cards.Card.PossibleRanksHighCardFirst.First()).Select(x => x.RankNumericValue).Distinct().ToList();

            rankList.Sort();

            List <int> straightDraw = new List <int>();

            for (int i = 0; i < rankList.Count; i++)
            {
                if (!straightDraw.Any() || (rankList[i] == straightDraw.Last() + 1))
                {
                    straightDraw.Add(rankList[i]);
                    continue;
                }

                if (straightDraw.Count == 4)
                {
                    if (HandAnalyzerHelpers.IsStraight(straightDraw) &&
                        playerCards.Any(x => straightDraw.Contains(x.RankNumericValue)) &&
                        playerCards.Any(x => !straightDraw.Contains(x.RankNumericValue)))
                    {
                        return(true);
                    }
                }

                straightDraw.Clear();
                straightDraw.Add(rankList[i]);
            }

            return(false);
        }
Esempio n. 11
0
        public virtual bool Analyze(IEnumerable <HandHistories.Objects.Cards.Card> playerCards, BoardCards boardCards)
        {
            if (playerCards == null || boardCards == null || playerCards.Count() != 2 || boardCards.Count() == 0)
            {
                return(false);
            }

            var allCards = HandAnalyzerHelpers.CombineCardLists(boardCards, playerCards);

            if (HandAnalyzerHelpers.IsPair(playerCards, 1) || !HandAnalyzerHelpers.IsPair(allCards, 1))
            {
                return(false);
            }

            if (playerCards.Any(c => c.RankNumericValue == boardCards.Min(x => x.RankNumericValue)))
            {
                return(true);
            }

            return(false);
        }
Esempio n. 12
0
        public bool Analyze(IEnumerable <HandHistories.Objects.Cards.Card> playerCards, BoardCards boardCards)
        {
            if (playerCards == null || boardCards == null || playerCards.Count() != 2 || boardCards.Count() < 2)
            {
                return(false);
            }

            if (HandAnalyzerHelpers.IsPair(playerCards, 1))
            {
                return(false);
            }

            var allCards = HandAnalyzerHelpers.CombineCardLists(boardCards, playerCards);

            if (HandAnalyzerHelpers.IsNofKind(allCards, 3) || HandAnalyzerHelpers.IsNofKind(allCards, 4))
            {
                return(false);
            }

            var pairs       = allCards.GroupBy(x => x.RankNumericValue).OrderByDescending(x => x.Key).Where(x => x.Count() == 2);
            var sortedBoard = boardCards.OrderBy(x => x.RankNumericValue);

            if (pairs != null && pairs.Count() > 1 && sortedBoard != null && sortedBoard.Count() >= 2)
            {
                pairs = pairs.Take(2);
                var bottomTwo = boardCards.OrderBy(x => x.RankNumericValue).Take(2).Distinct();

                if (bottomTwo != null && bottomTwo.Count() == 2)
                {
                    return(pairs.Any(x => x.Key == sortedBoard.First().RankNumericValue) &&
                           pairs.Any(x => x.Key == sortedBoard.Last().RankNumericValue) &&
                           playerCards.Any(x => x.RankNumericValue == sortedBoard.First().RankNumericValue) &&
                           playerCards.Any(x => x.RankNumericValue == sortedBoard.Last().RankNumericValue));
                }
            }

            return(false);
        }
Esempio n. 13
0
        public virtual bool Analyze(IEnumerable <HandHistories.Objects.Cards.Card> playerCards, BoardCards boardCards)
        {
            if (playerCards == null || boardCards == null || playerCards.Count() != 2 || boardCards.Count() < 2)
            {
                return(false);
            }

            var allCards = HandAnalyzerHelpers.CombineCardLists(boardCards, playerCards);

            if (HandAnalyzerHelpers.IsPair(playerCards, 1) || !HandAnalyzerHelpers.IsPair(allCards, 1))
            {
                return(false);
            }

            var thirdCardRank = boardCards.OrderByDescending(x => x.RankNumericValue).ElementAt(2).RankNumericValue;

            if (playerCards.Any(c => c.RankNumericValue == thirdCardRank))
            {
                return(true);
            }

            return(false);
        }
Esempio n. 14
0
        public bool Analyze(IEnumerable <HandHistories.Objects.Cards.Card> playerCards, BoardCards boardCards)
        {
            if (playerCards == null || boardCards == null || playerCards.Count() != 2 || boardCards.Count() < 2)
            {
                return(false);
            }

            var allCards = HandAnalyzerHelpers.CombineCardLists(boardCards, playerCards);

            if (HandAnalyzerHelpers.IsNofKind(allCards, 3) || HandAnalyzerHelpers.IsNofKind(allCards, 4))
            {
                return(false);
            }

            var pairs = allCards.GroupBy(x => x.RankNumericValue).Where(x => x.Count() == 2);

            if (pairs != null && pairs.Count() > 1)
            {
                return(boardCards.Any(x => x.RankNumericValue > pairs.Max(p => p.Max(m => m.RankNumericValue))));
            }

            return(false);
        }
Esempio n. 15
0
        public bool Analyze(IEnumerable <Cards.Card> playerCards, BoardCards boardCards)
        {
            if (playerCards == null || boardCards == null || playerCards.Count() != 2 || boardCards.Count() < 3)
            {
                return(false);
            }

            if (HandAnalyzerHelpers.IsPair(playerCards, 1))
            {
                return(false);
            }

            if (playerCards.Any(p => boardCards.Any(b => b.RankNumericValue == p.RankNumericValue)))
            {
                return(false);
            }

            var allCards = HandAnalyzerHelpers.CombineCardLists(playerCards, boardCards);
            var rankList = allCards.Select(x => x.RankNumericValue).Distinct().ToList();

            if (allCards.Any(x => x.Rank == Cards.Card.PossibleRanksHighCardFirst.First()))
            {
                rankList.Add(1);
            }
            rankList.Sort();

            List <int> currentSequence  = new List <int>();
            List <int> previousSequence = new List <int>();

            for (int i = 0; i < rankList.Count; i++)
            {
                if (!currentSequence.Any() || (rankList[i] == currentSequence.Last() + 1))
                {
                    currentSequence.Add(rankList[i]);
                    continue;
                }

                if (currentSequence.Count >= 1 && currentSequence.Count <= 3)
                {
                    if (!previousSequence.Any())
                    {
                        previousSequence = new List <int>(currentSequence);
                    }
                    else if (currentSequence.Min() - previousSequence.Max() > 3)
                    {
                        if (previousSequence.Count() == 3)
                        {
                            if (previousSequence.Contains(1))
                            {
                                previousSequence[previousSequence.IndexOf(1)] = Cards.Card.GetRankNumericValue(Cards.Card.PossibleRanksHighCardFirst.First());
                            }

                            if (playerCards.All(x => previousSequence.Contains(x.RankNumericValue)))
                            {
                                return(true);
                            }
                        }
                    }
                    else if ((previousSequence.Count + currentSequence.Count) == 3)
                    {
                        if (HandAnalyzerHelpers.IsStraight(currentSequence) &&
                            HandAnalyzerHelpers.IsStraight(previousSequence))
                        {
                            if (previousSequence.Contains(1))
                            {
                                previousSequence[previousSequence.IndexOf(1)] = Cards.Card.GetRankNumericValue(Cards.Card.PossibleRanksHighCardFirst.First());
                            }

                            if (playerCards.All(p => currentSequence.Contains(p.RankNumericValue) || previousSequence.Contains(p.RankNumericValue)))
                            {
                                return(true);
                            }
                        }
                    }
                }

                previousSequence = new List <int>(currentSequence);
                currentSequence.Clear();
                currentSequence.Add(rankList[i]);
            }

            return(false);
        }