public static Card operator ++(Card card) { var newCard = new Card(card.Type, card.Suit); if (newCard.Suit != CardSuit.Spades) { newCard.Suit++; } else { if (newCard.Type == CardType.Ace) { newCard.Type = CardType.Seven; newCard.Suit = CardSuit.Clubs; } else { newCard.Type++; newCard.Suit = CardSuit.Clubs; } } return newCard; }
private bool IsCombinationOfQueenAndKingAvailable(Card playedCard) { if (!this.Contains(playedCard)) { return false; } if (playedCard.Type == CardType.King) { return this.Any(x => x.Type == CardType.Queen && x.Suit == playedCard.Suit); } if (playedCard.Type == CardType.Queen) { return this.Any(x => x.Type == CardType.King && x.Suit == playedCard.Suit); } return false; }
public bool IsBeloteAllowed(Contract contract, IList<Card> currentTrickCards, Card card) { var belote = false; if (contract.Type != ContractType.NoTrumps) { if (contract.Type == ContractType.AllTrumps) { if (currentTrickCards.Count == 0) { // The player is first belote = true; } else { if (currentTrickCards[0].Suit == card.Suit) { // Belote is allowed only when playing card from the same suit belote = true; } } } else { // Clubs, Diamonds, Hearts or Spades if (card.Suit == contract.Type.ToCardSuit()) { // Only if belote is from the trump suit belote = true; } } } if (belote) { return this.IsCombinationOfQueenAndKingAvailable(card); } return false; }
private void SetHandStrength(Card card, BidType bidType) { if (card.Type == CardType.Ten) { announceStrength[bidType] += 3; } if (card.Type == CardType.Queen || card.Type == CardType.King) { announceStrength[bidType] += 2; } if (card.Type == CardType.Ace) { announceStrength[bidType] += 5; } if (card.Type == CardType.Nine) { announceStrength[bidType] += 6; } if (card.Type == CardType.Jack) { announceStrength[bidType] += 10; } if (card.Type == CardType.Seven || card.Type == CardType.Eight) { announceStrength[bidType] += 1; } }
public void AddCard(Card card) { this.cards.Add(card); }
//only when playes last private bool WinningThinnerTactic(ref Card cardToPlay, IList<Card> allowedCards, IList<Card> currentTrickCards) { foreach (Card card in allowedCards.OrderBy(x => x.GetValue(this.currentContract))) { bool isWinner = true; foreach (Card item in this.onTheTable.Where(x => x.Suit == card.Suit)) { if (card.Type < item.Type) { isWinner = false; break; } } if (isWinner) { cardToPlay = card; return true; } } return false; }
private bool ThinnerTactic(ref Card cardToPlay, IList<Card> allowedCards, IList<Card> currentTrickCards) { cardToPlay = allowedCards.OrderBy(x => x.GetValue(this.currentContract)).ElementAt(0); return true; }
//used only when starts first private bool RussianTzarTactic(ref Card cardToPlay, IList<Card> allowedCards, IList<Card> currentTrickCards) { foreach (Card card in allowedCards.OrderByDescending(x => x.GetValue(this.currentContract))) { bool isWinner = true; foreach (Card item in this.remainedInGame.Where(x => x.Suit == card.Suit)) { if (card.Type < item.Type) { isWinner = false; break; } } if (isWinner) { cardToPlay = card; return true; } } return false; }
//used only when starts first private bool PartnerSeekingTactic(ref Card cardToPlay, IList<Card> allowedCards, IList<Card> currentTrickCards) { CardSuit? myPartnerSuit = null; if (this.partnerBids.Count(x => x != BidType.AllTrumps || x != BidType.NoTrumps || x != BidType.Double || x != BidType.ReDouble) > 0) { myPartnerSuit = (CardSuit)((this.partnerBids.Where(x => x != BidType.AllTrumps || x != BidType.NoTrumps || x != BidType.Double || x != BidType.ReDouble).ElementAt(0)) - 1); } if (myPartnerSuit != null && allowedCards.Any(x => x.Suit == myPartnerSuit)) { cardToPlay = allowedCards.Where(x => x.Suit == myPartnerSuit).OrderByDescending(x => x.GetValue(this.currentContract)).ElementAt(0); return true; } if (this.myPartnerBurst != null && allowedCards.Any(x => x.Suit == this.myPartnerBurst)) { cardToPlay = allowedCards.Where(x => x.Suit == this.myPartnerBurst).OrderByDescending(x => x.GetValue(this.currentContract)).ElementAt(0); return true; } else { return false; } }
//used only when starts first, could be further improved private bool CardBursterTactic(ref Card cardToPlay, IList<Card> allowedCards, IList<Card> currentTrickCards) { foreach (Card card in allowedCards.OrderByDescending(x => x.GetValue(this.currentContract))) { foreach (Card item in this.remainedInGame.Where(x => x.Suit == card.Suit)) { if (card.Type < item.Type) { if (allowedCards.Count(x => x.Suit == card.Suit) > 1) { cardToPlay = allowedCards.Where(x => x.Suit == card.Suit).OrderByDescending(x => x.GetValue(this.currentContract)).ElementAt(1); return true; } break; } } } return false; }