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


C# CardCollection.RemoveRange方法代码示例

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


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

示例1: Decide_Vault

		protected override ChoiceResult Decide_Vault(Choice choice)
		{
			switch (choice.ChoiceType)
			{
				case ChoiceType.Options:
					// If there are at least 2 non-Action & non-Treasure cards, discard 2 of them
					IEnumerable<Card> vaultDiscardableCards = this.RealThis.Hand[c =>
						(c.Category & Category.Treasure) != Category.Treasure &&
						(c.Category & Category.Action) != Category.Action];

					if (vaultDiscardableCards.Count() >= 2)
						return new ChoiceResult(new List<String>() { choice.Options[0].Text });
					else
						return new ChoiceResult(new List<String>() { choice.Options[1].Text });

				case ChoiceType.Cards:
					if (choice.Text.StartsWith("Discard any number of cards"))
					{
						/// TODO -- this needs to be a bit smarter.  It shouldn't discard Action cards if we have 1+ Actions left
						/// It can also be improved to chain with Tactician (and so can Secret Chamber, for that matter)
						// Discard all non-Treasure cards
						return new ChoiceResult(new CardCollection(choice.Cards.Where(c => (c.Category & Category.Treasure) != Category.Treasure)));
					}
					else // "Choose 2 cards to discard"
					{
						CardCollection vDiscards = new CardCollection();
						vDiscards.AddRange(choice.Cards.Where(c => (c.Category & Category.Curse) == Category.Curse));
						if (vDiscards.Count < 2)
							vDiscards.AddRange(choice.Cards.Where(card => (card.Category & Category.Ruins) == Category.Ruins));
						if (vDiscards.Count < 2)
							vDiscards.AddRange(choice.Cards.Where(card => card.Category == Category.Victory));
						if (vDiscards.Count > 2)
							vDiscards.RemoveRange(2, vDiscards.Count - 2);
						else
							vDiscards.AddRange(this.FindBestCardsToDiscard(choice.Cards, 2 - vDiscards.Count));
						return new ChoiceResult(vDiscards);
					}

				default:
					return base.Decide_Vault(choice);
			}
		}
开发者ID:micahpaul,项目名称:dominion_net_multi,代码行数:42,代码来源:Standard.cs

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