Ejemplo n.º 1
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));
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 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]);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 5
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]);
        }
Ejemplo n.º 6
0
        public void Find_CanPlayFiveAndOneRankedCards_ReturnFiveRankedCard()
        {
            var boardContext = new BoardContextStub
            {
                ExpectedCards = new[]
                {
                    new Card(Color.Blue, Rank.One),
                    new Card(Color.Green, Rank.Five),
                }
            };

            var player = GetPlayer();

            var playerContext = new PlayerContextStub
            {
                Player = player,
                Hand   = new[]
                {
                    new CardInHand(new Card(Color.Yellow, Rank.Two), player),
                    new CardInHand(new Card(Color.Blue, Rank.One), player),
                    new CardInHand(new Card(Color.Green, Rank.Five), player),
                },
            };

            // action
            var clueToPlayFinder = new ClueToPlayFinder(boardContext, playerContext);
            var result           = clueToPlayFinder.Find();

            // assert
            Assert.IsTrue((result.Action.Outcome & OutcomeFlags.Play) > 0);
            Assert.IsTrue(result.Action.Cards.Any());
            Assert.IsTrue(result.Action.Cards.Any(c => c.Equals(new Card(Color.Green, Rank.Five))));
        }
Ejemplo n.º 7
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());
        }
Ejemplo n.º 8
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();
        }
Ejemplo n.º 9
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));
        }
Ejemplo n.º 10
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());
        }
Ejemplo n.º 11
0
        public void Find_NoCardsToPlay_ReturnsNull()
        {
            var boardContext = new BoardContextStub
            {
                ExpectedCards = new[] { new Card(Color.Blue, Rank.One), }
            };

            var player = GetPlayer();

            var playerContext = new PlayerContextStub
            {
                Player = player,
                Hand   = new [] { new CardInHand(new Card(Color.Yellow, Rank.Two), player) },
            };

            // action
            var clueToPlayFinder = new ClueToPlayFinder(boardContext, playerContext);
            var result           = clueToPlayFinder.Find();

            // assert
            Assert.IsNull(result);
        }