private float MaxHandValue(Card card, PlayerTurnContext context)
        {
            var suit = card.Suit;
            var value = card.GetValue();
            var isTrump = context.TrumpCard.Suit == suit;

            var result = 0f;

            var cardsToTake = this.cardtracker
                .AllCards[suit]
                .Where(x => x.Key < value &&
                    (x.Value == CardTracerState.InOpponentHand || x.Value == CardTracerState.Unknown))
                .ToList();

            if (isTrump)
            {
                cardsToTake
                    .AddRange(this.cardtracker
                        .AllCards
                        .Where(s => s.Key != suit)
                        .SelectMany(c => c.Value)
                        .Where(x => x.Value == CardTracerState.InOpponentHand || x.Value == CardTracerState.Unknown));
            }

            var high = cardsToTake.Count > 0 ? cardsToTake.Max(x => x.Key) : 0;

            result += high;

            if (isTrump)
            {
                result += 10;
            }

            return result / (this.MaxTakeCases(value, suit) - cardsToTake.Count());
        }
Exemple #2
0
        public void TwoEqualCardsAreConsideredTheSame()
        {
            var first = new Card(CardSuit.Club, CardType.Ace);
            var second = new Card(CardSuit.Club, CardType.Ace);

            Assert.AreEqual(first, second);
        }
        public ICollection<Card> GetOpponentCards(ICollection<Card> myCards, ICollection<Card> playedCards, Card activeTrumpCard, CardSuit suit)
        {
            var playerCards = new CardCollection
                                  {
                                      new Card(suit, CardType.Nine),
                                      new Card(suit, CardType.Jack),
                                      new Card(suit, CardType.Queen),
                                      new Card(suit, CardType.King),
                                      new Card(suit, CardType.Ten),
                                      new Card(suit, CardType.Ace),
                                  };

            foreach (var card in myCards.Where(x => x.Suit == suit))
            {
                playerCards.Remove(card);
            }

            foreach (var card in playedCards.Where(x => x.Suit == suit))
            {
                playerCards.Remove(card);
            }

            if (activeTrumpCard != null)
            {
                playerCards.Remove(activeTrumpCard);
            }

            return playerCards;
        }
 public void TestDeckChangeTrumpCard()
 {
     var card = new Card(CardSuit.Club, CardType.Jack);
     var deck = new Santase.Logic.Cards.Deck();
     deck.ChangeTrumpCard(card);
     Assert.AreEqual(card, deck.GetTrumpCard);
 }
 private float PointAndSuitCountParameter(Card card, PlayerTurnContext context, ICollection<Card> allowedCards)
 {
     var cardSuit = card.Suit;
     float cardValue = card.GetValue();
     float coutOfSuitInHand = allowedCards.Count(x => x.Suit == cardSuit);
     return (11f - cardValue) * coutOfSuitInHand;
 }
        public double CalculateProbabilityCardToBeTaken(Card card, ICollection<Card> myCards, ICollection<Card> playedCards)
        {
            ICollection<Card> opponentCards = this.opponentsCardProvider.GetOpponentCards(myCards, playedCards, this.context.TrumpCard, card.Suit);
            ICollection<Card> trumpOpponentCard = this.opponentsCardProvider.GetOpponentCards(myCards, playedCards, this.context.TrumpCard, this.context.TrumpCard.Suit);
            int biggestThanCardCount = 0;
            foreach (var opponentCard in opponentCards)
            {
                if (opponentCard.Suit == this.context.TrumpCard.Suit && card.Suit != opponentCard.Suit)
                {
                    biggestThanCardCount++;
                }
                else if (opponentCard.GetValue() > card.GetValue())
                {
                    biggestThanCardCount++;
                }
            }

            if (card.Suit != this.context.TrumpCard.Suit)
            {
                biggestThanCardCount += trumpOpponentCard.Count;
            }

            int lesserThanCardCount = 24 - playedCards.Count - biggestThanCardCount - 6;
            if (lesserThanCardCount < 6)
            {
                return 1;
            }

            double result = CalculateFactoriel(lesserThanCardCount) / SixFactoriel * CalculateFactoriel(lesserThanCardCount - 6);
            return 1 - result;
        }
Exemple #7
0
 public void CloneShouldReturnObjectWithTheSameHashCode()
 {
     var card = new Card(CardSuit.Spade, CardType.Nine);
     var newCard = card.DeepClone();
     Assert.IsNotNull(newCard);
     Assert.AreEqual(card.GetHashCode(), newCard.GetHashCode());
 }
        protected Announce PossibleAnnounce(Card cardToBePlayed, Card cardTrump)
        {
            CardType cardTypeToSearch;
            if (cardToBePlayed.Type == CardType.Queen)
            {
                cardTypeToSearch = CardType.King;
            }
            else if (cardToBePlayed.Type == CardType.King)
            {
                cardTypeToSearch = CardType.Queen;
            }
            else
            {
                return Announce.None;
            }
            var cardToSearch = new Card(cardToBePlayed.Suit, cardTypeToSearch);

            if (!this.cards.Contains(cardToSearch))
            {
                return Announce.None;
            }

            if (cardToBePlayed.Suit == cardTrump.Suit)
            {
                return Announce.Forty;
            }
            else
            {
                return Announce.Twenty;
            }
        }
 public void ExpectTrumpCardToEqualSwappedCard()
 {
     var deck = new Deck();
     var card = new Card(CardSuit.Club, CardType.Ace);
     deck.ChangeTrumpCard(card);
     Assert.AreEqual(card, deck.GetTrumpCard);
 }
 public void ChangingTrumpCardShouldNotThrow()
 {
     Deck deck = new Deck();
     Card trumpCard = deck.GetTrumpCard;
     Card newCard = new Card(CardSuit.Heart, CardType.Nine);
     deck.ChangeTrumpCard(newCard);
 }
 public void AddCardShouldCallPlayersAddCardMethod()
 {
     var player = new Mock<BasePlayer>();
     var roundPlayerInfo = new RoundPlayerInfo(player.Object);
     var card = new Card(CardSuit.Club, CardType.Ace);
     roundPlayerInfo.AddCard(card);
     player.Verify(x => x.AddCard(card), Times.Once());
 }
 public void AddCardShouldAddTheCardToTheLocalCardsList()
 {
     var player = new Mock<BasePlayer>();
     var roundPlayerInfo = new RoundPlayerInfo(player.Object);
     var card = new Card(CardSuit.Club, CardType.Ace);
     roundPlayerInfo.AddCard(card);
     Assert.IsTrue(roundPlayerInfo.Cards.Contains(card));
 }
        public float CardScore(Card card, PlayerTurnContext context, ICollection<Card> allowedCards)
        {
            float result = 0f;
            result += this.PointAndSuitCountParameter(card, context, allowedCards);
            result -= PointAndSuitMultiplier * this.PointAndSuitCountParameter(card, context, allowedCards);

            return result;
        }
Exemple #14
0
        public void EqualsShouldReturnFalseWhenGivenNonCardObject()
        {
            var card = new Card(CardSuit.Club, CardType.Nine);

            // ReSharper disable once SuspiciousTypeConversion.Global
            var areEqual = card.Equals(new CardTests());
            Assert.IsFalse(areEqual);
        }
 public void DeckShouldReturnProperTrumpCardAfterChangingIt()
 {
     var deck = new Deck();
     var newTrumpCard = new Card(CardSuit.Heart, CardType.Ace);
     deck.ChangeTrumpCard(newTrumpCard);
     var currentTrumpCard = deck.GetTrumpCard;
     Assert.AreSame(newTrumpCard, currentTrumpCard);
 }
Exemple #16
0
 public void ChangeTrumpCardShouldWorkProperly()
 {
     IDeck deck = new Deck();
     var card = new Card(CardSuit.Spade, CardType.Nine);
     deck.ChangeTrumpCard(card);
     var trumpCard = deck.TrumpCard;
     Assert.AreEqual(card, trumpCard);
 }
Exemple #17
0
 public void ChangeTrumpCard(Card newCard)
 {
     this.TrumpCard = newCard;
     if (this.listOfCards.Count > 0)
     {
         this.listOfCards[0] = newCard;
     }
 }
Exemple #18
0
 public virtual void StartRound(ICollection<Card> cards, Card trumpCard, int myTotalPoints, int opponentTotalPoints)
 {
     this.Cards.Clear();
     foreach (var card in cards)
     {
         this.Cards.Add(card);
     }
 }
 public void Add(Card edge)
 {
     if (!this.Neighbours.ContainsKey(edge))
     {
         var child = new TreeNode();
         this.Neighbours.Add(edge, child);
     }
 }
 public CardStatistic(int worth, int canTake, int taken3, int lengthOfSuit, Card card )
 {
     this.CardWorth = worth;
     this.CanTakeCount = canTake;
     this.CanBeTakenCount = taken3;
     this.Card = card;
     this.LengthOfSuit = lengthOfSuit;
 }
        public void ChangeTrumpCardTest(CardSuit suit, CardType type)
        {
            var newCard = new Card(suit, type);
            var deck = new Deck();

            deck.ChangeTrumpCard(newCard);

            Assert.AreNotEqual(0, deck.CardsLeft, "Change card doesn't work");
        }
 public void SetCard(Card card)
 {
     this.Card = card;
     this.Image.Source = ImageFromRelativePath(
         this,
         card != null ? $"Assets/Cards/{card.Type}{card.Suit}.png" : "Assets/Cards/Back.png");
     this.Image.Visibility = Visibility.Visible;
     this.Image.Opacity = 1;
 }
Exemple #23
0
 public void CloneShouldReturnEqualObjectWithEqualProperties()
 {
     var card = new Card(CardSuit.Club, CardType.Ace);
     var newCard = card.DeepClone();
     Assert.IsNotNull(newCard);
     Assert.IsTrue(card.Equals(newCard));
     Assert.AreEqual(card.Suit, newCard.Suit);
     Assert.AreEqual(card.Type, newCard.Type);
 }
 public PlayerTurnContext(
     BaseRoundState state,
     Card trumpCard,
     int cardsLeftInDeck)
 {
     this.State = state;
     this.TrumpCard = trumpCard;
     this.CardsLeftInDeck = cardsLeftInDeck;
 }
Exemple #25
0
 public PlayerAction(
     PlayerActionType type,
     Card card,
     Announce announce)
 {
     this.Type = type;
     this.Card = card;
     this.Announce = announce;
 }
        public void DeckShouldChangeTrumpCardCorrectly()
        {
            Deck deck = new Deck();
            Card newTrumpCard = new Card(CardSuit.Spade, CardType.Ace);

            deck.ChangeTrumpCard(newTrumpCard);

            Assert.AreEqual(newTrumpCard, deck.GetTrumpCard);
        }
        private int NumberOfHandsCardCanTake(Card card, PlayerTurnContext context)
        {
            var count = this.cardTracker.AllCards[card.Suit]
                   .Where(x => (x.Value == CardTracerState.InOpponentHand || x.Value == CardTracerState.Unknown)
                               && x.Key < card.GetValue())
                   .Count();

            return count;
        }
        public void ChangeTrumpCardShouldChangeDeckTrumpCardToTheNewTrumpCardInstance()
        {
            var deck = new Deck();
            var newTrumpCard = new Card(CardSuit.Club, CardType.Ace);

            deck.ChangeTrumpCard(newTrumpCard);

            Assert.AreEqual(newTrumpCard, deck.GetTrumpCard);
        }
 public GameAction(Card opponent, Card player, PlayerTurnContext context, ICardTracker cardTracker)
 {
     this.OpponetCard = opponent;
     this.PlayerCard = player;
     this.PlayerTakes = this.CheckIfPlayerTakes(opponent, player, context);
     this.HandValue = opponent.GetValue() + player.GetValue();
     this.CardMaxWorth = this.CardMaxWorthCalculator(player, cardTracker);
     this.OpponentPoints = context.FirstPlayerRoundPoints;
     this.PlayerPoints = context.SecondPlayerRoundPoints;
 }
Exemple #30
0
        public void TestChangeDeckTrump()
        {
            Card trumpCard = new Card(CardSuit.Heart, CardType.King);
            Deck deck = new Deck();

            deck.ChangeTrumpCard(trumpCard);

            Assert.AreEqual(trumpCard, deck.GetTrumpCard);
            Assert.AreEqual(true, deck.GetTrumpCard.Equals(trumpCard));
        }