Beispiel #1
0
        public static String[] customSudoku(int dificulty)
        {
            int nb = 10;

            String[] lines = new String[nb];
            for (int i = 0; i < nb; i++)
            {
                lines[i] = sudoku.create(dificulty);
            }

            return(lines);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            sudoku = new Sudoku();

            solvers = new List <ISudokuSolver>();
            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                foreach (var objType in assembly.GetTypes())
                {
                    if (typeof(ISudokuSolver).IsAssignableFrom(objType) && !(typeof(ISudokuSolver) == objType))
                    {
                        solvers.Add((ISudokuSolver)Activator.CreateInstance(objType));
                    }
                }
            }

            bool Quitter = false;

            do
            {
                Console.WriteLine("\n\n\n                Résolution de Sudoku\n");

                for (int i = 0; i < solvers.Count; i++)
                {
                    Console.WriteLine("                " + i + ". " + solvers[i].Name);
                }

                Console.WriteLine("                " + (solvers.Count) + ". Benchmark Easy");
                Console.WriteLine("                " + (solvers.Count + 1) + ". Benchmark Hardest");
                Console.WriteLine("                " + (solvers.Count + 2) + ". Benchmark Top 95");
                Console.WriteLine("                " + (solvers.Count + 3) + ". Benchmark Custom");
                Console.WriteLine("                " + (solvers.Count + 4) + ". Quitter");

                Console.WriteLine("\n                Que voulez vous faire ?");

                int choix = int.Parse(Console.ReadLine());

                var watch = Stopwatch.StartNew();
                watch.Stop();
                float elapsedMs;

                if (choix >= 0 && choix < solvers.Count)
                {
                    Console.WriteLine("\n        /*--------------------" + solvers[choix].Name + "--------------------*/\n");
                    watch = Stopwatch.StartNew();
                    solvers[choix].Solve();
                    watch.Stop();
                    elapsedMs = watch.ElapsedMilliseconds;
                    Console.WriteLine("\n\n                SOLVED IN : " + elapsedMs + " ms\n\n");
                    if (solvers[choix].Sudoku.validationSudoku())
                    {
                        Console.WriteLine("        !!! FELICITATION !!! : Ce sudoku est validé");
                    }
                    solvers[choix].Sudoku.showTwoSudoku();
                    Console.WriteLine("\n        /*--------------------FIN " + solvers[choix].Name + "--------------------*/\n");
                }
                else if (choix == solvers.Count)
                {
                    benchmark(sudoku.getFile("Sudoku_Easy50.txt"));
                }
                else if (choix == solvers.Count + 1)
                {
                    benchmark(sudoku.getFile("Sudoku_hardest.txt"));
                }
                else if (choix == solvers.Count + 2)
                {
                    benchmark(sudoku.getFile("Sudoku_Top95.txt"));
                }
                else if (choix == solvers.Count + 3)
                {
                    int      nb    = 10;
                    String[] lines = new String[nb];
                    for (int i = 0; i < nb; i++)
                    {
                        lines[i] = sudoku.create(25);
                    }
                    benchmark(lines);
                }
                else if (choix == solvers.Count + 4)
                {
                    Quitter = true;
                }
            } while (!Quitter);

            Console.WriteLine("\n\n\n        FIIIIIN");
            Console.ForegroundColor = ConsoleColor.Yellow;
        }