public void Should_CallTrickPredicate_OnEachSquare()
        {
            // Arrange
            var testSquares = new[]
            {
                Mock.Of <ISquare>(),
                Mock.Of <ISquare>(),
                Mock.Of <ISquare>(),
            };

            var testTricks = new[]
            {
                Mock.Of <ITrick>(),
                Mock.Of <ITrick>(),
                Mock.Of <ITrick>(),
            };
            var trickEngine = new TrickEngine(Mock.Of <IMapHandler>(), testTricks);

            // Act
            var result = trickEngine.TryDoStep(testSquares, out _, out _);

            // Assert
            Assert.IsFalse(result);
            foreach (var trick in testTricks.Select(Mock.Get))
            {
                trick.Verify(t => t.Predicate(It.IsAny <ISquare>()), Times.Exactly(testSquares.Length));
                trick.VerifyNoOtherCalls();
            }
        }
Beispiel #2
0
        public int[] PlayRound()
        {
            var cards = CardCollection.AllCards();

            //Deal cards
            var playerCards = Dealer.Deal(CardCollection.AllCards(), PlayerCount);
            var minHandSize = playerCards.Min(hand => hand.Cards().Count());
            var seats       = Enumerable.Range(0, PlayerCount).Select(i =>
            {
                return(new Seat(i, _players[i], playerCards[i]));
            }).ToArray();

            InitialMove[] initialMoves = DoInitialMoves(playerCards);
            GiveInitialCards(playerCards, initialMoves);

            var         scoreCount     = new ScoreCount(PlayerCount);
            TrickResult previousWinner = null;

            for (int i = 0; i < minHandSize - 1; i++)
            {
                previousWinner = new TrickEngine(seats).PlayTrick(previousWinner);
                scoreCount.Add(previousWinner.Winner.Index, previousWinner.WinnerPrice());
            }

            var bottleTax = initialMoves.Sum(move => move.ToBottle.Score);
            var scores    = Scores(scoreCount, previousWinner.BottleOwner.Index, bottleTax);

            foreach (var player in _players)
            {
                player.RoundEnded(scores);
            }

            return(scores);
        }
        public void Should_CallTrickDoTheThing_OnSquaresWherePredicateIsTrue()
        {
            // Arrange
            var emptySquareList = new ISquare[0] as IReadOnlyCollection <ISquare>;

            var testSquares = new[]
            {
                Mock.Of <ISquare>(),
                Mock.Of <ISquare>(),
                Mock.Of <ISquare>(),
            };

            var testTricks = new[]
            {
                Mock.Of <ITrick>(),
                Mock.Of <ITrick>(),
                Mock.Of <ITrick>(),
            };

            void SetupTruePredicateFor(int i)
            {
                var trickMock = Mock.Get(testTricks[i]);

                trickMock.Setup(t => t.Predicate(testSquares[i])).Returns(true);
                trickMock.Setup(t => t.DoTheThing(out emptySquareList, out emptySquareList));
            }

            SetupTruePredicateFor(0);
            SetupTruePredicateFor(1);
            SetupTruePredicateFor(2);

            var trickEngine = new TrickEngine(Mock.Of <IMapHandler>(), testTricks);

            // Act
            var result = trickEngine.TryDoStep(testSquares, out var processedSquares, out var newSquaresToProcess);

            // Assert
            Assert.IsFalse(result); // No squares are returned as either processed or newToProcess
            Assert.IsEmpty(processedSquares);
            Assert.IsEmpty(newSquaresToProcess);
            foreach (var trick in testTricks.Select(Mock.Get))
            {
                trick.Verify(t => t.Predicate(It.IsAny <ISquare>()), Times.Exactly(testSquares.Length));
                trick.Verify(t => t.DoTheThing(out emptySquareList, out emptySquareList), Times.Once);
                trick.VerifyNoOtherCalls();
            }
        }
Beispiel #4
0
        public void PlayTrick_SetsCorrectWinnerWhenNoCardIsUnderBottlePrice()
        {
            var seats = Enumerable.Range(0, 3).Select(index => {
                var card   = new Card(CardType.Blue, index + StartingBottlePrice + 1, 1);
                var hand   = new Hand(new[] { card });
                var player = Substitute.For <IGameAi>();
                player.Play(Arg.Any <Card[]>()).Returns(card);
                var seat = new Seat(index, player, hand);
                return(seat);
            }).ToArray();
            var result = new TrickEngine(seats).PlayTrick(null);

            Assert.IsNull(result.BottleOwner);
            Assert.AreEqual(StartingBottlePrice, result.BottlePrice);
            Assert.AreEqual(seats[2], result.Winner);
            Assert.AreEqual(3, result.WinnerPrice().Count());
        }
Beispiel #5
0
        public void PlayTrick_StartsFromFirstPlayerIfThereIsNoPreviousResult()
        {
            var seats = Enumerable.Range(0, 3).Select(index => {
                var card   = new Card(CardType.Blue, index + 1, 1);
                var hand   = new Hand(new[] { card });
                var player = Substitute.For <IGameAi>();
                player.Play(Arg.Any <Card[]>()).Returns(card);
                var seat = new Seat(index, player, hand);
                return(seat);
            }).ToArray();

            var result = new TrickEngine(seats).PlayTrick(null);

            Assert.NotNull(result);
            Assert.AreEqual(seats[2], result.BottleOwner);
            Assert.AreEqual(3, result.BottlePrice);
            Assert.AreEqual(seats[2], result.Winner);
            Assert.AreEqual(3, result.WinnerPrice().Count());
        }
        public void Should_ReturnTrue_WhenASquareHasBeenReturnedAsProcessed()
        {
            // Arrange
            var testSquares = new[]
            {
                Mock.Of <ISquare>(),
                Mock.Of <ISquare>(),
                Mock.Of <ISquare>(),
            };

            var testTricks = new[]
            {
                Mock.Of <ITrick>(),
                Mock.Of <ITrick>(),
                Mock.Of <ITrick>(),
            };

            var emptySquareList     = new ISquare[0] as IReadOnlyCollection <ISquare>;
            var processedSquareList = new[]
            {
                testSquares[0],
            } as IReadOnlyCollection <ISquare>;

            var trickMock = Mock.Get(testTricks[0]);

            trickMock.Setup(t => t.Predicate(testSquares[0])).Returns(true);
            trickMock.Setup(t => t.DoTheThing(out processedSquareList, out emptySquareList));

            var trickEngine = new TrickEngine(Mock.Of <IMapHandler>(), testTricks);

            // Act
            var result = trickEngine.TryDoStep(testSquares, out var processedSquares, out var newSquaresToProcess);

            // Assert
            Assert.IsTrue(result); // No squares are returned as either processed or newToProcess
            Assert.IsTrue(processedSquares.Count == 1 && processedSquares.First() == processedSquareList.Single());
            Assert.IsEmpty(newSquaresToProcess);
        }