public BeloteCard GetBest(Card32Family trumpFamily) { Card32Family?requested = RequestedFamily; if (requested != null) { BeloteCard bestCard = Deck.Cards[0]; if (Deck.Cards.Count > 1) { for (int i = 1; i < Deck.Cards.Count; ++i) { BeloteCard card = Deck.Cards[i]; bestCard = BeloteCard.GetBestCard(card, bestCard, trumpFamily); } } return(bestCard); } return(null); }
protected BeloteDeck ComputePlayableCards(Fold fold, Card32Family trumpFamily) { BeloteDeck playables = new BeloteDeck(); m_trumpCards.Clear(); m_trumpBetterCards.Clear(); if (!Hand.Empty) { // No cards in the fold, all cards are valid if (fold.RequestedFamily == null) { playables.CopyFrom(Hand); } else { BeloteCard bestCard = fold.GetBest(trumpFamily); Player bestPlayer = bestCard.Owner as Player; Card32Family requestedFamily = (Card32Family)fold.RequestedFamily; // We look for cards of the requested families foreach (BeloteCard card in Hand.Cards) { if (card.Family == requestedFamily) { playables.AddCard(card); } if (card.Family == trumpFamily) { m_trumpCards.Add(card); if (bestCard.Family == trumpFamily) { if (BeloteCard.GetBestCard(card, bestCard, trumpFamily) == card) { m_trumpBetterCards.Add(card); } } } } // Remove all trump cards that are too low if (!playables.Empty && trumpFamily == requestedFamily) { if (m_trumpBetterCards.Count > 0) { playables.Clear(); playables.AddCards(m_trumpBetterCards); } } // No card of the requested family if (playables.Empty) { // Best card is partner we can play what we want if (bestPlayer.Team == this.Team) { playables.CopyFrom(Hand); } else { if (bestCard.Family == trumpFamily) { if (m_trumpBetterCards.Count > 0) { playables.AddCards(m_trumpBetterCards); } else // TODO : Add "pisser" rules { playables.AddCards(m_trumpCards); } } else { playables.AddCards(m_trumpCards); } if (playables.Empty) { playables.CopyFrom(Hand); } } } } } return(playables); }