Example #1
0
        public int playRound(Player player, DiceValue pick, int bet)
        {
            using (LogContext.PushProperties(new PropertyEnricher("Player", player, true)))
            {
                Log.Information("Player {Name} has bet {Bet} on {Pick}\tBalance: {Balance}", player.Name, bet, pick, player.Balance);
            }

            if (player == null) throw new ArgumentException("Player cannot be null");
            if (player == null) throw new ArgumentException("Pick cannot be null");
            if (bet < 0) throw new ArgumentException("Bet cannot be negative");

            if (!this.PickCount.ContainsKey(pick)) this.PickCount.Add(pick, 0);
            this.PickCount[pick]++; // Increment counter for pick count for DiceValue

            Log.Information("Deducting bet");
            player.takeBet(bet);
            Log.Information("Balance: {Balance}", player.Balance);

            int matches = 0;
            for (int i = 0; i < dice.Count; i++)
            {
                var value = dice[i].roll();
                Log.Information("Dice {Number} is a {Roll}", i, value);

                if (!this.RollCount.ContainsKey(value)) this.RollCount.Add(value, 0);
                this.RollCount[value]++; // Increment counter for roll count for DiceValue

                if (value.Equals(pick))
                {
                    matches += 1;
                    Log.Information("Match!");
                }
                else
                {
                    Log.Information("Not a Match!");
                }
            }

            int winnings = matches * bet;

            if (matches > 0)
            {
                player.receiveWinnings(winnings);
                player.returnBet(bet);
            }

            Log.Information("Winnings are {Winnings}", winnings);
            Log.Information("Player's Balance is now {Balance}", player.Balance);

            return winnings;
        }
Example #2
0
        public int playRound(Player player, DiceValue pick, int bet)
        {
            if (player == null) throw new ArgumentException("Player cannot be null");
            if (player == null) throw new ArgumentException("Pick cannot be null");
            if (bet < 0) throw new ArgumentException("Bet cannot be negative");

            player.takeBet(bet);

            int matches = 0;
            for (int i = 0; i < dice.Count; i++)
            {
                dice[i].roll();
                if (values[i].Equals(pick)) matches += 1;
            }

            int winnings = matches * bet;
            if (matches > 0)
            {
                player.receiveWinnings(winnings);
            }

            return winnings;
        }
Example #3
0
        public int playRound(Player player, DiceValue pick, int bet)
        {
            if (player == null)
            {
                throw new ArgumentException("Player cannot be null");
            }
            if (player == null)
            {
                throw new ArgumentException("Pick cannot be null");
            }
            if (bet < 0)
            {
                throw new ArgumentException("Bet cannot be negative");
            }

            player.takeBet(bet);

            int matches = 0;

            for (int i = 0; i < dice.Count; i++)
            {
                dice[i].roll();
                if (values[i].Equals(pick))
                {
                    matches += 1;
                }
            }

            int winnings = matches * bet;

            if (matches > 0)
            {
                player.receiveWinnings(winnings);
            }

            return(winnings);
        }
        public void TakesBetWhenBalanceExceedsBet()
        {
            var player = new Player("Test", 10) { Limit = 0 };
            player.takeBet(5);

            // Check bet was taken and error wasn't thrown.
            Assert.Equal(5, player.Balance);
        }
 public void TakeBetThrowsExceptionWhenBetExceedsBalance()
 {
     var player = new Player("Test", 0) { Limit = 0 };
     Assert.Throws<ArgumentException>(() => player.takeBet(5));
 }
Example #6
0
        public void GivenPlayerPlaysARound_WhenTheplayerWinsOrLosesAMatch_BalanceIncreases(
         DiceValue pick,
         DiceValue dieValue1,
         DiceValue dieValue2,
         DiceValue dieValue3,
         int balance,
         int bet,
         int winnings,
         int total,
         string name
            )
        {
            // Arrange.
            var player = new Player(name, balance);

            // Act : deduct bet and add winnings;
            player.takeBet(bet);
            player.receiveWinnings(winnings);

            // Assert
            player.Balance.Should().Be(total);
        }