private int GetNutHighCard(List <int> orderedRanks)
        {
            int firstRank = orderedRanks.Max() + 2;

            while (firstRank > orderedRanks.Min() - 2)
            {
                firstRank = BoardTextureAnalyzerHelpers.GetHighestUniqueRankNumberForList(orderedRanks, firstRank);
                var secondRank = BoardTextureAnalyzerHelpers.GetHighestUniqueRankNumberForList(orderedRanks, firstRank - 1);
                if (secondRank <= 0)
                {
                    break;
                }

                var connectedList = new List <int>(orderedRanks);
                connectedList.Add(secondRank);
                connectedList = HandAnalyzerHelpers.GetConnectedCards(firstRank, connectedList);

                if (connectedList.Count > 4)
                {
                    var hand = connectedList.OrderByDescending(x => x).Take(5);
                    if (HandAnalyzerHelpers.IsStraight(hand))
                    {
                        return(hand.Max());
                    }
                }
                firstRank--;
            }

            return(-1);
        }
        public bool Analyze(BoardCards boardCards, BoardTextureItem boardTexture)
        {
            var boardTextureItem = boardTexture as StraightBoardTextureItem;

            if (boardTextureItem == null || !CardHelper.IsStreetAvailable(boardCards.ToString(), boardTextureItem.TargetStreet))
            {
                return(false);
            }

            int numberOfOpenEndedStraights = 0;

            var orderedRanks = BoardTextureAnalyzerHelpers.GetOrderedBoardNumericRanks(boardCards, boardTextureItem);

            if (orderedRanks.Count < 2)
            {
                return(false);
            }

            int firstRank = orderedRanks.Max() + 2;

            while (firstRank > orderedRanks.Min() - 2)
            {
                firstRank = BoardTextureAnalyzerHelpers.GetHighestUniqueRankNumberForList(orderedRanks, firstRank);
                var secondRank = BoardTextureAnalyzerHelpers.GetHighestUniqueRankNumberForList(orderedRanks, firstRank - 1);
                if (secondRank <= 0)
                {
                    break;
                }

                var connectedList = new List <int>(orderedRanks);
                connectedList.Add(secondRank);
                connectedList = HandAnalyzerHelpers.GetConnectedCards(firstRank, connectedList);

                if (connectedList.Count > 4)
                {
                    numberOfOpenEndedStraights += HandAnalyzerHelpers.IsStraight(connectedList.OrderByDescending(x => x).Take(5)) ? 1 : 0;
                }
                firstRank--;
            }

            return(BoardTextureAnalyzerHelpers.CheckEquality(boardTextureItem.SelectedSign.Key, numberOfOpenEndedStraights, boardTextureItem.SelectedNumber));
        }
        public bool Analyze(BoardCards boardCards, BoardTextureItem boardTexture)
        {
            var boardTextureItem = boardTexture as StraightBoardTextureItem;

            if (boardTextureItem == null || !CardHelper.IsStreetAvailable(boardCards.ToString(), boardTextureItem.TargetStreet))
            {
                return(false);
            }

            int numberOfOpenEndedStraights = 0;

            var orderedRanks = BoardTextureAnalyzerHelpers.GetOrderedBoardNumericRanks(boardCards, boardTextureItem);

            if (orderedRanks.Count < 2)
            {
                return(false);
            }

            int nutRank = GetNutHighCard(orderedRanks);

            if (nutRank <= 0)
            {
                return(false);
            }

            int firstRank  = orderedRanks.Max() + 3;
            int secondRank = firstRank - 1;

            while (firstRank > nutRank)
            {
                firstRank  = BoardTextureAnalyzerHelpers.GetHighestUniqueRankNumberForList(orderedRanks, firstRank);
                secondRank = BoardTextureAnalyzerHelpers.GetHighestUniqueRankNumberForList(orderedRanks, secondRank);

                if (firstRank == secondRank)
                {
                    secondRank = BoardTextureAnalyzerHelpers.GetHighestUniqueRankNumberForList(orderedRanks, secondRank - 1);
                }

                if (secondRank <= 0 || secondRank < orderedRanks.Min() - 3)
                {
                    firstRank--;
                    secondRank = firstRank;
                    continue;
                }

                var tempList = new List <int>(orderedRanks);
                tempList.Add(firstRank);
                tempList.Add(secondRank);
                tempList = tempList.Where(x => x <= firstRank).ToList();
                if (tempList.Count > 3)
                {
                    var hand      = tempList.OrderByDescending(x => x).Take(4);
                    var isGutShot = hand.Max() - hand.Min() == 4;
                    if (isGutShot)
                    {
                        numberOfOpenEndedStraights++;
                    }
                }
                secondRank--;
            }

            return(BoardTextureAnalyzerHelpers.CheckEquality(boardTextureItem.SelectedSign.Key, numberOfOpenEndedStraights, boardTextureItem.SelectedNumber));
        }
        public bool Analyze(BoardCards boardCards, BoardTextureItem boardTexture)
        {
            var boardTextureItem = boardTexture as StraightBoardTextureItem;

            if (boardTextureItem == null || !CardHelper.IsStreetAvailable(boardCards.ToString(), boardTextureItem.TargetStreet))
            {
                return(false);
            }

            int numberOfOpenEndedStraights = 0;

            var orderedRanks = BoardTextureAnalyzerHelpers.GetOrderedBoardNumericRanks(boardCards, boardTextureItem);

            if (orderedRanks.Count < 2)
            {
                return(false);
            }

            int  firstRank     = BoardTextureAnalyzerHelpers.GetHighestUniqueRankNumberForList(orderedRanks, orderedRanks.Max() + 2);
            int  initFirstRank = firstRank;
            int  nutRank       = 0;
            bool isNutFound    = false;

            while (firstRank > orderedRanks.Min() - 2)
            {
                firstRank = BoardTextureAnalyzerHelpers.GetHighestUniqueRankNumberForList(orderedRanks, firstRank);
                if (isNutFound && firstRank <= nutRank)
                {
                    break;
                }

                var secondRank = BoardTextureAnalyzerHelpers.GetHighestUniqueRankNumberForList(orderedRanks, firstRank - 1);
                if (secondRank <= 0)
                {
                    break;
                }

                var connectedList = new List <int>(orderedRanks);
                connectedList.Add(secondRank);
                connectedList = HandAnalyzerHelpers.GetConnectedCards(firstRank, connectedList);

                if (connectedList.Count > (isNutFound ? 3 : 4))
                {
                    var  hand       = connectedList.OrderByDescending(x => x).Take(isNutFound ? 4 : 5);
                    bool isStraight = HandAnalyzerHelpers.IsStraight(hand);
                    if (isStraight)
                    {
                        if (!isNutFound)
                        {
                            isNutFound = true;
                            firstRank  = initFirstRank;
                            nutRank    = hand.Max();
                            continue;
                        }
                        else
                        {
                            numberOfOpenEndedStraights++;
                        }
                    }
                }
                firstRank--;
            }

            return(BoardTextureAnalyzerHelpers.CheckEquality(boardTextureItem.SelectedSign.Key, numberOfOpenEndedStraights, boardTextureItem.SelectedNumber));
        }