private static void TrySolve(Definition.Sudoku playingSudoku, bool showGUI)
        {
            SudokuConsole.Print(playingSudoku);

            Console.WriteLine();

            //show sudoku with GUI
            if (showGUI)
            {
                playerGUIController = new GUI.SudokuPlayerController(null, playingSudoku);
            }

            bool     solved;
            TimeSpan interval;

            using (var solver = new Core.SudokuSolver(playingSudoku))
            {
                DateTime beforeNow = DateTime.Now;
                solved   = solver.TrySolve();
                interval = DateTime.Now - beforeNow;
            }

            string resultInfo = solved ?
                                "Solved" :
                                "Cannot solve this sudoku with current knowledge";

            Console.WriteLine("{0} in {1:0} ms", resultInfo, interval.TotalMilliseconds);

            if (!solved)
            {
                Console.WriteLine("{0} seats remainder",
                                  new SudokuElementEnumerable(playingSudoku).SeatCount());
            }

            bool reallySolved = solved && playingSudoku.Validate();

            if (!reallySolved)
            {
                if (solved)
                {
                    Console.WriteLine("じゃないよ!");
                }
            }
            SudokuConsole.Print(playingSudoku);

            Console.WriteLine();

            if (showGUI)
            {
                playerGUIController.Show();
            }
        }
示例#2
0
        private static void BuildSudokuAndTrySolve(Core.SudokuBuilder builder, int level, bool showGUI)
        {
            var originSudoku = builder.Source;

            //create a Soduku to play from completed Sudoku with difficult level
            var playingSudoku = builder.Build(new Core.DifficultLevel(level));             //last: 35

            SudokuConsole.Print(playingSudoku);

            Console.WriteLine();

            //show sudoku with GUI
            var playerGUIController = SudokuBuildAndResolve.playerGUIController;

            if (showGUI)
            {
                if (playerGUIController != null)
                {
                    playerGUIController.Close();
                }
                playerGUIController = new GUI.SudokuPlayerController(originSudoku, playingSudoku);
                SudokuBuildAndResolve.playerGUIController = playerGUIController;
            }

            bool     solved;
            TimeSpan interval;

            using (var solver = new Core.SudokuSolver(playingSudoku))
            {
                DateTime beforeNow = DateTime.Now;
                solved   = solver.TrySolve();
                interval = DateTime.Now - beforeNow;
            }

            string resultInfo = solved ?
                                "Solved" :
                                "Cannot solve this sudoku with current knowledge";

            Console.WriteLine("{0} in {1:0} ms", resultInfo, interval.TotalMilliseconds);

            if (!solved)
            {
                Console.WriteLine("{0} seats remainder",
                                  new SudokuElementEnumerable(playingSudoku).SeatCount());
            }

            bool reallySolved = solved && playingSudoku.Validate();

            if (!reallySolved)
            {
                if (solved)
                {
                    Console.WriteLine("じゃないよ!");
                }
                SudokuConsole.Print(playingSudoku);
            }
            else
            {
                if (!originSudoku.ValueEquals(playingSudoku))
                {
                    Console.WriteLine("in a different way");
                }
            }

            Console.WriteLine();

            if (showGUI)
            {
                playerGUIController.Show();
            }
        }