Exemple #1
0
        public void DiscardEstimator_AllCardsWithSameProbability_ReturnsAllCards()
        {
            var discardStrategyStub = CreateDiscardStrategy();
            var blueOneCard         = new Card(Color.Blue, Rank.One);
            var yellowTwoCard       = new Card(Color.Yellow, Rank.Two);
            var yellowThreeCard     = new Card(Color.Yellow, Rank.Three);

            discardStrategyStub.AddToHand(blueOneCard);
            discardStrategyStub.AddToHand(yellowTwoCard);
            discardStrategyStub.AddToHand(yellowThreeCard);

            var dict = new Dictionary <Card, double>
            {
                [blueOneCard]     = 0.3,
                [yellowTwoCard]   = 0.3,
                [yellowThreeCard] = 0.3
            };

            SetProbabilities(discardStrategyStub, dict);

            var boardContext  = new BoardContextStub();
            var playerContext = PlayerContextFabric.CreateStub(discardStrategyStub.Player, discardStrategyStub.Hand);

            // act
            var estimator = new DiscardEstimator(discardStrategyStub);
            var cards     = estimator.GetPossibleCards(boardContext, playerContext);

            // arrange
            Assert.AreEqual(3, cards.Count);
        }
Exemple #2
0
        public void DiscardEstimator_KnowAboutBlueOneOnlyAndProbability10_ReturnsBlueOne()
        {
            var discardStrategyStub = CreateDiscardStrategy();

            var blueOneCard     = new Card(Color.Blue, Rank.One);
            var yellowTwoCard   = new Card(Color.Yellow, Rank.Two);
            var yellowThreeCard = new Card(Color.Yellow, Rank.Three);

            discardStrategyStub.AddToHand(blueOneCard);
            discardStrategyStub.AddToHand(yellowTwoCard);
            discardStrategyStub.AddToHand(yellowThreeCard);

            var dict = new Dictionary <Card, double>
            {
                [blueOneCard]     = 1.0,
                [yellowTwoCard]   = 0.25,
                [yellowThreeCard] = 0.25
            };

            SetProbabilities(discardStrategyStub, dict);

            var boardContext = new BoardContextStub();
            //new BoardContext(new FireworkPile(discardStrategyStub.GameProvider), new Card[0], new Card[0]);
            var playerContext = PlayerContextFabric.CreateStub(discardStrategyStub.Player, discardStrategyStub.Hand);

            playerContext.KnowAboutRankOrColorPredicate = cardInHand => cardInHand.Card == blueOneCard;

            // Act
            var estimator = new DiscardEstimator(discardStrategyStub);
            var cards     = estimator.GetPossibleCards(boardContext, playerContext);

            // Assert
            Assert.AreEqual(1, cards.Count);
            Assert.IsTrue(cards.Contains(blueOneCard));
        }
Exemple #3
0
        public void DiscardEstimator_BlueOneHasMaxProbability_ReturnsBlueOne()
        {
            var discardStrategyStub = CreateDiscardStrategy();

            var blueOneCard     = new Card(Color.Blue, Rank.One);
            var yellowTwoCard   = new Card(Color.Yellow, Rank.Two);
            var yellowThreeCard = new Card(Color.Yellow, Rank.Three);

            discardStrategyStub.AddToHand(blueOneCard);
            discardStrategyStub.AddToHand(yellowTwoCard);
            discardStrategyStub.AddToHand(yellowThreeCard);

            var dict = new Dictionary <Card, double>
            {
                [blueOneCard]     = 0.5,
                [yellowTwoCard]   = 0.3,
                [yellowThreeCard] = 0.25
            };

            SetProbabilities(discardStrategyStub, dict);

            var boardContext = new BoardContextStub();
            //new BoardContext(new FireworkPile(discardStrategyStub.GameProvider), new Card[0], new Card[0]);
            var playerContext = PlayerContextFabric.CreateStub(discardStrategyStub.Player, discardStrategyStub.Hand);

            // Act
            var estimator = new DiscardEstimator(discardStrategyStub);
            var cards     = estimator.GetPossibleCards(boardContext, playerContext);

            // Assert
            Assert.AreEqual(1, cards.Count);
            Assert.AreEqual(blueOneCard, cards[0]);
        }
Exemple #4
0
        public void DiscardEstimator_KnowSomethingAboutAllCardsAndTheSameProbabilities_ReturnsAllCards()
        {
            var discardStrategyStub = CreateDiscardStrategy();

            var blueOneCard     = new Card(Color.Blue, Rank.One);
            var yellowTwoCard   = new Card(Color.Yellow, Rank.Two);
            var yellowThreeCard = new Card(Color.Yellow, Rank.Three);

            discardStrategyStub.AddToHand(blueOneCard);
            discardStrategyStub.AddToHand(yellowTwoCard);
            discardStrategyStub.AddToHand(yellowThreeCard);

            var dict = new Dictionary <Card, double>
            {
                [blueOneCard]     = 0.33,
                [yellowTwoCard]   = 0.33,
                [yellowThreeCard] = 0.33
            };

            SetProbabilities(discardStrategyStub, dict);

            var boardContext  = new BoardContextStub();//new BoardContext(new FireworkPile(discardStrategyStub.GameProvider), new Card[0], new Card[0]);
            var playerContext = PlayerContextFabric.CreateStub(discardStrategyStub.Player, discardStrategyStub.Hand);

            playerContext.KnowAboutRankOrColorPredicate = cardInHand => true;


            var estimator = new DiscardEstimator(discardStrategyStub);
            var cards     = estimator.GetPossibleCards(boardContext, playerContext);

            Assert.AreEqual(3, cards.Count);
        }
        public void PlayCardEstimator_PlayOneRankedCardInDefaultIfPossible_ReturnsOne(int blowCounter)
        {
            // arrange
            var blueOneCard   = new Card(Color.Blue, Rank.One);
            var whiteTwoCard  = new Card(Color.White, Rank.Two);
            var blueThreeCard = new Card(Color.Blue, Rank.Three);

            var gameProvider     = GameProviderFabric.Create(Color.White, Color.Blue);
            var playStrategyStub = InitPlayStrategy(gameProvider);

            playStrategyStub.AddCardInHand(blueOneCard);
            playStrategyStub.AddCardInHand(whiteTwoCard);
            playStrategyStub.AddCardInHand(blueThreeCard);

            var dict = new Dictionary <Card, Probability>
            {
                { blueOneCard, new Probability(0.2) },
                { whiteTwoCard, new Probability(0.3) },
                { blueThreeCard, new Probability(0.4) },
            };

            SetProbabilities(playStrategyStub, dict);

            var boardContext = new BoardContextStub
            {
                ExpectedCards = new[] { new Card(Color.Blue, Rank.One), new Card(Color.White, Rank.Two), },
                BlowCounter   = blowCounter
            };

            var playerContext = PlayerContextFabric.CreateStub(playStrategyStub.Player, playStrategyStub.Hand);

            var clueAboutOneRank = new ClueAboutRank(Rank.One);
            var blueOneInHand    = playStrategyStub.Hand.First(card => card.Card == blueOneCard);

            playerContext.CluesAboutCard[blueOneInHand] = new List <ClueType> {
                clueAboutOneRank
            };

            // act
            var playCardEstimator = new PlayCardEstimator(playStrategyStub);
            var possibleCards     = playCardEstimator.GetPossibleCards(boardContext, playerContext).ToList();

            // assert
            Assert.IsTrue(possibleCards.Count == 1);
            Assert.AreEqual(blueOneCard, possibleCards.First());
        }
        public void PlayCardEstimator_TwoSubtleCluesWithDifferentProbabilies_ReturnsTwoCards()
        {
            // arrange
            var blueOneCard   = new Card(Color.Blue, Rank.One);
            var whiteTwoCard  = new Card(Color.White, Rank.Two);
            var blueThreeCard = new Card(Color.Blue, Rank.Three);
            var whiteFourCard = new Card(Color.White, Rank.Four);

            var gameProvider     = GameProviderFabric.Create(Color.White, Color.Blue);
            var playStrategyStub = InitPlayStrategy(gameProvider);

            playStrategyStub.AddCardInHand(blueOneCard);
            playStrategyStub.AddCardInHand(whiteTwoCard);
            playStrategyStub.AddCardInHand(blueThreeCard);
            playStrategyStub.AddCardInHand(whiteFourCard);

            var dict = new Dictionary <Card, Probability>
            {
                { blueOneCard, new Probability(0.2) },
                { whiteTwoCard, new Probability(0.3) },
                { blueThreeCard, new Probability(0.4) },
                { whiteFourCard, new Probability(0.5) }
            };

            SetProbabilities(playStrategyStub, dict);

            var playerContext = PlayerContextFabric.CreateStub(playStrategyStub.Player, playStrategyStub.Hand);

            playerContext.IsSubtleCluePredicate =
                cardInHand => new [] { blueOneCard, whiteTwoCard }.Contains(cardInHand.Card);

            var boardContext = new BoardContextStub();

            // act
            var playCardEstimator = new PlayCardEstimator(playStrategyStub);
            var possibleCards     = playCardEstimator.GetPossibleCards(boardContext, playerContext);

            // assert
            Assert.AreEqual(2, possibleCards.Count);
            Assert.IsTrue(possibleCards.Contains(blueOneCard));
            Assert.IsTrue(possibleCards.Contains(whiteTwoCard));
        }
        public void PlayCardEstimator_NoSubtleCluesAndAllProbabilitiesLessThanThreshold_ReturnsEmpty()
        {
            // arrange
            var blueOneCard   = new Card(Color.Blue, Rank.One);
            var whiteTwoCard  = new Card(Color.White, Rank.Two);
            var blueThreeCard = new Card(Color.Blue, Rank.Three);
            var whiteFourCard = new Card(Color.White, Rank.Four);

            var gameProvider     = GameProviderFabric.Create(Color.White, Color.Blue);
            var playStrategyStub = InitPlayStrategy(gameProvider);

            playStrategyStub.AddCardInHand(blueOneCard);
            playStrategyStub.AddCardInHand(whiteTwoCard);
            playStrategyStub.AddCardInHand(blueThreeCard);
            playStrategyStub.AddCardInHand(whiteFourCard);

            var dict = new Dictionary <Card, Probability>
            {
                { blueOneCard, new Probability(0.2) },
                { whiteTwoCard, new Probability(0.3) },
                { blueThreeCard, new Probability(0.4) },
                { whiteFourCard, new Probability(0.5) }
            };

            SetProbabilities(playStrategyStub, dict);

            var boardContext = new BoardContextStub
            {
                ExpectedCards = new[] { new Card(Color.Blue, Rank.One), new Card(Color.White, Rank.One), }
            };

            var playerContext = PlayerContextFabric.CreateStub(playStrategyStub.Player, playStrategyStub.Hand);

            // act
            var playCardEstimator = new PlayCardEstimator(playStrategyStub);
            var possibleCards     = playCardEstimator.GetPossibleCards(boardContext, playerContext);

            // assert
            Assert.IsTrue(!possibleCards.Any());
        }