Beispiel #1
0
        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());
        }
Beispiel #2
0
        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());
        }