/**
         * Rate puzzle difficulty meaning as number of closed routes (number of
         * wrong guesses).
         *
         * @see SudokuStore#calculatePuzzleRating(int[,])
         */
        private void ratePuzzleDifficulty()
        {
            int rating = SudokuStore.calculatePuzzleRating(puzzle);

            if (rating >= 0)
            {
                JanetConsole.println(">>>");
                JanetConsole.println(">>> Puzzle rating: " + rating);
                JanetConsole.println(">>>");
            }
            else
            {
                JanetConsole.println(">>> !!! Error code: " + rating + " !!! <<<");
                JanetConsole.println(">>> " + ErrorCodes.getErrorDescription(rating));
            }
        }
Beispiel #2
0
        /**
         * Start the Janet-Sudoku Tutorial code.
         * @param args    No arguments are considered.
         */
        public static void Start()
        {
            String tmpDir = FileX.getTmpDir();
            {
                /*
                 * Simple sudoku generation.
                 */
                SudokuStore.consolePrintln("");
                SudokuStore.consolePrintln("Simple sudoku generation.");
                SudokuGenerator sg = new SudokuGenerator();
                int[,] puzzle = sg.generate();
                SudokuStore.consolePrintBoard(puzzle);
            }
            {
                /*
                 * Simple sudoku generation + parameters.
                 */
                SudokuStore.consolePrintln("");
                SudokuStore.consolePrintln("Simple sudoku generation + parameters.");
                SudokuGenerator sg = new SudokuGenerator(SudokuGenerator.PARAM_GEN_RND_BOARD);
                int[,] puzzle = sg.generate();
                SudokuStore.consolePrintBoard(puzzle);
            }
            {
                /*
                 * Simple sudoku generation + puzzle rating.
                 */
                SudokuStore.consolePrintln("");
                SudokuStore.consolePrintln("Simple sudoku generation + puzzle rating.");
                SudokuGenerator sg = new SudokuGenerator();
                int[,] puzzle = sg.generate();
                int rating = SudokuStore.calculatePuzzleRating(puzzle);
                SudokuStore.consolePrintBoard(puzzle);
                SudokuStore.consolePrintln("Puzzle rating: " + rating);
            }
            {
                /*
                 * Solving sudoku example.
                 */
                SudokuStore.consolePrintln("");
                SudokuStore.consolePrintln("Solving sudoku example.");
                SudokuSolver ss = new SudokuSolver(SudokuPuzzles.PUZZLE_EXAMPLE_001);
                SudokuStore.consolePrintBoard(ss.getBoard());
                ss.solve();
                SudokuStore.consolePrintBoard(ss.getSolvedBoard());
            }
            {
                /*
                 * Saving board examples
                 */
                SudokuStore.consolePrintln("");
                SudokuStore.consolePrintln("Saving board examples " + tmpDir);
                SudokuStore.saveBoard(SudokuPuzzles.PUZZLE_EXAMPLE_001, tmpDir + "sudoku-board-ex-1.txt");
                SudokuStore.saveBoard(SudokuPuzzles.PUZZLE_EXAMPLE_001, tmpDir + "sudoku-board-ex-2.txt", "This is a head comment");
                SudokuStore.saveBoard(SudokuPuzzles.PUZZLE_EXAMPLE_001, tmpDir + "sudoku-board-ex-3.txt", "This is a head comment", "And a tail comment");
                SudokuSolver ss = new SudokuSolver(1);
                ss.solve();
                ss.saveSolvedBoard(tmpDir + "sudoku-board-ex-sol.txt", "Solution for the PUZZLE_EXAMPLE_001");
            }

            /*
             * And many other staff provided by the library :-)
             */
        }