Exemplo n.º 1
0
        // Main method to get user input and choose to run the test or the custom program
        static void Main(string[] args)
        {
            // Variables to store user input
            string allInput;
            char   input = '?';

            // Do while the user stated that they wanted to rerun the program
            do
            {
                // Method call to get user input
                GetUserInput();

                // If the program is in test mode, run the test
                if (testMode)
                {
                    RunTest();
                }
                // Else run the custom program
                else
                {
                    // Begin hill climbing based on the inputted boolean variables
                    HillClimbing.RunHillClimbing(doesRestart, movesSideways, boardSize);
                }

                // Do while the user did not input Y or N
                do
                {
                    // Get user input to run the program again
                    Logger.WriteLine("\nWould you like to run the program again? (Y/N)");
                    allInput = Console.ReadLine();

                    // If the user inputted a string with at least one character
                    if (allInput.Length > 0)
                    {
                        // Set the input equal to the first character
                        input = allInput.ToUpper()[0];
                        Logger.WriteLine(input, false);
                    }
                }while(input != 'Y' && input != 'N');
            }while(input == 'Y');

            // Output the data to the CSV file
            Logger.OutputToFile();

            Console.WriteLine("\nPress enter to exit...");
            Console.ReadLine();
        }
Exemplo n.º 2
0
        // Method to run the test and log the results to an CSV file
        static void RunTest()
        {
            Logger.WriteLine("Running tests....this might take a while...");

            // List of the results for the hill climbing runs
            var results = new List <HillClimbingResult>();

            // Run hill climbing without restarting or sideways moves 500 times
            Logger.WriteLine("Recording default Hill Climbing with 8 Queens statistics...");
            for (int i = 0; i < 500; i++)
            {
                results.Add(HillClimbing.RunHillClimbing(false, false, 8, false));
            }

            // Run hill climbing with sideways moves 500 times
            Logger.WriteLine("Recording sideways moves Hill Climbing with 8 Queens statistics...");
            for (int i = 0; i < 500; i++)
            {
                results.Add(HillClimbing.RunHillClimbing(false, true, 8, false));
            }

            // Run hill climbing with random restart 500 times
            Logger.WriteLine("Recording random restart without sideways moves Hill Climbing with 8 Queens statistics...");
            for (int i = 0; i < 500; i++)
            {
                results.Add(HillClimbing.RunHillClimbing(true, false, 8, false));
            }

            // Run hill climbing with random restart and sideways moves 500 times
            Logger.WriteLine("Recording random restart with sideways moves Hill Climbing with 8 Queens statistics...");
            for (int i = 0; i < 500; i++)
            {
                results.Add(HillClimbing.RunHillClimbing(true, true, 8, false));
            }

            // Write the results to a CSV file
            using (var writer = new StreamWriter($"output/results_{DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond}.csv"))
                using (var csv = new CsvWriter(writer))
                {
                    csv.WriteRecords <HillClimbingResult>(results);
                }

            Logger.WriteLine("All test results recorded in output directory");
        }