Sort() private method

private Sort ( CardComparer comparer ) : void
comparer CardComparer
return void
コード例 #1
0
        private void FindSequentialForColor(CardsCollection cards)
        {
            CardComparer comparer = new CardComparer( );

            cards.Sort(comparer);               // we have cards sorted like A,K,Q,J,10,9,8,7

            CardsCollection foundCards = new CardsCollection();

            for (int i = 0; i < cards.Count - 1; i++)
            {
                if (IsConsequent(cards[i], cards[i + 1]))
                {
                    if (foundCards.IsEmpty)
                    {
                        foundCards.Add(cards[i]);
                    }

                    foundCards.Add(cards[i + 1]);
                }
                else
                {
                    if (!foundCards.IsEmpty)
                    {
                        AddSequentialCombination(foundCards);
                        foundCards = new CardsCollection();
                    }
                }
            }

            if (!foundCards.IsEmpty)
            {
                AddSequentialCombination(foundCards);
            }
        }
コード例 #2
0
        private void FindSequentialForColor( CardsCollection cards )
        {
            CardComparer comparer = new CardComparer( );
            cards.Sort( comparer ); // we have cards sorted like A,K,Q,J,10,9,8,7

            CardsCollection foundCards = new CardsCollection();

            for( int i = 0; i < cards.Count-1; i++ )
            {
                if( IsConsequent( cards[i], cards[i+1] ) )
                {
                    if( foundCards.IsEmpty )
                    {
                        foundCards.Add ( cards[i] );
                    }

                    foundCards.Add ( cards[i+1] );
                }
                else
                {
                    if( !foundCards.IsEmpty )
                    {

                        AddSequentialCombination( foundCards );
                        foundCards = new CardsCollection();
                    }
                }
            }

            if( !foundCards.IsEmpty )
            {
                AddSequentialCombination( foundCards );
            }
        }