當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。