public void GivenIHaveNotRolledDoublesThenIGetAnotherTurn()
        {
            var rolls    = new[] { 6, 6, 5, 2 };
            var numRolls = 0;

            randomizer.GetRandomNumber(1, 6).Returns(i => rolls[numRolls++]);

            player.TakeTurn(new Cup(2, randomizer));

            player.CurrentSquare.Should().Be(board.Squares[19]);
        }
예제 #2
0
        public int Roll()
        {
            var value = randomizer.GetRandomNumber(1, 6);

            LastValue = value;
            return(value);
        }
        public static TransportType GetRandomTransportTypeBetweenCarAndBus(IRandomizer randomizer)
        {
            var types = new[] { TransportType.Bus, TransportType.Car };
            var index = randomizer.GetRandomNumber(0, types.Length);

            return(types[index]);
        }
예제 #4
0
        public void ThenPlayersCollect200Dollars()
        {
            // They will roll 10 each time, but not doubles
            var numRolls = 0;

            randomizer.GetRandomNumber(1, 6).Returns(
                i => numRolls++ % 2 == 0 ? 6 : 4
                );

            for (int i = 0; i < 5; i++)
            {
                game.PlayRound();
            }

            game.IsOver.Should().BeFalse();
            game.Players.ToList().ForEach(p => Assert.That(p.Balance, Is.EqualTo(2200)));
        }
        public static TransportType GetRandomTransportWithoutType(TransportType transportType, IRandomizer randomizer, TransportType[] availableTransportTypes)
        {
            var types        = availableTransportTypes.Where(t => t != transportType).ToArray();
            var randomNumber = randomizer.GetRandomNumber(0, types.Length);
            var type         = types[randomNumber];

            return(type);
        }
        private List <string> GetRandomNeighbors(List <string> appropriateCandidates, int needCountPassengers)
        {
            var randomNeighbors = new List <string>();

            for (var i = 0; i < needCountPassengers; i++)
            {
                if (appropriateCandidates.Count == 0)
                {
                    return(randomNeighbors);
                }
                var randomPassengerIndex = randomizer.GetRandomNumber(0, appropriateCandidates.Count - 1);
                var randomPassengerId    = appropriateCandidates[randomPassengerIndex];

                randomNeighbors.Add(randomPassengerId);
                appropriateCandidates.RemoveAt(randomPassengerIndex);
            }

            return(randomNeighbors);
        }
예제 #7
0
        public void RollDice(IDice[] dice)
        {
            if (RollsLeft < 1)
            {
                throw new InvalidOperationException($"Player {Players[ActivePlayer]} has exceeded the maximum number of dice rolls in this turn.");
            }

            if (dice.Length != 5)
            {
                throw new RankException("Only rank of 5 dices is supported.");
            }

            foreach (var die in dice)
            {
                if (die.IsUnlocked)
                {
                    die.Result = _randomizer.GetRandomNumber(1, die.SideNumber);
                }
            }

            RollResult = dice;
            RollsLeft--;
        }
        public void Should_create_neighborhood_when_set_neighbors_count_for_each_passengers()
        {
            const int columns    = 2;
            var       passengers = CreatePassengers(columns * columns);

            randomizer.GetRandomNumber(Arg.Any <int>(), Arg.Any <int>())
            .Returns(0);

            var result = manager.GetEachPassengerNeighbors(4, columns, passengers);

            result["1"].Should().BeEquivalentTo(new List <string> {
                "2", "3", "4"
            });
            result["2"].Should().BeEquivalentTo(new List <string> {
                "1", "3", "4"
            });
            result["3"].Should().BeEquivalentTo(new List <string> {
                "1", "2", "4"
            });
            result["4"].Should().BeEquivalentTo(new List <string> {
                "1", "2", "3"
            });
        }
예제 #9
0
        public void RollDiceCommand_CommandExecuted_ReturnsRollResults(
            int rollResult)
        {
            _randomizer.GetRandomNumber(1, 6).Returns(rollResult);

            _rollDiceCommand.Execute(null);
            var expected = rollResult;
            var result   = _vm.Dice;

            Assert.AreEqual(expected, result[0].Result);
            Assert.AreEqual(expected, result[1].Result);
            Assert.AreEqual(expected, result[2].Result);
            Assert.AreEqual(expected, result[3].Result);
            Assert.AreEqual(expected, result[4].Result);
        }
        public static TransportType GetRandomTransportType(IRandomizer randomizer, TransportType[] availableTransportTypes)
        {
            var index = randomizer.GetRandomNumber(0, availableTransportTypes.Length);

            return(availableTransportTypes[index]);
        }
예제 #11
0
 public virtual void SetUp()
 {
     randomizer = Substitute.For <IRandomizer>();
     randomizer.GetRandomNumber(1, 6).Returns(6);
     cup = new Cup(2, randomizer);
 }
예제 #12
0
        public void RollDice_GivenUnlockedDices_ResultsAreStored(int expectedRollResult)
        {
            _randomizer.GetRandomNumber(MIN_VALUE, MAX_VALUE).Returns(expectedRollResult);
            var dices = MakeNewDiceSet();

            _game.NewGame("A");

            _game.RollDice(dices);
            var result = _game.RollResult.All(d => d.Result == expectedRollResult);

            Assert.IsTrue(result);
        }