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


C# Card.GetValue方法代码示例

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


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

示例1: FindHighestValueCardFromSuit

        private Card FindHighestValueCardFromSuit(Card opponentCard, ICollection<Card> possibleCardsToPlay)
        {
            var cardToPlay = possibleCardsToPlay
                .Where(c => c.Suit == opponentCard.Suit && c.GetValue() > opponentCard.GetValue())
                .FirstOrDefault();

            return cardToPlay;
        }
开发者ID:StevenTsvetkov,项目名称:Telerik-Teamwork-DSA,代码行数:8,代码来源:HelionPlayer.cs

示例2: PlayTrumpCardAgainstCardFromSuit

        /// <summary>
        /// Find best trump card when do not have cards from the opponent card suit.
        /// </summary>
        /// <param name="context">The information about current turn.</param>
        /// <param name="possibleCardsToPlay">Cards that player can play.</param>
        /// <param name="opponentCard">Card that opponent have played.</param>
        /// <returns>Find the optimal trump card to be played.</returns>
        private Card PlayTrumpCardAgainstCardFromSuit(PlayerTurnContext context, ICollection<Card> possibleCardsToPlay, Card opponentCard)
        {
            var trumpCards = possibleCardsToPlay
                .OrderByDescending(c => c.GetValue())
                .ToList();

            int botskoPoints = BotskoPlayer.BotskoIsFirstPlayer ?
                context.FirstPlayerRoundPoints : context.SecondPlayerRoundPoints;
            var biggestTrumpInHand = trumpCards.FirstOrDefault();
            var smallestTrumpInHand = trumpCards.Last();

            // Check if can win with opponent card points and biggest trump card points,
            if (botskoPoints + biggestTrumpInHand.GetValue() + opponentCard.GetValue() >= 66)
            {
                return trumpCards.FirstOrDefault();
            }

            if (trumpCards.Count > 1)
            {
                if (this.playerAnnounce != null &&
                    this.playerAnnounce.Suit == biggestTrumpInHand.Suit)
                {
                    // If have bigger trump card than King and smaller than Queen
                    // play smaller trump card.
                    if (biggestTrumpInHand.Type != CardType.King &&
                        smallestTrumpInHand.Type != CardType.Queen)
                    {
                        return smallestTrumpInHand;
                    }

                    // If have bigger trump card than King but the smallest is Queen
                    // play bigger trump card.
                    if (biggestTrumpInHand.Type != CardType.King &&
                        smallestTrumpInHand.Type == CardType.Queen)
                    {
                        return biggestTrumpInHand;
                    }

                    // If have bigger trump card than Kign but have 40 too
                    // play bigger trump card.
                    if (biggestTrumpInHand.Type == CardType.King)
                    {
                        return smallestTrumpInHand;
                    }
                }

                // Check if have more than 1 trump cards and the biggest in the game is in my hand.
                // Then play the smallest trump card.
                if (this.FirstTurnLogic.IsBiggestCardInMyHand(biggestTrumpInHand))
                {
                    return smallestTrumpInHand;
                }
            }

            return trumpCards.Last();
        }
开发者ID:pawelangelow,项目名称:Botsko,代码行数:63,代码来源:BotskoPlayer.cs

示例3: IsBiggestCardInMyHand

        /// <summary>
        /// Check if the biggest card from given suit in the hand is the biggest not played.
        /// </summary>
        /// <param name="biggestCard">The biggest card from given suit in the hand.</param>
        /// <returns>Return true if biggestCard is the biggest one left in the game.
        ///          Return false if there is bigger one.</returns>
        public bool IsBiggestCardInMyHand(Card biggestCard)
        {
            int suit = (int)biggestCard.Suit;
            int biggestCardValue = biggestCard.GetValue();

            if (biggestCardValue == 11)
            {
                return true;
            }

            for (int type = 5; type >= 0; type--)
            {
                if (this.PlayedCards[suit, type] == false)
                {
                    int cardValue = this.GetCardValue(type);
                    if (biggestCardValue < cardValue)
                    {
                        return false;
                    }
                }
            }

            return true;
        }
开发者ID:pawelangelow,项目名称:Botsko,代码行数:30,代码来源:BotskoPlayerFirstTurnLogic.cs

示例4: HasWinningTrumpCard

        private Card HasWinningTrumpCard(PlayerTurnContext context, ICollection<Card> possibleCardsToPlay, Card opponentCard)
        {
            var trumpSuit = context.TrumpCard.Suit;
            var trumps = possibleCardsToPlay
                .Where(c => c.Suit == trumpSuit)
                .OrderByDescending(c => c.GetValue())
                .ToList();

            if (trumps.Count() == 0)
            {
                return null;
            }

            var biggestTrumpInHand = trumps.FirstOrDefault();
            int botskoPoints = BotskoPlayer.BotskoIsFirstPlayer ?
                    context.FirstPlayerRoundPoints : context.SecondPlayerRoundPoints;

            //// Case 1: we have trump and playing it will end the game
            if (biggestTrumpInHand.GetValue() + botskoPoints + opponentCard.GetValue() >= 66)
            {
                return biggestTrumpInHand;
            }

            //// Case 2: we have 2 trumps and playing them will end the game
            if (trumps.Count() >= 2)
            {
                var trumpsSum = trumps[0].GetValue() + trumps[1].GetValue();
                if (trumpsSum + botskoPoints + opponentCard.GetValue() >= 66)
                {
                    return biggestTrumpInHand;
                }
            }

            //// Case 3: we have 40 and something else, playing something else to call 40 on next round
            if (this.playerAnnounce != null &&
                this.playerAnnounce.Suit == trumpSuit &&
                trumps.Count >= 3)
            {
                return trumps
                    .Where(c => c.Type != CardType.King && c.Type != CardType.Queen)
                    .OrderBy(c => c.GetValue())
                    .First();
            }

            return null;
        }
开发者ID:pawelangelow,项目名称:Botsko,代码行数:46,代码来源:BotskoPlayer.cs

示例5: PlayCardFromSameSuit

        /// <summary>
        /// Choose card when rules apply and have card/s from the same suit
        /// like the card that opponent have played.
        /// </summary>
        /// <param name="possibleCardsToPlay">Cards that player can play.</param>
        /// <param name="opponentCard">Card that opponent have played.</param>
        /// <returns>Returns the optimal card to be played.</returns>
        private Card PlayCardFromSameSuit(ICollection<Card> possibleCardsToPlay, Card opponentCard)
        {
            var opponentCardValue = opponentCard.GetValue();

            var biggerCardsThanOpponent = possibleCardsToPlay
                .Where(c => c.GetValue() > opponentCardValue)
                .OrderByDescending(c => c.GetValue())
                .ToList();
            var biggerCardsCount = biggerCardsThanOpponent.Count;

            // Check if haven't got bigger card/s than opponent and return the smallest one.
            if (biggerCardsCount == 0)
            {
                return this.FindSmallestCardFromGivenSuit(possibleCardsToPlay, opponentCard.Suit);
            }

            // If have only one bigger card returns it.
            // This check can be remove but I let it here for sure.
            if (biggerCardsCount == 1)
            {
                return biggerCardsThanOpponent.First();
            }

            if (biggerCardsCount > 1)
            {
                // If have more than 1 bigger cards but the opponent have only one card
                // from this suit, play the biggest one.
                if (this.CardsFromGivenSuit(opponentCard.Suit) - this.MyCardsFromGivenSuit(opponentCard.Suit) == 1)
                {
                    return biggerCardsThanOpponent.First();
                }

                // If have more than 1 bigger cards and the opponent should have more than
                // one card from this suit play the smallest bigger.
                if (biggerCardsCount == 2)
                {
                    return biggerCardsThanOpponent.Last();
                }

                return biggerCardsThanOpponent.First();
            }

            // Should never goes here.
            return possibleCardsToPlay.First();
        }
开发者ID:pawelangelow,项目名称:Botsko,代码行数:52,代码来源:BotskoPlayer.cs

示例6: HasBiggerCardInSameSuit

        private Card HasBiggerCardInSameSuit(ICollection<Card> possibleCardsToPlay, Card opponentCard)
        {
            var biggerCards = possibleCardsToPlay
                .Where(c => c.Suit == opponentCard.Suit &&
                            c.GetValue() > opponentCard.GetValue())
                .OrderByDescending(c => c.GetValue())
                .ToList();

            if (biggerCards != null)
            {
                return biggerCards.FirstOrDefault();
            }

            return null;
        }
开发者ID:pawelangelow,项目名称:Botsko,代码行数:15,代码来源:BotskoPlayer.cs

示例7: CardToSave

        private Card CardToSave(Card opponentCard, PlayerTurnContext context, ICollection<Card> possibleCardsToPlay)
        {
            Card cardToPlay = possibleCardsToPlay
                    .Where(c => c.Suit == opponentCard.Suit && c.GetValue() > opponentCard.GetValue())
                    .OrderByDescending(c => c.GetValue())
                    .FirstOrDefault();

            if (opponentCard.Suit == context.TrumpCard.Suit)
            {
                return cardToPlay;
            }
            else
            {
                if (cardToPlay == null)
                {
                    cardToPlay = possibleCardsToPlay
                        .Where(c => c.Suit == context.TrumpCard.Suit)
                        .OrderByDescending(c => c.GetValue()) //Maybe check for 40
                        .FirstOrDefault();
                }
            }

            return cardToPlay; // Plays he highest card
        }
开发者ID:pawelangelow,项目名称:Botsko,代码行数:24,代码来源:BotskoPlayer.cs

示例8: CardToGetTheLastOfDeck

        private Card CardToGetTheLastOfDeck(Card opponentCard, PlayerTurnContext context, ICollection<Card> possibleCardsToPlay)
        {
            Card cardToReturn = null;

            if (opponentCard.GetValue() <= 4)
            {
                cardToReturn = possibleCardsToPlay
                    .OrderBy(c => c.GetValue())
                    .FirstOrDefault();
            }
            else
            {
                var countOf40Cards = possibleCardsToPlay
                    .Where(c => c.Suit == context.TrumpCard.Suit &&
                    (c.Type == CardType.King || c.Type == CardType.Queen))
                    .Count();

                if (countOf40Cards == 1 &&
                    (context.TrumpCard.Type == CardType.King || context.TrumpCard.Type == CardType.Queen))
                {
                    cardToReturn = possibleCardsToPlay
                    .OrderBy(c => c.GetValue())
                    .FirstOrDefault(); // Maybe get his card in other cases
                }
            }

            return cardToReturn;
        }
开发者ID:pawelangelow,项目名称:Botsko,代码行数:28,代码来源:BotskoPlayer.cs

示例9: CardToBeatHis

        private Card CardToBeatHis(Card opponentCard, PlayerTurnContext context, ICollection<Card> possibleCardsToPlay)
        {
            if (opponentCard.Suit == context.TrumpCard.Suit)
            {
                return null; // There is no point
            }

            var myCard = possibleCardsToPlay
                .Where(c =>
                c.GetValue() > opponentCard.GetValue() &&
                c.Suit == opponentCard.Suit)
                .FirstOrDefault();

            if (myCard != null)
            {
                return myCard; // We have ace to beat his 10
            }

            var trumpCards = possibleCardsToPlay
                .Where(c => c.Suit == context.TrumpCard.Suit)
                .OrderBy(c => c.GetValue())
                .ToList();
            var trumpCard = trumpCards
                .FirstOrDefault();

            if (trumpCard != null) // TODO: Optimize it
            {
                // In case we have 9 and is good to change
                if (trumpCard.Type == CardType.Nine &&
                    this.IsGoodToChange(context) &&
                    (trumpCards.Last().Type != CardType.Queen && trumpCards.Last().Type != CardType.King))
                {
                    return trumpCards.Last();
                }

                if (this.FirstTurnLogic.CheckForPossible20or40(trumpCard))
                {
                    return trumpCard; // Booo, get this damage!
                }
            }

            return null;
        }
开发者ID:pawelangelow,项目名称:Botsko,代码行数:43,代码来源:BotskoPlayer.cs

示例10: GetHigherCard

 protected Card GetHigherCard(Card firstPlayedCard)
 {
     return this.possibleCardsToPlay.OrderByDescending(c => c.GetValue())
         .FirstOrDefault(c => c.Suit == firstPlayedCard.Suit && c.GetValue() > firstPlayedCard.GetValue());
 }
开发者ID:NinjAScode,项目名称:Teamwork-SixtySix,代码行数:5,代码来源:BaseChooseCardStrategy.cs


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