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