示例#1
0
        public SheepCard PlayWeakestWin(IPlayer thisPlayer, ITrick trick)
        {
            var legalCards    = thisPlayer.Cards.Where(c => trick.IsLegalAddition(c, thisPlayer));
            var winnableCards = GameStateUtils.GetCardsThatCouldWin(trick, legalCards);

            return(winnableCards.OrderByDescending(c => CardUtil.GetRank(c)).First());
        }
示例#2
0
        public SheepCard PlayStrongestLoosingCard(IPlayer thisPlayer, ITrick trick)
        {
            var legalCards    = thisPlayer.Cards.Where(c => trick.IsLegalAddition(c, thisPlayer));
            var winnableCards = GameStateUtils.GetCardsThatCouldWin(trick, legalCards);

            return(legalCards.Except(winnableCards).OrderBy(c => CardUtil.GetRank(c)).First());
        }
示例#3
0
        public TrickWinner Winner()
        {
            var moves = OrderedMoves;

            if (!moves.Any())
            {
                return(null);
            }
            var firstSuite = CardUtil.GetSuit(moves.First().Value);
            var validCards = new List <KeyValuePair <IPlayer, SheepCard> >();

            foreach (var keyValuePair in moves)
            {
                var suite = CardUtil.GetSuit(keyValuePair.Value);
                if (suite == firstSuite || suite == Suit.TRUMP)
                {
                    validCards.Add(keyValuePair);
                }
            }
            return(new TrickWinner()
            {
                Player = validCards.OrderBy(kvp => CardUtil.GetRank(kvp.Value)).First().Key,
                Points = moves.Sum(c => CardUtil.GetPoints(c.Value))
            });
        }
示例#4
0
 public SheepCard GiveAwayLeastPower(IPlayer thisPlayer, ITrick trick)
 {
     return(thisPlayer.Cards
            .Where(c => trick.IsLegalAddition(c, thisPlayer))
            .OrderByDescending(c => CardUtil.GetRank(c))
            .First());
 }
示例#5
0
 private static SheepCard GetStrongestCard(IEnumerable <SheepCard> unrevealedCards, Suit startSuit)
 {
     return(unrevealedCards
            .OrderBy(c => CardUtil.GetSuit(c) == Suit.TRUMP ? 1 : 2)
            .ThenBy(c => CardUtil.GetSuit(c) == startSuit ? 1 : 2)
            .ThenBy(c => CardUtil.GetRank(c))
            .First());
 }
示例#6
0
        public static KeyValuePair <IPlayer, SheepCard> GetWinningPlay(ITrick trick)
        {
            var startSuit   = CardUtil.GetSuit(trick.CardsByPlayer.First().Value);
            var winningPlay = trick.CardsByPlayer
                              .OrderBy(cp => CardUtil.GetSuit(cp.Value) == Suit.TRUMP ? 1 : 2)
                              .ThenBy(cp => CardUtil.GetSuit(cp.Value) == startSuit ? 1 : 2)
                              .ThenBy(cp => CardUtil.GetRank(cp.Value))
                              .First();

            return(winningPlay);
        }
示例#7
0
        public List <SheepCard> RetireOneFailOrLowestRankCards()
        {
            var groups = _cards
                         .GroupBy(c => CardUtil.GetSuit(c))
                         .OrderBy(g => g.Key != Suit.TRUMP ? CardsPerSuit[g.Key] : int.MaxValue);
            var retVal = new List <SheepCard>();

            foreach (var group in groups)
            {
                retVal.AddRange(group.OrderByDescending(c => CardUtil.GetRank(c)));
            }
            return(retVal.Take(2).ToList());
        }
示例#8
0
        public SheepCard PlaySecondStrongestLoosingCard(IPlayer thisPlayer, ITrick trick)
        {
            var legalCards    = thisPlayer.Cards.Where(c => trick.IsLegalAddition(c, thisPlayer));
            var winnableCards = GameStateUtils.GetCardsThatCouldWin(trick, legalCards);
            var cards         = legalCards.Except(winnableCards).OrderBy(c => CardUtil.GetRank(c)).ToList();

            if (cards.Count == 1)
            {
                return(cards.Single());
            }
            else
            {
                return(cards[1]);
            }
        }
示例#9
0
 private SheepCard GetLeadMove(ITrick trick)
 {
     if (trick.IHand.Picker == this || IamPartner(trick))
     {
         if (Cards.Average(c => CardUtil.GetRank(c)) > 10)
         {
             return(Cards
                    .Where(c => trick.IsLegalAddition(c, this))
                    .OrderBy(c => CardUtil.GetSuit(c) == Suit.TRUMP ? 1 : 2)
                    .ThenByDescending(c => CardUtil.GetRank(c))
                    .FirstOrDefault());
         }
         else
         {
             return(Cards
                    .Where(c => trick.IsLegalAddition(c, this))
                    .OrderBy(c => CardUtil.GetSuit(c) == Suit.TRUMP ? 1 : 2)
                    .ThenBy(c => CardUtil.GetRank(c))
                    .FirstOrDefault());
         }
     }
     else
     {
         if (trick.IHand.IGame.PartnerMethodEnum == PartnerMethod.CalledAce && trick.IHand.PartnerCardEnum.HasValue)
         {
             var partnerCardSuit = CardUtil.GetSuit(trick.IHand.PartnerCardEnum.Value);
             return(Cards
                    .OrderBy(c => CardUtil.GetSuit(c) == partnerCardSuit ? 1 : 2)
                    .ThenBy(c => CardUtil.GetSuit(c) != Suit.TRUMP ? 1 : 2)
                    .ThenByDescending(c => CardUtil.GetRank(c))
                    .FirstOrDefault());
         }
         else
         {
             return(Cards
                    .OrderBy(c => CardUtil.GetSuit(c) != Suit.TRUMP ? 1 : 2)
                    .ThenByDescending(c => CardUtil.GetRank(c))
                    .FirstOrDefault());
         }
     }
 }
示例#10
0
        public static IEnumerable <SheepCard> GetCardsThatCouldWin(ITrick trick, IEnumerable <SheepCard> comparisonCards)
        {
            if (!trick.CardsByPlayer.Any())
            {
                return(comparisonCards);
            }
            var startSuit       = CardUtil.GetSuit(trick.CardsByPlayer.First().Value);
            var winningCard     = GameStateUtils.GetWinningPlay(trick).Value;
            var winningCardRank = CardUtil.GetRank(winningCard);

            if (CardUtil.GetSuit(winningCard) == Suit.TRUMP)
            {
                return(comparisonCards.Where(c => CardUtil.GetRank(c) < winningCardRank));
            }
            else
            {
                return(comparisonCards.Where(c =>
                                             CardUtil.GetSuit(c) == Suit.TRUMP ||
                                             CardUtil.GetSuit(c) == startSuit && CardUtil.GetRank(c) < winningCardRank
                                             ));
            }
        }
示例#11
0
        public override bool WillPick(IHand hand)
        {
            var highPointCards         = Cards.Count(c => CardUtil.GetPoints(c) >= 10);
            var avgRank                = Cards.Average(c => CardUtil.GetRank(c));
            var playerQueueRankInTrick = QueueRankInHand(hand);
            var middleQueueRankInTrick = (hand.PlayerCount + 1) / 2;

            if (hand.PlayerCount == 5)
            {
                var willPick = avgRank <= 6 ||
                               avgRank <= 13 && highPointCards > 2 ||
                               avgRank <= 13 && playerQueueRankInTrick > middleQueueRankInTrick;
                return(willPick);
            }
            else
            {
                var willPick = avgRank <= 8 ||
                               avgRank <= 16 && highPointCards > 2 ||
                               avgRank <= 16 && playerQueueRankInTrick > middleQueueRankInTrick;
                return(willPick);
            }
        }
示例#12
0
 protected override List <SheepCard> DropCardsForPickInternal(IHand hand)
 {
     return(Cards.OrderByDescending(c => CardUtil.GetRank(c)).Take(2).ToList());
 }