private IList <PlayAction> GetValidPlayActions() { if (StickResult != null) { return(new List <PlayAction>()); } var allHandPlayActionList = PlayerHandDictionary[CurrentPlayer.PlayerId].Cards .Select(c => new PlayAction { PlayerInfo = CurrentPlayer, Card = c }) .ToList(); if (!StickSuit.HasValue) { //Case nothing played yet return(allHandPlayActionList); } var cardComparer = GetCardComparer(); var highestPlayedCard = PlayActionList .OrderByDescending(a => a.Card, cardComparer) .Select(a => a.Card) .First(); var canUnderTrump = PlayType.IsTrump() && allHandPlayActionList .All(a => a.Card.CardSuit == PlayType.GetTrumpSuit()) && allHandPlayActionList .All(a => a.Card.CardRank == CardRank.Jack || cardComparer.Compare(a.Card, highestPlayedCard) < 0); var hasSameSuitCardBesidesTrumpJack = allHandPlayActionList .Any(a => a.Card.CardSuit == StickSuit.Value && !(PlayType.IsTrump() && a.Card.CardSuit == PlayType.GetTrumpSuit() && a.Card.CardRank == CardRank.Jack)); var validPlayActions = allHandPlayActionList .Where(a => { var isTrump = PlayType.IsTrump() && a.Card.CardSuit == PlayType.GetTrumpSuit(); var isHigherThenPlayedCard = cardComparer.Compare(a.Card, highestPlayedCard) > 0; //disjoint condition list var isSameSuit = a.Card.CardSuit == StickSuit.Value; var isHigherNonSuitTrumpCard = !isSameSuit && isTrump && isHigherThenPlayedCard; var isLowerNonSuitUnderTrumpCard = !isSameSuit && isTrump && !isHigherThenPlayedCard && canUnderTrump; var isPlayableNonSuitNonTrumpCard = !isSameSuit && !hasSameSuitCardBesidesTrumpJack; var isValid = isSameSuit || isHigherNonSuitTrumpCard || isLowerNonSuitUnderTrumpCard || isPlayableNonSuitNonTrumpCard; return(isValid); }) .ToList(); return(validPlayActions); }
public static int GetRank(this Card card, PlayType playType) { if (playType.IsTrump() && card.CardSuit == playType.GetTrumpSuit()) { return(10 + _trumpRankList.IndexOf(card.CardRank)); } if (playType.IsTrump() || playType == PlayType.UpDown) { return(_upDownRankList.IndexOf(card.CardRank)); } return(_downUpRankList.IndexOf(card.CardRank)); }
public static int GetValue(this Card card, PlayType playType) { if (playType.IsTrump()) { var isTrumpCard = card.CardSuit == playType.GetTrumpSuit(); switch (card.CardRank) { case CardRank.Six: return(0); case CardRank.Seven: return(0); case CardRank.Eight: return(0); case CardRank.Nine: return(isTrumpCard ? 14 : 0); case CardRank.Ten: return(10); case CardRank.Jack: return(isTrumpCard ? 20 : 2); case CardRank.Queen: return(3); case CardRank.King: return(4); case CardRank.Ace: return(11); default: throw new NotImplementedException(); } } else { var isUpDown = playType == PlayType.UpDown; var isDownUp = playType == PlayType.DownUp; switch (card.CardRank) { case CardRank.Six: return(isDownUp ? 11 : 0); case CardRank.Seven: return(0); case CardRank.Eight: return(8); case CardRank.Nine: return(0); case CardRank.Ten: return(10); case CardRank.Jack: return(2); case CardRank.Queen: return(3); case CardRank.King: return(4); case CardRank.Ace: return(isUpDown ? 11 : 0); default: throw new NotImplementedException(); } } }