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


C# CardCollection.Sort方法代码示例

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


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

示例1: Decide_WanderingMinstrel

		protected override ChoiceResult Decide_WanderingMinstrel(Choice choice)
		{
			// Just sort everything best-to-worst
			CardCollection cards = new CardCollection(choice.Cards);
			cards.Sort(new DominionBase.Cards.Sorting.ByCost(DominionBase.Cards.Sorting.SortDirection.Descending));
			return new ChoiceResult(cards);
		}
开发者ID:micahpaul,项目名称:dominion_net_multi,代码行数:7,代码来源:Standard.cs

示例2: AttackedBy

		/// <summary>
		/// Fires off the Attack event, so any listeners can pick it up.
		/// </summary>
		/// <param name="player">The attacking player</param>
		/// <param name="attackingCard">The card that triggered the Attack event</param>
		/// <returns>"true" if the Attack can proceed (wasn't blocked).  "false" if the Attack was blocked.</returns>
		/// <summary>
		public Boolean AttackedBy(Player attacker, Card attackingCard)
		{
			if (Attacked != null)
			{
				AttackedEventArgs aea = null;
				Boolean cancelled = false;
				do
				{
					aea = new AttackedEventArgs(attacker, attackingCard);
					aea.Cancelled |= cancelled;
					Attacked(this, aea);

					CardCollection cards = new CardCollection(aea.Revealable.Values.Select(s => s.Card));
					if (cards.Count > 0)
					{
						cards.Sort();
						Choice choice = new Choice("Reveal a card?", null, attackingCard, cards, this, true, aea);
						ChoiceResult result = this.MakeChoice(choice);

						if (result.Cards.Count > 0)
							aea.Revealable[result.Cards[0].CardType].Method(this, ref aea);
						else
							break;
					}

					cancelled |= aea.Cancelled;

				} while (Attacked != null && aea.HandledBy.Count > 0);

				if (aea != null)
					cancelled |= aea.Cancelled;

				return !cancelled;
			}
			return true;
		}
开发者ID:micahpaul,项目名称:dominion_net_multi,代码行数:43,代码来源:Player.cs

示例3: 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

示例4: IsFlush

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

            CardCollection cardList = new CardCollection(_cardList);

            CardCollection clubs = new CardCollection();
            CardCollection diamonds = new CardCollection();
            CardCollection hearts = new CardCollection();
            CardCollection spades = new CardCollection();

            foreach (Card card in cardList)
            {
                switch (card.Suit)
                {
                    case Suit.Clubs:
                        clubs.Add(card);
                        break;
                    case Suit.Diamonds:
                        diamonds.Add(card);
                        break;
                    case Suit.Hearts:
                        hearts.Add(card);
                        break;
                    case Suit.Spades:
                        spades.Add(card);
                        break;
                    default:
                        break;
                }
            }

            if (clubs.Count >= 5)
            {
                winningCards = clubs;
                winningCards.Sort();
                return true;
            }

            if (diamonds.Count >= 5)
            {
                winningCards = diamonds;
                winningCards.Sort();
                return true;
            }

            if (hearts.Count >= 5)
            {
                winningCards = hearts;
                winningCards.Sort();
                return true;
            }

            if (spades.Count >= 5)
            {
                winningCards = spades;
                winningCards.Sort();
                return true;
            }

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

示例5: CheckHighestPairConfiguration

        public bool CheckHighestPairConfiguration(out Hand hand)
        {
            checkCardList();

            // make a copy
            //List<Card> cardList = new List<Card>(_cardList);
            CardCollection cardList = new CardCollection(_cardList);
            cardList.Sort();

            // this is a list of cards that match the key value
            Dictionary<int, CardCollection> matches = new Dictionary<int, CardCollection>();

            int numPairs = 0;
            int numThrees = 0;
            int numFours = 0;

            // Construct the dictionary
            foreach (Card card in cardList)
            {
                if (matches.ContainsKey(card.Value))
                    matches[card.Value].Add(card);
                else
                    matches.Add(card.Value, new CardCollection(new Card[] { card }));
                    //matches.Add(card.Value, new List<Card>(new Card[] { card }));
            }

            // Determine the number of pairs, threes, and fours
            //foreach (List<Card> cardPairs in matches.Values)
            foreach (CardCollection cardPairs in matches.Values)
            {
                if (cardPairs.Count == 2)
                    numPairs++;

                if (cardPairs.Count == 3)
                    numThrees++;

                if (cardPairs.Count == 4)
                    numFours++;
            }

            //List<Card> resultCards = new List<Card>();
            CardCollection resultCards = new CardCollection();

            // Okay, here comes the real logic
            // One Pair and One Pair Only
            if (numPairs == 1 && numThrees == 0 && numFours == 0)
            {
                // Continue with the assumption that we'll only find one pair
                foreach (int cardValue in matches.Keys)
                {
                    if (matches[cardValue].Count == 2) // this is our pair
                    {
                        resultCards.AddRange(matches[cardValue]);
                        break;
                    }
                }

                // Also add the next highest card
                for (int highCard = cardList.Count - 1; highCard >= 0; highCard--)
                {
                    if (!resultCards.Contains(cardList[highCard]))
                    {
                        // Add the next highest card from the sorted list and break
                        resultCards.Add(cardList[highCard]);
                        break;
                    }
                }

                // Construct the Best Hand for one pair and return true
                //hand = new BestHand(resultCards, HandType.OnePair);
                hand = new Hand(resultCards, Combination.OnePair);
                return true;
            }

            // Two Pair and two pair only
            else if (numPairs >= 2 && numThrees == 0 && numFours == 0)
            {
                int numPairsFound = 0;

                // Continue with the assumption that we'll only find two pairs
                foreach (int cardValue in new Stack<int>(matches.Keys))
                {
                    if (matches[cardValue].Count == 2) // this is our pair
                    {
                        resultCards.AddRange(matches[cardValue]);
                        numPairs++;
                        if (numPairsFound >= 2)
                            break;
                    }
                }

                // Also add the next highest card
                for (int highCard = cardList.Count - 1; highCard >= 0; highCard--)
                {
                    if (!resultCards.Contains(cardList[highCard]))
                    {
                        // Add the next highest card from the sorted list and break
                        resultCards.Add(cardList[highCard]);
                        break;
                    }
//.........这里部分代码省略.........
开发者ID:bberak,项目名称:PokerDotNet,代码行数:101,代码来源:HandEvaluator.cs

示例6: Play

		public override void Play(Player player)
		{
			base.Play(player);

			SupplyCollection availableSupplies = new SupplyCollection(player._Game.Table.Supplies.Where(kvp => kvp.Value.Randomizer != null && kvp.Value.Randomizer.GroupMembership != Group.None));
			CardCollection cards = new CardCollection();
			Choice choice = new Choice("Name a card", this, availableSupplies, player, false);
			foreach (Supply supply in player._Game.Table.Supplies.Values.Union(player._Game.Table.SpecialPiles.Values))
			{
				foreach (Type type in supply.CardTypes)
				{
					if (!choice.Supplies.Any(kvp => kvp.Value.CardType == type))
						cards.Add(Card.CreateInstance(type));
				}
			}
			cards.Sort();
			choice.AddCards(cards);

			ChoiceResult result = player.MakeChoice(choice);
			ICard namedCard = null;
			if (result.Supply != null)
				namedCard = result.Supply;
			else
				namedCard = result.Cards[0];

			player._Game.SendMessage(player, this, namedCard);
			if (player.CanDraw)
			{
				player.Draw(DeckLocation.Revealed);
				if (player.Revealed[namedCard.CardType].Count > 0)
				{
					player.AddCardsToHand(DeckLocation.Revealed);
				}
				else
				{
					player.AddCardsToDeck(player.RetrieveCardsFrom(DeckLocation.Revealed), DeckPosition.Top);
				}
			}
		}
开发者ID:micahpaul,项目名称:dominion_net_multi,代码行数:39,代码来源:DarkAges.cs

示例7: Play

		public override void Play(Player player)
		{
			base.Play(player);

			SupplyCollection availableSupplies = new SupplyCollection(player._Game.Table.Supplies.Where(kvp => kvp.Value.Randomizer != null && kvp.Value.Randomizer.GroupMembership != Group.None));
			CardCollection cards = new CardCollection();
			Choice choice = new Choice("Name a card", this, availableSupplies, player, false);
			foreach (Supply supply in player._Game.Table.Supplies.Values.Union(player._Game.Table.SpecialPiles.Values))
			{
				foreach (Type type in supply.CardTypes)
				{
					if (!choice.Supplies.Any(kvp => kvp.Value.CardType == type))
						cards.Add(Card.CreateInstance(type));
				}
			}
			cards.Sort();
			choice.AddCards(cards);

			ChoiceResult result = player.MakeChoice(choice);
			ICard namedCard = null;
			if (result.Supply != null)
				namedCard = result.Supply;
			else
				namedCard = result.Cards[0];

			player._Game.SendMessage(player, this, namedCard);
			CardCollection newCards = player.Draw(3, DeckLocation.Revealed);

			player.Trash(player.RetrieveCardsFrom(DeckLocation.Revealed, c => c.Name == namedCard.Name));

			Choice replaceChoice = new Choice("Choose order of cards to put back on your deck", this, player.Revealed, player, true, player.Revealed.Count, player.Revealed.Count);
			ChoiceResult replaceResult = player.MakeChoice(replaceChoice);
			player.RetrieveCardsFrom(DeckLocation.Revealed, replaceResult.Cards);
			player.AddCardsToDeck(replaceResult.Cards, DeckPosition.Top);
		}
开发者ID:micahpaul,项目名称:dominion_net_multi,代码行数:35,代码来源:Guilds.cs


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