本文整理汇总了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;
}
示例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();
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例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
}
示例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;
}
示例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;
}
示例10: GetHigherCard
protected Card GetHigherCard(Card firstPlayedCard)
{
return this.possibleCardsToPlay.OrderByDescending(c => c.GetValue())
.FirstOrDefault(c => c.Suit == firstPlayedCard.Suit && c.GetValue() > firstPlayedCard.GetValue());
}