コード例 #1
0
        public void GetThrownCards_FireworkPileWithBlueOneAndDiscardPileWithBlueOne_ReturnsListWith2Elements()
        {
            //// arrange

            // create fake deck that contains blue one cards only
            FakeGameProvider provider = GameProviderFabric.Create(Color.Blue);

            // play blue one card
            var fireworkPile = new FireworkPile(provider);

            fireworkPile.AddCard(new Card(Color.Blue, Rank.One));

            // discard blue one card
            var discardPile = new DiscardPile(provider);

            discardPile.AddCard(new Card(Color.Blue, Rank.One));

            GameProvider gameProvider = new GameProvider();
            var          pileAnalyzer = new PilesAnalyzer(gameProvider);

            //// act
            IReadOnlyList <Card> actual = pileAnalyzer.GetThrownCards(fireworkPile, discardPile);

            Assert.AreEqual(2, actual.Count);
        }
コード例 #2
0
        public void EstimateCardToPlayProbability_PossibleOneOnly_ReturnsMinimumProbability()
        {
            IGameProvider gameProvider = GameProviderFabric.Create(Color.Blue, Color.Green);

            Game game   = new Game(gameProvider, 2);
            var  player = new Player(game);

            var blueOneCard   = new Card(Color.Blue, Rank.One);
            var blueOneInHand = new CardInHand(player, blueOneCard);

            var guess = new Guess(gameProvider, blueOneInHand);

            guess.Visit(new ClueAboutNotRank(Rank.Five));
            guess.Visit(new ClueAboutNotRank(Rank.Four));
            guess.Visit(new ClueAboutNotRank(Rank.Three));
            guess.Visit(new ClueAboutNotRank(Rank.Two));

            var playStrategy = new PlayCardStrategy(new[] { guess });

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

            var result = playStrategy.EstimateCardToPlayProbability(boardContext);

            Assert.AreEqual(Probability.Minimum, result[blueOneInHand]);
        }
コード例 #3
0
        public void GetCardsWhateverToPlay_EmptyPiles_ReturnsAllUniqueCards()
        {
            IGameProvider gameProvider =
                GameProviderFabric.Create(new List <Color> {
                Color.White, Color.Red
            });

            var fireworkPile = new FireworkPile(gameProvider);
            var discardPile  = new DiscardPile(gameProvider);

            var pileAnalyzer = new PilesAnalyzer(gameProvider);

            // act
            IReadOnlyList <Card> actual = pileAnalyzer.GetCardsWhateverToPlay(fireworkPile, discardPile);

            // assert
            var actualMatrix = new CardsToMatrixConverter(gameProvider).Encode(actual);

            var expectedMatrix = gameProvider.CreateEmptyMatrix();

            expectedMatrix[Rank.One, Color.White]   = 1;
            expectedMatrix[Rank.One, Color.Red]     = 1;
            expectedMatrix[Rank.Two, Color.White]   = 1;
            expectedMatrix[Rank.Two, Color.Red]     = 1;
            expectedMatrix[Rank.Three, Color.White] = 1;
            expectedMatrix[Rank.Three, Color.Red]   = 1;
            expectedMatrix[Rank.Four, Color.White]  = 1;
            expectedMatrix[Rank.Four, Color.Red]    = 1;
            expectedMatrix[Rank.Five, Color.White]  = 1;
            expectedMatrix[Rank.Five, Color.Red]    = 1;

            TestHelper.AreMatrixEqual(expectedMatrix, actualMatrix, gameProvider);
        }
コード例 #4
0
        public void GetThrownCards_FireworkPileWithBlueOneAndDiscardPileWithBlueOne_ReturnsListWithBlueOnesOnly()
        {
            //// arrange

            FakeGameProvider gameProvider =
                GameProviderFabric.Create(new List <Color> {
                Color.Blue, Color.Red
            }.AsReadOnly());

            // play blue one card
            var fireworkPile = new FireworkPile(gameProvider);

            fireworkPile.AddCard(new Card(Color.Blue, Rank.One));

            // discard blue one card
            var discardPile = new DiscardPile(gameProvider);

            discardPile.AddCard(new Card(Color.Blue, Rank.One));

            var pileAnalyzer = new PilesAnalyzer(gameProvider);

            //// act
            IReadOnlyList <Card> actual = pileAnalyzer.GetThrownCards(fireworkPile, discardPile);

            Assert.IsTrue(actual.Count > 0 &&
                          actual.All(card => Equals(card, new Card(Color.Blue, Rank.One))));
        }
コード例 #5
0
        public DiscardStrategyStub CreateDiscardStrategy()
        {
            var gameProvider = GameProviderFabric.Create(Color.Blue, Color.Yellow);

            DiscardStrategyStub stub = new DiscardStrategyStub
            {
                Player       = new Player(new Game(gameProvider, 4)),
                GameProvider = gameProvider,
            };

            return(stub);
        }
コード例 #6
0
        public void KnowAboutNominalOrColor_Default_ReturnsFalse()
        {
            IGameProvider gameProvider = GameProviderFabric.Create(Color.Red, Color.Yellow);

            Guess guess = new Guess(
                gameProvider,
                CreateCardInHand(gameProvider, new Card(Color.Red, Rank.Two)));

            bool result = guess.KnowAboutRankOrColor();

            Assert.IsFalse(result);
        }
コード例 #7
0
        public void GetThrownCards_EmptyPiles_ReturnsEmptyList()
        {
            IGameProvider gameProvider = GameProviderFabric.Create(Color.Multicolor);

            var pileAnalyzer = new PilesAnalyzer(gameProvider);

            var fireworkPile = new FireworkPile(gameProvider);
            var discardPile  = new DiscardPile(gameProvider);

            IReadOnlyList <Card> actual = pileAnalyzer.GetThrownCards(fireworkPile, discardPile);

            Assert.IsEmpty(actual);
        }
コード例 #8
0
        public void GetProbability_EmptyCardsToSearch_ReturnsZero()
        {
            FakeGameProvider gameProvider = GameProviderFabric.Create(Color.Red);

            Guess guess = new Guess(gameProvider,
                                    CreateCardInHand(gameProvider, new Card(Color.Red, Rank.One)));

            List <Card> excludedCards = new List <Card>();
            List <Card> cardsToSearch = new List <Card>();

            Probability result = guess.GetProbability(cardsToSearch, excludedCards);

            Assert.AreEqual(0, result.Value);
        }
コード例 #9
0
        public void KnowAboutNominalOrColor_NotAnyColorsExceptRed_ReturnsTrue()
        {
            IGameProvider gameProvider = GameProviderFabric.Create(Color.Red, Color.Yellow);

            var redTwoCardInHand = CreateCardInHand(gameProvider, new Card(Color.Red, Rank.Two));
            var cardsToClue      = new[] { redTwoCardInHand };

            Guess guess = new Guess(gameProvider, redTwoCardInHand);

            guess.Visit(new ClueAboutNotColor(Color.Yellow));

            bool result = guess.KnowAboutRankOrColor();

            Assert.IsTrue(result);
        }
コード例 #10
0
        public void KnowAllAboutNominalAndColor_ClueAboutRedAndClueAboutTwo_ReturnsTrue()
        {
            IGameProvider gameProvider = GameProviderFabric.Create(Color.Red);

            var   redTwoCardInHand = CreateCardInHand(gameProvider, new Card(Color.Red, Rank.Two));
            var   cardsToClue      = new[] { redTwoCardInHand };
            Guess guess            = new Guess(gameProvider, redTwoCardInHand);

            guess.Visit(new ClueAboutColor(Color.Red));
            guess.Visit(new ClueAboutRank(Rank.Two));

            bool result = guess.KnowAboutNominalAndColor();

            Assert.IsTrue(result);
        }
コード例 #11
0
        public void GetUniqueCards_DiscardBlueTwoCard_ContainsBlueTwoCard()
        {
            IGameProvider gameProvider = GameProviderFabric.Create(Color.Blue);

            FireworkPile fireworkPile = new FireworkPile(gameProvider);
            DiscardPile  discardPile  = new DiscardPile(gameProvider);

            Card blueTwoCard = new Card(Color.Blue, Rank.Two);

            discardPile.AddCard(blueTwoCard);

            var pileAnalyzer = new PilesAnalyzer(gameProvider);

            IReadOnlyList <Card> actual = pileAnalyzer.GetUniqueCards(fireworkPile, discardPile);

            Assert.IsTrue(actual.Contains(new Card(Color.Blue, Rank.Two)));
        }
コード例 #12
0
        public void KnowAllAboutNominalAndColor_ClueAboutColorOnly_ReturnsFalse()
        {
            IGameProvider gameProvider = GameProviderFabric.Create(new List <Color> {
                Color.Red, Color.Yellow
            });

            var redTwoCardInHand = CreateCardInHand(gameProvider, new Card(Color.Red, Rank.Two));
            var cardsToClue      = new[] { redTwoCardInHand };

            Guess guess = new Guess(gameProvider, redTwoCardInHand);

            guess.Visit(new ClueAboutColor(Color.Red));

            bool result = guess.KnowAboutNominalAndColor();

            Assert.IsFalse(result);
        }
コード例 #13
0
        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());
        }
コード例 #14
0
        //[Test]
        void EstimateDiscardProbability__()
        {
            // arrange
            var provider            = GameProviderFabric.Create(Color.Blue, Color.Green);
            var guessAboutBlueThree = CreateGuess(provider, new Card(Color.Blue, Rank.Three));
            var guessAboutGreenTwo  = CreateGuess(provider, new Card(Color.Green, Rank.Two));
            var discardStrategy     = new DiscardStrategy(new [] { guessAboutGreenTwo, guessAboutBlueThree });

            var boardContext = new BoardContextStub
            {
                ExcludedCards       = new List <Card>(),
                WhateverToPlayCards = new List <Card>(),
            };

            //act
            discardStrategy.EstimateDiscardProbability(boardContext);
            Assert.Fail();
        }
コード例 #15
0
        public void GetUniqueCards_DiscardAllYellowOneCards_DoesNotContainYellowCards()
        {
            IGameProvider provider = GameProviderFabric.Create(Color.Yellow);

            var fireworkPile = new FireworkPile(provider);
            var discardPile  = new DiscardPile(provider);

            discardPile.AddCard(new Card(Color.Yellow, Rank.One));
            discardPile.AddCard(new Card(Color.Yellow, Rank.One));
            discardPile.AddCard(new Card(Color.Yellow, Rank.One));

            GameProvider gameProvider = new GameProvider();
            var          pileAnalyzer = new PilesAnalyzer(gameProvider);

            IReadOnlyList <Card> actual = pileAnalyzer.GetUniqueCards(fireworkPile, discardPile);

            Assert.IsFalse(actual.Any(card => card.Color == Color.Yellow));
        }
コード例 #16
0
        public void GetUniqueCards_PlayRedOneAndDiscardRedOne_DoesNotContainRedOne()
        {
            IGameProvider provider = GameProviderFabric.Create(Color.Red);

            var fireworkPile = new FireworkPile(provider);

            fireworkPile.AddCard(new Card(Color.Red, Rank.One));

            var discardedPile = new DiscardPile(provider);

            discardedPile.AddCard(new Card(Color.Red, Rank.One));

            var pileAnalyzer = new PilesAnalyzer(provider);

            IReadOnlyList <Card> actual = pileAnalyzer.GetUniqueCards(fireworkPile, discardedPile);

            Assert.IsFalse(actual.Contains(new Card(Color.Red, Rank.One)));
        }
コード例 #17
0
        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));
        }
コード例 #18
0
        public void GetCardsWhateverToPlay_DiscardedAllWhiteOne_DoesNotContainWhiteCards()
        {
            FakeGameProvider provider = GameProviderFabric.Create(new List <Color> {
                Color.White, Color.Red
            });

            var fireworkPile = new FireworkPile(provider);
            var discardPile  = new DiscardPile(provider);

            discardPile.AddCard(new Card(Color.White, Rank.One));
            discardPile.AddCard(new Card(Color.White, Rank.One));
            discardPile.AddCard(new Card(Color.White, Rank.One));

            GameProvider gameProvider = new GameProvider();
            var          pileAnalyzer = new PilesAnalyzer(gameProvider);

            IReadOnlyList <Card> actual = pileAnalyzer.GetCardsWhateverToPlay(fireworkPile, discardPile);

            Assert.IsTrue(actual.All(card => card.Color != Color.White));
        }
コード例 #19
0
        public void GetProbability_ExcludeAllRedTwoCards_ReturnsZeroForRedTwoCard()
        {
            FakeGameProvider gameProvider = GameProviderFabric.Create(Color.Red);

            Guess guess = new Guess(gameProvider,
                                    CreateCardInHand(gameProvider, new Card(Color.Red, Rank.Three)));

            List <Card> excludedCards = new List <Card>
            {
                new Card(Color.Red, Rank.Two),
                new Card(Color.Red, Rank.Two),
            };

            List <Card> cardsToSearch = new List <Card> {
                new Card(Color.Red, Rank.Two)
            };

            Probability result = guess.GetProbability(cardsToSearch, excludedCards);

            Assert.AreEqual(0, result.Value);
        }
コード例 #20
0
        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());
        }
コード例 #21
0
        public void GetProbability_ExcludeAllCardsExceptYellowTwo_ReturnsOneForYellowTwo()
        {
            IGameProvider gameProvider = GameProviderFabric.Create(new List <Color> {
                Color.Red, Color.Yellow
            });

            Guess guess = new Guess(gameProvider,
                                    CreateCardInHand(gameProvider, new Card(Color.Yellow, Rank.Two)));

            List <Card> cardsToExclude = new List <Card>
            {
                new Card(Color.Red, Rank.One),
                new Card(Color.Red, Rank.One),
                new Card(Color.Red, Rank.One),
                new Card(Color.Red, Rank.Two),
                new Card(Color.Red, Rank.Two),
                new Card(Color.Red, Rank.Three),
                new Card(Color.Red, Rank.Three),
                new Card(Color.Red, Rank.Four),
                new Card(Color.Red, Rank.Four),
                new Card(Color.Red, Rank.Five),
                new Card(Color.Yellow, Rank.One),
                new Card(Color.Yellow, Rank.One),
                new Card(Color.Yellow, Rank.One),
                // miss yellow two.
                new Card(Color.Yellow, Rank.Three),
                new Card(Color.Yellow, Rank.Three),
                new Card(Color.Yellow, Rank.Four),
                new Card(Color.Yellow, Rank.Four),
                new Card(Color.Yellow, Rank.Five),
            };

            List <Card> cardsToSearch = new List <Card> {
                new Card(Color.Yellow, Rank.Two)
            };

            Probability result = guess.GetProbability(cardsToSearch, cardsToExclude);

            Assert.AreEqual(1.0, result.Value);
        }