Beispiel #1
0
        private static void Main(string[] args)
        {
            Console.WriteLine("Number of simulations: ");

            var noOfSimulations = int.Parse(Console.ReadLine());


            /* An instance of a game-session(simulation) needs:
             *    1. Number of simulations.
             *    2. Two players: One contestant, and one host.
             */

            // Simulation 1: With swap.
            var simulationSwap = new MontyHallGame(noOfSimulations, new Contestant(true), new Host(false));

            simulationSwap.RunGameSimulation();
            PrintResults(simulationSwap);

            // Simulation 2: With swap and random host.
            var simulationSwapRandom = new MontyHallGame(noOfSimulations, new Contestant(true), new Host(true));

            simulationSwapRandom.RunGameSimulation();
            PrintResults(simulationSwapRandom);

            // Simulation 3: Without swap, type of host doesn't matter for this simulation since contestant keeps first choice.
            var simulationNoSwap = new MontyHallGame(noOfSimulations, new Contestant(false), new Host(false));

            simulationNoSwap.RunGameSimulation();
            PrintResults(simulationNoSwap);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            var mh = new MontyHallGame(2, new RandomDoorSelector());

            Console.WriteLine(mh.hasWon());
        }
Beispiel #3
0
 private static void PrintResults(MontyHallGame montyHallGame)
 {
     Console.WriteLine("With switch: " + montyHallGame.Contestant.SwapBox);
     Console.WriteLine("Random host: " + montyHallGame.Host.RandomReveal);
     Console.WriteLine("Wins total: " + montyHallGame.Contestant.Wins + " / " + montyHallGame.NoOfSimulations);
     Console.WriteLine("Win percentage: " + montyHallGame.Contestant.WinPercentage + "%");
     Console.WriteLine(Environment.NewLine);
 }
Beispiel #4
0
        public static void RunSimulation(int iterations, string whichRun, string policy)
        {
            Dictionary <string, int> gameResults = new Dictionary <string, int>();

            gameResults.Add("Won", 0);
            gameResults.Add("Lost", 0);
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine($"{whichRun} run: Policy = {policy}");
            for (int i = 0; i < iterations; i++)
            {
                var game = new MontyHallGame();
                game.PlayTheGameSimulated();
                if (policy == "Stay")
                {
                    if (game.ChosenDoor.Occupant == OccupantType.Car)
                    {
                        gameResults["Won"] += 1;
                    }
                    else
                    {
                        gameResults["Lost"] += 1;
                    }
                }
                else
                {
                    if (game.ClosedDoor.Occupant == OccupantType.Car)
                    {
                        gameResults["Won"] += 1;
                    }
                    else
                    {
                        gameResults["Lost"] += 1;
                    }
                }
            }
            Console.WriteLine("*********************************************************************");
            Console.WriteLine($"Wins:\t{gameResults["Won"]}\t\tLosses:\t{gameResults["Lost"]}");
            Console.WriteLine($"Win percentage: {((decimal)gameResults["Won"]/iterations)*100}");
            Console.WriteLine("*********************************************************************");
        }
Beispiel #5
0
        private void RunSimulation(int numberOfTimes, bool swap)
        {
            int playerWon  = 0;         // number of times player has won
            int playerLost = 0;         // number of times player has lost

            MontyHallGame game = new MontyHallGame();

            for (int i = 0; i < numberOfTimes; i++)
            {
                if (game.Play(swap))
                {
                    playerWon++;
                }
                else
                {
                    playerLost++;
                }
            }

            Console.WriteLine("Results for {0}switching doors:", swap ? "" : "not ");
            Console.WriteLine("Times won: {0}, times lost: {1}\n", playerWon, playerLost);
        }
Beispiel #6
0
        private void RunSimulation(int numberOfTimes, bool swap)
        {
            int playerWon = 0;          // number of times player has won
            int playerLost = 0;         // number of times player has lost

            MontyHallGame game = new MontyHallGame();

            for(int i = 0; i < numberOfTimes; i++)
            {
                if (game.Play(swap))
                {
                    playerWon++;
                }
                else
                {
                    playerLost++;
                }
            }

            Console.WriteLine("Results for {0}switching doors:", swap ? "" : "not ");
            Console.WriteLine("Times won: {0}, times lost: {1}\n", playerWon, playerLost);
        }