当前位置: 首页>>代码示例>>C#>>正文


C# CardCollection.Insert方法代码示例

本文整理汇总了C#中CardCollection.Insert方法的典型用法代码示例。如果您正苦于以下问题:C# CardCollection.Insert方法的具体用法?C# CardCollection.Insert怎么用?C# CardCollection.Insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CardCollection的用法示例。


在下文中一共展示了CardCollection.Insert方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IsStraight

        public bool IsStraight(out CardCollection winningCards)
        {
            checkCardList();

            // Get a copy of the card list
            CardCollection cardList = new CardCollection(_cardList);

            winningCards = new CardCollection();

            // Sort the cards by value
            cardList.Sort();

            // if there is an ace in the deck, it got moved to the end by the sort
            // so we need to insert a new "ace" in the sorted deck (with a value of 1) in the beginning position
            foreach (Card card in cardList)
            {
                if (card.Value == (int)Rank.Ace)
                {
                    cardList.Insert(0, new Card(card.Rank, card.Suit));
                    break;
                }
            }

            int cardsInARow = 1;

            // Check each card and the next one
            for (int i = 0; i < cardList.Count; i++)
            {
                // Add the current card to the winning cards index, just in case it's part of a straight
                winningCards.Add(cardList[i]);

                // If this is the last card, check to see if it is part of a straight
                if (i == cardList.Count - 1)
                {
                    if (cardList[i].IsOneGreaterThan(cardList[i - 1]))
                    {
                        cardsInARow++;
                    }
                    else
                        winningCards.Clear();
                }
                else
                {
                    // If this card is the same as the next one, ignore it
                    if (cardList[i].Value == cardList[i + 1].Value)
                    {
                        // remove the card we just added
                        winningCards.Remove(cardList[i]);
                        continue;
                    }

                    // Check to see if this card is exactly one less than the next card
                    if (cardList[i].IsOneLessThan(cardList[i + 1]))
                    {
                        cardsInARow++;
                    }
                    else
                    {
                        // if we already have a straight (5 cards) stop checking for more straights
                        if (cardsInARow >= 5)
                            break;
                        else
                        {
                            cardsInARow = 1;
                            winningCards.Clear();
                        }
                    }
                }
            }

            // Trim off any excess cards that are not the highest straight, and return true
            // Example: if you have A 2 3 4 5 6, the ace will be cut off and 2 3 4 5 6 will be preserved
            if (winningCards.Count >= 5)
            {
                if (winningCards.Count > 5)
                    winningCards.RemoveRange(0, winningCards.Count - 5);

                return true;
            }

            else
            {
                winningCards = null;
                return false;
            }
        }
开发者ID:bberak,项目名称:PokerDotNet,代码行数:86,代码来源:HandEvaluator.cs


注:本文中的CardCollection.Insert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。