internal static void PlayGame(int bet, Game game, Player player, ref DiceValue pick, int currentGame, ref int winCount, ref int loseCount)
        {
            Console.Write("Start Game {0}: ", currentGame);
            Console.WriteLine("{0} starts with balance {1}", player.Name, player.Balance);

            int turn = 0;

            while (player.balanceExceedsLimitBy(bet) && player.Balance < 200)
            {
                try
                {
                    PlayRound(bet, game, player, pick, ref winCount, ref loseCount);
                }
                catch (ArgumentException e)
                {
                    Console.WriteLine("{0}\n\n", e.Message);
                }

                pick = Dice.RandomValue;
                turn++;
            } //while

            Console.Write("{1} turns later.\nEnd Game {0}: ", turn, currentGame);
            Console.WriteLine("{0} now has balance {1}\n", player.Name, player.Balance);
        }
        public void BalanceExceedsLimitByReturnsTrueWhenBalanceExceedsBetLimit()
        {
            var player = new Player("Test", 10) { Limit = 0 };

            var response = player.balanceExceedsLimitBy(5);

            Assert.True(response);
        }
        public void BalanceExceedsLimitByReturnsFalseWhenBalanceDoesNotExceedBetLimit()
        {
            var player = new Player("Test", 10) { Limit = 0 };

            var response = player.balanceExceedsLimitBy(15);

            Assert.False(response);
        }
        public void BalanceExceedsLimitByReturnsFalseOnEqual()
        {
            var player = new Player("Test", 5);

            var response = player.balanceExceedsLimitBy(5);

            Assert.True(response);
        }
Example #5
0
        public void EnsurePlayerIsNotWinningTooFrequently()
        {
            var die1 = new Dice();
            var die2 = new Dice();
            var die3 = new Dice();

            // Introduce a player with $100
            var player = new Player("SomeGuy", 100);

            // Choose a symbol from the playmat.
            var pick = Dice.RandomValue;

            // Place a bet of $5
            const int bet = 5;

            // Start a game
            var game = new Game(die1, die2, die3);
            var numMatches = 0;
            var numturns = 0;

            while (player.balanceExceedsLimitBy(bet) && player.Balance < 150)
            {
                numturns++;
                IList<DiceValue> currentValues1 = new List<DiceValue>(game.CurrentDiceValues);
                game.PlayRound(player, pick, bet);
                var currentValues2 = game.CurrentDiceValues;

                try
                {
                    currentValues1.Should().NotBeEquivalentTo(currentValues2);
                }
                catch (AssertException e)
                {
                    numMatches++;
                }
            }

            numMatches.Should().BeLessThan((int)Math.Round(0.125 * numturns));
        }
Example #6
0
        static void Main(string[] args)
        {
            // Create Dice.
            IDice d1 = new Dice();
            IDice d2 = new Dice();
            IDice d3 = new Dice();

            // Create player.
            IPlayer p = new Player("Fred", 100);

            Console.WriteLine(p);
            Console.WriteLine();

            // Create Game.
            Console.WriteLine("New game for {0}", p.Name);
            Game g = new Game(d1, d2, d3);

            // Initial dice values? Why does this matter?
            IList <DiceValue> cdv = g.CurrentDiceValues;

            Console.WriteLine("Current dice values : {0} {1} {2}", cdv[0], cdv[1], cdv[2]);

            // Unused random dice value? Why is this done?
            DiceValue rv = Dice.RandomValue;

            // Unused random
            Random random = new Random();

            // Setup initial conditions.
            int bet = 5;

            p.Limit = 0;
            int       winnings = 0;
            DiceValue pick     = Dice.RandomValue;

            Console.WriteLine("Chosen Dice Value:" + pick);

            int totalWins   = 0;
            int totalLosses = 0;

            while (true)
            {
                int winCount  = 0;
                int loseCount = 0;

                // Play 100 times
                for (int i = 0; i < 100; i++)
                {
                    // Re-creating player with the same balance each time.
                    p = new Player("Fred", 100);
                    Console.Write("Start Game {0}: ", i);
                    Console.WriteLine("{0} starts with balance {1}", p.Name, p.Balance);
                    int turn = 0;

                    // Balance lower limit 0 upper limit 200.
                    while (p.balanceExceedsLimitBy(bet) && p.Balance < 200)
                    {
                        try
                        {
                            winnings = g.PlayRound(p, pick, bet);
                            cdv      = g.CurrentDiceValues;

                            Console.WriteLine("Picked {3} and Rolled {0} {1} {2}", cdv[0], cdv[1], cdv[2], pick);
                            if (winnings > 0)
                            {
                                Console.WriteLine("{0} bet {3} and won {1} balance now {2}", p.Name, winnings, p.Balance, bet);
                                winCount++;
                            }
                            else
                            {
                                Console.WriteLine("{0} bet {3} and lost {1} balance now {2}", p.Name, bet, p.Balance, bet);
                                loseCount++;
                            }
                        }
                        catch (ArgumentException e)
                        {
                            Console.WriteLine("{0}\n\n", e.Message);
                        }
                        pick     = Dice.RandomValue;
                        winnings = 0;
                        turn++;
                    } //while

                    Console.Write("{1} turns later.\nEnd Game {0}: ", turn, i);
                    Console.WriteLine("{0} now has balance {1}\n", p.Name, p.Balance);
                } //for

                Console.WriteLine("Win count = {0}, Lose Count = {1}, {2:0.00}", winCount, loseCount, (float)winCount / (winCount + loseCount));
                totalWins   += winCount;
                totalLosses += loseCount;

                string ans = Console.ReadLine();
                if (ans.Equals("q"))
                {
                    break;
                }
            } //while true
            Console.WriteLine("Overall win rate = {0}%", (float)(totalWins * 100) / (totalWins + totalLosses));
            Console.ReadLine();
        }
Example #7
0
        public void BalanceExceedsLimitBy_With5DollarBetWhenOnly6DollarsRemaining_ReturnsFalse(string name)
        {
            var player = new Player(name, 6) { Limit = 0 };

            player.balanceExceedsLimitBy(5).Should().BeTrue();
        }
Example #8
0
        static void Main(string[] args)
        {
            Dice d1 = new Dice();
            Dice d2 = new Dice();
            Dice d3 = new Dice();

            Player p = new Player("Fred", 100);

            Console.WriteLine(p);
            Console.WriteLine();

            Console.WriteLine("New game for {0}", p.Name);
            Game g = new Game(d1, d2, d3);
            IList <DiceValue> cdv = g.CurrentDiceValues;

            Console.WriteLine("Current dice values : {0} {1} {2}", cdv[0], cdv[1], cdv[2]);

            DiceValue rv = Dice.RandomValue;

            Random random = new Random();
            int    bet    = 5;

            p.Limit = 0;
            int       winnings = 0;
            DiceValue pick     = Dice.RandomValue;

            int totalWins   = 0;
            int totalLosses = 0;

            while (true)
            {
                int winCount  = 0;
                int loseCount = 0;
                for (int i = 0; i < 100; i++)
                {
                    p = new Player("Fred", 100);
                    Console.Write("Start Game {0}: ", i);
                    Console.WriteLine("{0} starts with balance {1}", p.Name, p.Balance);
                    int turn = 0;
                    while (p.balanceExceedsLimitBy(bet) && p.Balance < 200)
                    {
                        try
                        {
                            winnings = g.playRound(p, pick, bet);
                            cdv      = g.CurrentDiceValues;

                            Console.WriteLine("Rolled {0} {1} {2}", cdv[0], cdv[1], cdv[2]);
                            if (winnings > 0)
                            {
                                Console.WriteLine("{0} won {1} balance now {2}", p.Name, winnings, p.Balance);
                                winCount++;
                            }
                            else
                            {
                                Console.WriteLine("{0} lost {1} balance now {2}", p.Name, bet, p.Balance);
                                loseCount++;
                            }
                        }
                        catch (ArgumentException e)
                        {
                            Console.WriteLine("{0}\n\n", e.Message);
                        }
                        pick     = Dice.RandomValue;
                        winnings = 0;
                        turn++;
                    } //while

                    Console.Write("{1} turns later.\nEnd Game {0}: ", turn, i);
                    Console.WriteLine("{0} now has balance {1}\n", p.Name, p.Balance);
                } //for

                Console.WriteLine("Win count = {0}, Lose Count = {1}, {2:0.00}", winCount, loseCount, (float)winCount / (winCount + loseCount));
                totalWins   += winCount;
                totalLosses += loseCount;

                string ans = Console.ReadLine();
                if (ans.Equals("q"))
                {
                    break;
                }
            } //while true
            Console.WriteLine("Overall win rate = {0}%", (float)(totalWins * 100) / (totalWins + totalLosses));
            Console.ReadLine();
        }
Example #9
0
        static void Main(string[] args)
        {
            Dice d1 = new Dice();
            Dice d2 = new Dice();
            Dice d3 = new Dice();

            Player p = new Player("Fred", 100);
            Console.WriteLine(p);
            Console.WriteLine();

            Console.WriteLine("New game for {0}", p.Name);
            Game g = new Game(d1, d2, d3);
            IList<DiceValue> cdv = g.CurrentDiceValues;
            Console.WriteLine("Current dice values : {0} {1} {2}", cdv[0], cdv[1], cdv[2]);

            DiceValue rv = Dice.RandomValue;

            Random random = new Random();
            int bet = 5;
            p.Limit = 0;
            int winnings = 0;
            DiceValue pick = Dice.RandomValue;

            int totalWins = 0;
            int totalLosses = 0;

            while (true)
            {
                int winCount = 0;
                int loseCount = 0;
                for (int i = 0; i < 100; i++)
                {
                    p = new Player("Fred", 100);
                    Console.Write("Start Game {0}: ", i);
                    Console.WriteLine("{0} starts with balance {1}", p.Name, p.Balance);
                    int turn = 0;
                    while (p.balanceExceedsLimitBy(bet) && p.Balance < 200)
                    {
                        //Console.Write("Turn {0}: ", turn+1);
                        //Console.WriteLine("Player {0} betting {1} on {2}. Balance:{3}, Limit:{4}",
                        //                   p.Name, bet, Dice.stringRepr(pick), p.Balance, p.Limit);

                        try
                        {
                            p.placeBet(bet);
                            winnings = g.playRound(bet, pick);
                            cdv = g.CurrentDiceValues;

                            //Console.WriteLine("Rolled {0} {1} {2}", cdv[0], cdv[1], cdv[2]);
                            if (winnings > 0)
                            {
                                p.receiveWinnings(winnings);
                                //Console.WriteLine("{0} won {1}", p.Name, winnings);
                            }
                            else
                            {
                                //Console.WriteLine("{0} lost {1}", p.Name, bet);
                            }
                        }
                        catch (BelowLimitException e)
                        {
                            Console.WriteLine("Error: {0}", e.Message);
                            throw new Exception("Really don't expect to see this");
                        }
                        catch (ArgumentException e)
                        {
                            Console.WriteLine("{0}\n\n", e.Message);
                        }
                        pick = Dice.RandomValue;
                        winnings = 0;
                        turn++;
                    } //while

                    if (p.Balance >= 200) winCount++;
                    else loseCount++;
                    Console.Write("{1} turns later.\nEnd Game {0}: ", i, turn);
                    Console.WriteLine("{0} now has balance {1}\n", p.Name, p.Balance);
                } //for
                Console.WriteLine("Win count = {0}, Lose Count = {1}", winCount, loseCount);
                totalWins += winCount;
                totalLosses += loseCount;

                string ans = Console.ReadLine();
                if (ans.Equals("q")) break;
            } //while true
            Console.WriteLine("Overall loss rate = {0}%", (float)(totalLosses * 100) / (totalWins + totalLosses));
            Console.ReadLine();
        }
Example #10
0
        static void Main(string[] args)
        {
            // Create Dice.
            IDice d1 = new Dice();
            IDice d2 = new Dice();
            IDice d3 = new Dice();

            // Create player.
            IPlayer p = new Player("Fred", 100);
            Console.WriteLine(p);
            Console.WriteLine();

            // Create Game.
            Console.WriteLine("New game for {0}", p.Name);
            Game g = new Game(d1, d2, d3);

            // Initial dice values? Why does this matter?
            IList<DiceValue> cdv = g.CurrentDiceValues;
            Console.WriteLine("Current dice values : {0} {1} {2}", cdv[0], cdv[1], cdv[2]);

            // Unused random dice value? Why is this done?
            DiceValue rv = Dice.RandomValue;

            // Unused random
            Random random = new Random();

            // Setup initial conditions.
            int bet = 5;
            p.Limit = 0;
            int winnings = 0;
            DiceValue pick = Dice.RandomValue;
            Console.WriteLine("Chosen Dice Value:" + pick);

            int totalWins = 0;
            int totalLosses = 0;

            while (true)
            {
                int winCount = 0;
                int loseCount = 0;

                // Play 100 times
                for (int i = 0; i < 100; i++)
                {
                    // Re-creating player with the same balance each time.
                    p = new Player("Fred", 100);
                    Console.Write("Start Game {0}: ", i);
                    Console.WriteLine("{0} starts with balance {1}", p.Name, p.Balance);
                    int turn = 0;

                    // Balance lower limit 0 upper limit 200.
                    while (p.balanceExceedsLimitBy(bet) && p.Balance < 200)
                    {
                        try
                        {
                            winnings = g.PlayRound(p, pick, bet);
                            cdv = g.CurrentDiceValues;

                            Console.WriteLine("Picked {3} and Rolled {0} {1} {2}", cdv[0], cdv[1], cdv[2], pick);
                            if (winnings > 0)
                            {
                                Console.WriteLine("{0} bet {3} and won {1} balance now {2}", p.Name, winnings, p.Balance, bet);
                                winCount++;
                            }
                            else
                            {
                                Console.WriteLine("{0} bet {3} and lost {1} balance now {2}", p.Name, bet, p.Balance, bet);
                                loseCount++;
                            }
                        }
                        catch (ArgumentException e)
                        {
                            Console.WriteLine("{0}\n\n", e.Message);
                        }
                        pick = Dice.RandomValue;
                        winnings = 0;
                        turn++;
                    } //while

                    Console.Write("{1} turns later.\nEnd Game {0}: ", turn, i);
                    Console.WriteLine("{0} now has balance {1}\n", p.Name, p.Balance);
                } //for

                Console.WriteLine("Win count = {0}, Lose Count = {1}, {2:0.00}", winCount, loseCount, (float)winCount / (winCount + loseCount));
                totalWins += winCount;
                totalLosses += loseCount;

                string ans = Console.ReadLine();
                if (ans.Equals("q")) break;
            } //while true
            Console.WriteLine("Overall win rate = {0}%", (float)(totalWins * 100) / (totalWins + totalLosses));
            Console.ReadLine();
        }
Example #11
0
        static void Main(string[] args)
        {
            Dice d1 = new Dice();
            Dice d2 = new Dice();
            Dice d3 = new Dice();

            Player p = new Player("Fred", 100);
            Console.WriteLine(p);
            Console.WriteLine();

            Console.WriteLine("New game for {0}", p.Name);
            Game g = new Game(d1, d2, d3);
            IList<DiceValue> cdv = g.CurrentDiceValues;
            Console.WriteLine("Current dice values : {0} {1} {2}", cdv[0], cdv[1], cdv[2]);

            DiceValue rv = Dice.RandomValue;

            Random random = new Random();
            int bet = 5;
            p.Limit = 0;
            int winnings = 0;
            DiceValue pick = Dice.RandomValue;

            int totalWins = 0;
            int totalLosses = 0;

            while (true)
            {
                int winCount = 0;
                int loseCount = 0;
                for (int i = 0; i < 100; i++)
                {
                    p = new Player("Fred", 100);
                    Console.Write("Start Game {0}: ", i);
                    Console.WriteLine("{0} starts with balance {1}", p.Name, p.Balance);
                    int turn = 0;
                    while (p.balanceExceedsLimitBy(bet) && p.Balance < 200)
                    {
                        try
                        {
                            winnings = g.playRound(p, pick, bet);
                            cdv = g.CurrentDiceValues;

                            Console.WriteLine("Rolled {0} {1} {2}", cdv[0], cdv[1], cdv[2]);
                            if (winnings > 0)
                            {
                                Console.WriteLine("{0} won {1} balance now {2}", p.Name, winnings, p.Balance);
                                winCount++;
                            }
                            else
                            {
                                Console.WriteLine("{0} lost {1} balance now {2}", p.Name, bet, p.Balance);
                                loseCount++;
                            }
                        }
                        catch (ArgumentException e)
                        {
                            Console.WriteLine("{0}\n\n", e.Message);
                        }
                        pick = Dice.RandomValue;
                        winnings = 0;
                        turn++;
                    } //while

                    Console.Write("{1} turns later.\nEnd Game {0}: ", turn, i);
                    Console.WriteLine("{0} now has balance {1}\n", p.Name, p.Balance);
                } //for

                Console.WriteLine("Win count = {0}, Lose Count = {1}, {2:0.00}", winCount, loseCount, (float) winCount/(winCount+loseCount));
                totalWins += winCount;
                totalLosses += loseCount;

                string ans = Console.ReadLine();
                if (ans.Equals("q")) break;
            } //while true
            Console.WriteLine("Overall win rate = {0}%", (float)(totalWins * 100) / (totalWins + totalLosses));
            Console.ReadLine();
        }