private Card Play_OnSuit() { if (BookCards.All(x => x.Suit != "s")) // Book has not been trumped { if (!PartnerWinning) { if (BookCards.Count == 3 || (BookCards.Count == 2 && Logic.LeftBid <= 0)) { // All other players have played a card, opposing team is winning. var overCards = Logic.HandCards.Where(x => x.Suit == LeadCard.Suit && x.Rank > HighCard.Rank).ToList(); // Play lowest card over the high card if possible. if (overCards.Any()) { return(overCards.OrderBy(x => x.Rank).First()); } } var s1 = PlayHighestKnown(LeadCard.Suit); if (s1 != null && s1.Rank > HighCard.Rank) { if (PartnerCard == null || HighCard.Rank != PartnerCard.Rank) { return(s1); } } } if (BookCards.Count == 2) // Partner is winning and opposing team will play after you. { // Check if your partner has the highest possible card (excluding your hand cards). var s2 = PlayHighestKnown(LeadCard.Suit); if (s2 != null && PartnerCard != null && s2.Rank > PartnerCard.Rank) { var partnerIsHighestKnown = true; for (var i = PartnerCard.Rank; i < s2.Rank; i++) { var higherCard = new Card(i, LeadCard.Suit); if (!Logic.PlayedCards.Contains(higherCard) && !Logic.HandCards.Contains(higherCard)) { partnerIsHighestKnown = false; } } // If a higher card exists than your partners play, but is not accounted for, play highest known. if (!partnerIsHighestKnown) { return(s2); } } } } // Can't play higher, play lowest. return(Logic.HandCards.Where(x => x.Suit == LeadCard.Suit).OrderBy(x => x.Rank).First()); }
private Card Play_PlayerNil_OnSuit() { if (BookCards.Any(x => x.Suit == "s")) { // Book has been trumped, play highest card in suit. return(Logic.HandCards .Where(x => x.Suit == LeadCard.Suit) .OrderByDescending(x => x.Rank) .First()); } var highestOnSuit = BookCards.Where(x => x.Suit == LeadCard.Suit).OrderByDescending(x => x.Rank).First(); if (Logic.HandCards.Any(x => x.Suit == LeadCard.Suit && x.Rank < highestOnSuit.Rank)) { // Play highest card under the highest in the book. return(Logic.HandCards .Where(x => x.Suit == LeadCard.Suit) .Where(x => x.Rank < highestOnSuit.Rank) .OrderByDescending(x => x.Rank) .First()); } return(Logic.HandCards .Where(x => x.Suit == LeadCard.Suit) .OrderBy(x => x.Rank) .First()); }
private Card Play_OffSuit() { if (PartnerWinning && (BookCards.Count == 3 || (BookCards.Count == 2 && Logic.LeftBid <= 0))) { // Partner is winning and no threats remain, sluff. var nonTrump = Logic.HandCards.Where(x => x.Suit != "s").OrderBy(x => x.Rank).ToList(); if (nonTrump.Any()) { return(nonTrump.First()); } // You're spade tight, return the lowest one. return(Logic.HandCards.OrderBy(x => x.Rank).First()); } if (Logic.HandCards.Any(x => x.Suit == "s")) { if (BookCards.Any(x => x.Suit == "s")) { var highTrump = BookCards.Where(x => x.Suit == "s").OrderByDescending(x => x.Rank).First(); if (PartnerCard != null && PartnerCard != highTrump) { var higherTrump = Logic.HandCards.Where(x => x.Suit == "s" && x.Rank > highTrump.Rank).ToList(); if (higherTrump.Any()) { return(higherTrump.OrderBy(x => x.Rank).First()); } } } return(Logic.HandCards .Where(x => x.Suit == "s") .OrderBy(x => x.Rank) .First()); } // Play lowest card. return(Logic.HandCards.OrderBy(x => x.Rank).First()); }
private Card Play_PlayerNil_OffSuit() { // Check non-trump suits for potential problems. (e.g. 2 cards left, 1 is the ace, etc.) var groups = Logic.HandCards.GroupBy(x => x.Suit, (key, cards) => new { suit = key, cards = cards.ToList() }); var problems = groups.Where(x => x.suit != "s" && x.cards.Count() <= 2 && x.cards.Any(y => y.Rank > 10)) .ToList(); if (problems.Any()) { var problem = problems.OrderBy(x => x.cards.Count()).First(); return(problem.cards.OrderByDescending(x => x.Rank).First()); } if (BookCards.Any(x => x.Suit == "s")) { // Book has been trumped, dump the highest spade under var trumpCard = BookCards.Where(x => x.Suit == "s").OrderByDescending(x => x.Rank).First(); var t1 = Logic.HandCards.Where(x => x.Suit == "s" && x.Rank < trumpCard.Rank).ToList(); if (t1.Any()) { return(t1.OrderByDescending(x => x.Rank).First()); } } if (Logic.HandCards.All(x => x.Suit == "s")) { //Play the lowest spade in your hand. return(Logic.HandCards.OrderBy(x => x.Rank).First()); } return(Logic.HandCards.Where(x => x.Suit != "s").OrderByDescending(x => x.Rank).First()); }
private Card Play_PartnerNil_OnSuit() { // If partner has not yet played, play high. if (PartnerCard == null) { return(Logic.HandCards .Where(x => x.Suit == LeadCard.Suit) .OrderByDescending(x => x.Rank) .First()); } // Partner has played, check if they are on suit. if (PartnerCard.Suit != LeadCard.Suit && PartnerCard.Suit != "s") { // Partner is off suit and safe, take book if sure. if (BookCards.All(x => x.Suit != "s")) { var s0 = PlayHighestKnown(LeadCard.Suit); if (s0 != null && HighCard.Rank < s0.Rank) { return(s0); } } } if (Logic.HandCards.Any(x => x.Suit == LeadCard.Suit && x.Rank > PartnerCard.Rank)) { return(Logic.HandCards .Where(x => x.Suit == LeadCard.Suit && x.Rank > PartnerCard.Rank) .OrderBy(x => x.Rank) .First()); } return(Logic.HandCards .Where(x => x.Suit == LeadCard.Suit) .OrderBy(x => x.Rank).First()); }