public List <SheepCard> RetireOneFailSuitsWithOneAceOrTen() { if (_acesAndTens.Count != 1) { return(null); } var pointSuit = _acesAndTensPerSuit.Single(g => g.Key != Suit.TRUMP).Key; var twoCardSuit = CardsPerSuit .Where(cps => cps.Value == 2) .Where(cps => cps.Key == pointSuit) .Select(cps => cps.Key) .FirstOrDefault(); var buryCards = _cards.Where(c => CardUtil.GetSuit(c) == twoCardSuit).ToList(); if (buryCards.Count != 2) { return(null); } if (!buryCards.Contains(_acesAndTens.Single())) { return(null); } return(buryCards); }
public List <SheepCard> RetireTwoFailSuitsWithOneAceOrTen() { if (_acesAndTens.Count != 1) { return(null); } var pointSuit = _acesAndTensPerSuit.Single(g => g.Key != Suit.TRUMP).Key; var oneCardSuits = CardsPerSuit .Where(cps => cps.Value == 1) .OrderBy(cps => cps.Key == pointSuit ? 1 : 2) .Select(cps => cps.Key) .Take(2) .ToList(); var buryCards = _cards.Where(c => oneCardSuits.Contains(CardUtil.GetSuit(c))).ToList(); if (buryCards.Count != 2) { return(null); } if (!buryCards.Contains(_acesAndTens.Single())) { return(null); } return(buryCards); }
private SheepCard GetLeadMove(ITrick trick) { if (trick.IHand.Picker == this || IamPartner(trick)) { return(Cards .Where(c => trick.IsLegalAddition(c, this)) .OrderBy(c => CardUtil.GetSuit(c) == Suit.TRUMP ? 1 : 2) .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) .FirstOrDefault()); } else { return(Cards .OrderBy(c => CardUtil.GetSuit(c) != Suit.TRUMP ? 1 : 2) .FirstOrDefault()); } } }
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)) }); }
public void CardUtil_GetSuit() { Assert.AreEqual(Suit.TRUMP, CardUtil.GetSuit(SheepCard.QUEEN_CLUBS)); Assert.AreEqual(Suit.TRUMP, CardUtil.GetSuit(SheepCard.QUEEN_DIAMONDS)); Assert.AreEqual(Suit.SPADES, CardUtil.GetSuit(SheepCard.ACE_SPADES)); Assert.AreEqual(Suit.CLUBS, CardUtil.GetSuit(SheepCard.N7_CLUBS)); Assert.AreEqual(Suit.TRUMP, CardUtil.GetSuit(SheepCard.N7_DIAMONDS)); }
public override bool GoItAlone(IHand hand) { var trumpCount = Cards.Count(c => CardUtil.GetSuit(c) == Suit.TRUMP); var queenJackCount = Cards.Count(c => new[] { CardType.JACK, CardType.QUEEN }.Contains(CardUtil.GetFace(c))); var queenCount = Cards.Count(c => CardUtil.GetFace(c) == CardType.QUEEN); return(trumpCount >= 5 && queenJackCount >= 3 && queenCount >= 2); }
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()); }
protected override List <SheepCard> DropCardsForPickInternal(IHand hand) { return(Cards .OrderBy(c => CardUtil.GetSuit(c) != Suit.TRUMP ? 1 : 2) .ThenByDescending(c => CardUtil.GetPoints(c)) .Take(2) .ToList()); }
public override bool WillPick(IHand hand) { var playerQueueRankInTrick = QueueRankInHand(hand); var middleQueueRankInTrick = (hand.PlayerCount + 1) / 2; var trumpCount = this.Cards.Count(c => CardUtil.GetSuit(c) == Suit.TRUMP); var willPick = playerQueueRankInTrick > middleQueueRankInTrick && trumpCount >= 3 || playerQueueRankInTrick == middleQueueRankInTrick && trumpCount >= 4 || trumpCount >= 5; return(willPick); }
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); }
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()); }
public List <SheepCard> RetireTwoFailSuits() { var buryCards = _cards .Where(c => CardUtil.GetSuit(c) != Suit.TRUMP) .Where(c => CardsPerSuit[CardUtil.GetSuit(c)] == 1) .Take(2) .ToList(); if (buryCards.Count == 2) { return(buryCards); } return(null); }
public bool UnplayedCardsBeatMyCards(IPlayer thisPlayer, ITrick trick) { var playableCards = thisPlayer.Cards.Where(c => trick.IsLegalAddition(c, thisPlayer)); var unrevealedCards = GetUnrevealedCards(thisPlayer, trick); var startSuit = CardUtil.GetSuit(trick.CardsByPlayer.First().Value); var strongestUnrevealedCard = GetStrongestCard(unrevealedCards, startSuit); var strongestOfMyCards = GetStrongestCard(playableCards, startSuit); var strongestCard = GetStrongestCard(new List <SheepCard>() { strongestUnrevealedCard, strongestOfMyCards }, startSuit); return(strongestCard == strongestUnrevealedCard); }
public List <SheepCard> RetireOneFailSuit() { var buryCards = _cards .Where(c => CardUtil.GetSuit(c) != Suit.TRUMP) .Where(c => CardsPerSuit[CardUtil.GetSuit(c)] == 2) .GroupBy(c => CardUtil.GetSuit(c)) .ToList(); if (buryCards.Any()) { return(buryCards.First().ToList()); } return(null); }
private bool IsLegalStartingCardInCalledAceGame(SheepCard card, IPlayer player) { var suitOfPartnerCard = CardUtil.GetSuit(IHand.PartnerCardEnum.Value); if (player == IHand.Picker) { return(true); } //Partner cannot lead with card in partner suit unless partner card has already been played or card is the partner card. return(!IHand.PartnerCardEnum.HasValue || !player.Cards.Contains(IHand.PartnerCardEnum.Value) || card == IHand.PartnerCardEnum || CardUtil.GetSuit(card) != CardUtil.GetSuit(IHand.PartnerCardEnum.Value)); }
public BuriedCardSelector(IReadOnlyList <SheepCard> cards) { CardsPerSuit = cards .Where(c => CardUtil.GetSuit(c) != Suit.TRUMP) .GroupBy(c => CardUtil.GetSuit(c)) .ToDictionary(g => g.Key, g => g.Count()); _cards = cards; _acesAndTens = cards .Where(c => CardUtil.GetSuit(c) != Suit.TRUMP) .Where(c => new[] { CardType.ACE, CardType.N10 }.Contains(CardUtil.GetFace(c))) .ToList(); _acesAndTensPerSuit = _acesAndTens .GroupBy(c => CardUtil.GetSuit(c)) .Where(g => g.Key != Suit.TRUMP) .OrderBy(g => g.Count()) .ToList(); }
public void BuriedCardSelector_BuryCardsByEasiestToRetireLowestRank_RetireNothing() { var cards = new List <SheepCard>() { SheepCard.N9_SPADES, SheepCard.N8_SPADES, SheepCard.N7_SPADES, SheepCard.N7_CLUBS, SheepCard.KING_CLUBS, SheepCard.N8_CLUBS, SheepCard.KING_DIAMONDS, SheepCard.QUEEN_CLUBS }; var selector = new BuriedCardSelector(cards); var actual = selector.CardsToBury; Assert.IsTrue(actual.All(c => CardUtil.GetSuit(c) == Suit.SPADES) || actual.All(c => CardUtil.GetSuit(c) == Suit.CLUBS)); }
protected LegalCalledAces LegalCalledAceSuits(IHand hand) { var allPickersCards = Cards .Union(hand.Blinds) .Union(hand.Buried) .ToList(); var allAces = new List <SheepCard>() { SheepCard.ACE_CLUBS, SheepCard.ACE_HEARTS, SheepCard.ACE_SPADES }; var allTens = new List <SheepCard>() { SheepCard.N10_CLUBS, SheepCard.N10_HEARTS, SheepCard.N10_SPADES }; var pickerHasAllAces = allAces.All(c => allPickersCards.Contains(c)); var potentialPartnerCards = pickerHasAllAces ? allTens : allAces; var illegalSuits = potentialPartnerCards .Where(sc => allPickersCards.Contains(sc)) .Select(sc => CardUtil.GetSuit(sc)) .Union(new List <Suit>() { Suit.TRUMP }) .ToList(); var acceptableSuits = allPickersCards .Where(c => { var suit = CardUtil.GetSuit(c); return(!illegalSuits.Contains(suit)); }) .GroupBy(c => CardUtil.GetSuit(c)); return(new LegalCalledAces() { LegalSuits = acceptableSuits, CardType = pickerHasAllAces ? CardType.N10 : CardType.ACE }); }
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 )); } }
public void BuriedCardSelector_BuryCardsByEasiestToRetireLowestRank_RetireOneButNotOther() { var cards = new List <SheepCard>() { SheepCard.N7_SPADES, SheepCard.JACK_HEARTS, SheepCard.N8_DIAMONDS, SheepCard.N8_SPADES, SheepCard.KING_HEARTS, SheepCard.KING_DIAMONDS, SheepCard.N9_SPADES, SheepCard.QUEEN_CLUBS }; var selector = new BuriedCardSelector(cards); var expected = new List <SheepCard>() { SheepCard.KING_HEARTS, SheepCard.KING_CLUBS }; var actual = selector.CardsToBury; Assert.IsTrue(actual.Contains(SheepCard.KING_HEARTS)); Assert.IsTrue(actual.Any(c => CardUtil.GetSuit(c) == Suit.SPADES)); }
private static bool CardFollowsSuit(SheepCard card, IPlayer player, SheepCard firstCard) { return(CardUtil.GetSuit(card) == CardUtil.GetSuit(firstCard) || !player.Cards.Any(c => CardUtil.GetSuit(c) == CardUtil.GetSuit(firstCard))); }