コード例 #1
0
        public static void benchmark(String fileName)
        {
            float[]  scores = new float[solvers.Count];
            String[] lines  = sudoku.getFile(fileName);

            for (int i = 0; i < solvers.Count; i++)
            {
                Console.WriteLine("        Test " + solvers[i].Name);
                for (int j = 0; j < lines.Length; j++)
                {
                    float score = testSolution(solvers[i], lines[j]);
                    if (score == -1)
                    {
                        scores[i] = -1;
                        Console.WriteLine("        " + fileName + " " + j + " failed validation");
                        break;
                    }
                    scores[i] += score;
                    Console.WriteLine("        " + fileName + " " + j + " success in : " + score + "ms");
                }
            }

            Console.WriteLine("\n        /*--------------------Résultat du Benchmark--------------------*/\n");
            Console.WriteLine("        " + lines.Length + " sodokus : " + fileName + "\n");
            for (int i = 0; i < solvers.Count; i++)
            {
                if (scores[i] == -1)
                {
                    Console.WriteLine("        " + solvers[i].Name + " : Non validé\n");
                }
                else
                {
                    Console.WriteLine("        " + solvers[i].Name + " : Validé en " + scores[i] + "ms  (" + (scores[i] / lines.Length) + " ms/sodoku)\n");
                }
            }
            Console.WriteLine("\n        /*--------------------FIN Résultat du Benchmark--------------------*/\n");
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: NizarECE/SudokuIA2
        static void Main(string[] args)
        {
            sudoku = new Sudoku();
            refreshSolver();

            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) + ". Remove Solver");
                Console.WriteLine("                " + (solvers.Count + 5) + ". Refresh Solver");
                Console.WriteLine("                " + (solvers.Count + 6) + ". Quitter");

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

                int choix;
                try
                {
                    choix = int.Parse(Console.ReadLine());
                }
                catch (Exception e)
                {
                    choix = -1;
                    Console.WriteLine("\n\n                Saisie invalide\n\n");
                }

                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)
                {
                    showScore(benchmark(sudoku.getFile("Sudoku_Easy50.txt")), 50, "Easy");
                }
                else if (choix == solvers.Count + 1)
                {
                    showScore(benchmark(sudoku.getFile("Sudoku_hardest.txt")), 11, "Hardest");
                }
                else if (choix == solvers.Count + 2)
                {
                    showScore(benchmark(sudoku.getFile("Sudoku_Top95.txt")), 95, "Top 95");
                }
                else if (choix == solvers.Count + 3)
                {
                    List <Dictionary <String, float> > scores = new List <Dictionary <string, float> >();

                    benchmark(customSudoku(30));
                    for (int i = 30; i >= 17; i--)
                    {
                        scores.Add(benchmark(customSudoku(i)));
                        foreach (KeyValuePair <String, float> score in scores[-i + 30])
                        {
                            if (score.Value > 5000 || score.Value < 0)
                            {
                                for (int j = 0; j < solvers.Count; j++)
                                {
                                    if (solvers[j].Name == score.Key)
                                    {
                                        solvers.RemoveAt(j);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    refreshSolver();
                    Console.WriteLine("\n        /*--------------------Résultat du Benchmark // Custom--------------------*/\n");
                    for (int i = 30; i >= 17; i--)
                    {
                        showCustomScore(scores[-i + 30], 10, "" + i);
                    }
                    Console.WriteLine("\n        /*--------------------FIN Résultat du Benchmark--------------------*/\n");
                }
                else if (choix == solvers.Count + 4)
                {
                    try
                    {
                        Console.WriteLine("\n        Quel Solver voulez vous supprimer ?\n");
                        int suppr = int.Parse(Console.ReadLine());
                        if (suppr >= 0 && suppr < solvers.Count)
                        {
                            solvers.RemoveAt(suppr);
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("\n\n                Saisie invalide\n\n");
                    }
                }
                else if (choix == solvers.Count + 5)
                {
                    refreshSolver();
                }
                else if (choix == solvers.Count + 6)
                {
                    Quitter = true;
                }
            } while (!Quitter);

            Console.WriteLine("\n\n\n        FIIIIIN");
            Console.ForegroundColor = ConsoleColor.Yellow;
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: mathildeLorrain/SudokuIA2
        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;
        }