示例#1
0
        //main program, starts here
        static void Main(string[] args)
        {
            bool            win = false;
            bool            continueExecution = true;
            int             numberOfWinnings  = 0;
            simulation      sim = new simulation();
            randomNumberGen rg  = new randomNumberGen();

            //get the consoleInterface, display welcome screen
            consoleInterface ic = consoleInterface.getInterface();

            ic.displayWelcome();

            //conitnue while user wants to
            while (continueExecution == true)
            {
                numberOfWinnings = 0;
                //start simulation of not switching doors
                ic.startWithoutSwitching();

                for (int i = 0; i < 10000; i++)
                {
                    int seed = rg.getNumber(100, i + Environment.TickCount);
                    win = sim.runSimWithoutSwitching(seed);

                    if (win == true)
                    {
                        numberOfWinnings += 1;
                    }
                }

                //calculate ratio which should be around 1/3
                double withoutSwitchingRatio = numberOfWinnings / 10000.0;

                //Displays results and resets numberOfWinnings variable
                ic.resultsWithoutSwitching(numberOfWinnings, withoutSwitchingRatio);
                numberOfWinnings = 0;

                //start simulation with switching
                ic.startWithSiwtching();

                for (int i = 0; i < 10000; i++)
                {
                    int seed = rg.getNumber(100, i + Environment.TickCount);
                    win = sim.runWithSwitching(seed);

                    if (win == true)
                    {
                        numberOfWinnings += 1;
                    }
                }

                //calculate ratio which should be around 2/3
                double withSwitchingRatio = numberOfWinnings / 10000.0;

                //Displays results
                ic.resultsWithSwitching(numberOfWinnings, withSwitchingRatio);
                continueExecution = ic.compareRatio(withoutSwitchingRatio, withSwitchingRatio);
            }
        }
        public static consoleInterface getInterface()
        {
            if (singleton == null)
            {
                singleton = new consoleInterface();
            }

            return(singleton);
        }