/** * Saves board to the text file. * * @param filePath Path to the file. * @param headComment Comment to be added at the head. * @param tailComment Comment to be added at the tail. * @return True if saving was successful, otherwise false. * * @see SudokuStore#saveBoard(int[,], String, String, String) * @see SudokuStore#boardToString(int[,], String, String) */ public bool saveBoard(String filePath, String headComment, String tailComment) { bool savingStatus = SudokuStore.saveBoard(sudokuBoard, filePath, headComment, tailComment); if (savingStatus == true) { addMessage("(saveBoard) Saving successful, file: " + filePath, MSG_INFO); } else { addMessage("(saveBoard) Saving failed, file: " + filePath, MSG_ERROR); } return(savingStatus); }
/* * ======================================== * Save Menu * ======================================== */ /** * Saves current puzzle in the txt file. * * @see SudokuStore#saveBoard(int[,], String) */ private void savePuzzle() { JanetConsole.print("File path: "); String filePath = JanetConsole.readLine(); FileInfo file = new FileInfo(filePath); DirectoryInfo dir = new DirectoryInfo(filePath); if ((file.Exists == true) || (dir.Exists == true)) { JanetConsole.println(">>> !!! Error - file already exists !!! <<<"); return; } bool puzzleSaved = SudokuStore.saveBoard(puzzle, filePath); if (puzzleSaved == false) { JanetConsole.println(">>> !!! Error while saving !!! <<<"); } }
/** * 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 :-) */ }