/** * Solves current puzzle. * * @see SudokuSolver#findAllSolutions() */ private void solveFindAll() { solver = new SudokuSolver(puzzle); setSolverOptions(); int solutionsNumber = solver.findAllSolutions(); JanetConsole.println(">>>>>>>> Solutions found: " + solutionsNumber); if (solutionsNumber > 0) { List <SudokuBoard> solutions = solver.getAllSolutionsList(); for (int i = 0; i < solutionsNumber; i++) { SudokuBoard solution = solutions[i]; JanetConsole.println(">>>>> Solution nr: " + i + "/" + solutionsNumber); JanetConsole.println(">>>>> Path nr: " + solution.pathNumber); JanetConsole.println(">>>>> Computing time: " + solver.getComputingTime() + " s."); SudokuStore.consolePrintBoard(solution.board); JanetConsole.println(">>>>>"); JanetConsole.println(">>>>> Hit enter o to continue (non empty line will cancel)."); String line = JanetConsole.readLine(); if (line.Length > 0) { break; } } } else { JanetConsole.println(solver.getMessages()); } }
/** * 13 rows keyboard input (4 supporting) - 0 or '.' as empty cell. * Any other character is being filtered out. * * @see SudokuStore#loadBoardFromStrings(String...) * @see SudokuStore#loadBoard(String[]) */ private void inputPuzzleFromKeyboard13rows() { JanetConsole.println("You will be asked for inputting 13 rows (4 supporting)."); JanetConsole.print("Row 1/13: "); String r1 = JanetConsole.readLine(); JanetConsole.print("Row 2/13: "); String r2 = JanetConsole.readLine(); JanetConsole.print("Row 3/13: "); String r3 = JanetConsole.readLine(); JanetConsole.print("Row 4/13: "); String r4 = JanetConsole.readLine(); JanetConsole.print("Row 5/13: "); String r5 = JanetConsole.readLine(); JanetConsole.print("Row 6/13: "); String r6 = JanetConsole.readLine(); JanetConsole.print("Row 7/13: "); String r7 = JanetConsole.readLine(); JanetConsole.print("Row 8/13: "); String r8 = JanetConsole.readLine(); JanetConsole.print("Row 9/13: "); String r9 = JanetConsole.readLine(); JanetConsole.print("Row 10/13: "); String r10 = JanetConsole.readLine(); JanetConsole.print("Row 11/13: "); String r11 = JanetConsole.readLine(); JanetConsole.print("Row 12/13: "); String r12 = JanetConsole.readLine(); JanetConsole.print("Row 13/13: "); String r13 = JanetConsole.readLine(); int[,] parsedPuzzle = SudokuStore.loadBoardFromStrings(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13); if (parsedPuzzle != null) { trackPuzzleUndo(); puzzle = parsedPuzzle; } else { JanetConsole.println(">>> !!! Error - incorrect puzzle definition !!! <<<"); } }
/** * Load puzzle from file. * @see SudokuStore#loadBoard(String) */ private void loadFromFile() { JanetConsole.print("File path: "); String filePath = JanetConsole.readLine(); FileInfo file = new FileInfo(filePath); if (file.Exists == false) { JanetConsole.println(">>> !!! Error - file does not exist !!! <<<"); return; } DirectoryInfo dir = new DirectoryInfo(filePath); if (dir.Exists == true) { JanetConsole.println(">>> !!! Error - not a file !!! <<<"); return; } int[,] puzzleLoaded = SudokuStore.loadBoard(filePath); if (puzzleLoaded == null) { JanetConsole.println(">>> !!! Error - incorrect file content !!! <<<"); return; } trackPuzzleUndo(); puzzle = puzzleLoaded; }
/** * One line keyboard input (81 characters) * 0 or '.' as empty cell. * * @see SudokuStore#loadBoardFromStringLine(String) */ private void inputPuzzleFromKeyboard1Line() { JanetConsole.print("One line definition: "); String line = JanetConsole.readLine(); int[,] parsedPuzzle = SudokuStore.loadBoardFromStringLine(line); if (parsedPuzzle != null) { trackPuzzleUndo(); puzzle = parsedPuzzle; } else { JanetConsole.println(">>> !!! Error - incorrect puzzle definition !!! <<<"); } }
/* * ======================================== * 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 !!! <<<"); } }
/** * 9 rows keyboard input - 0 or '.' as empty cell. * Any other character is being filtered out. * * @see SudokuStore#loadBoardFromStrings(String...) * @see SudokuStore#loadBoard(String[]) */ private void inputPuzzleFromKeyboard9rows() { JanetConsole.println("You will be asked for inputting 9 rows."); JanetConsole.print("Row 1/9: "); String r1 = JanetConsole.readLine(); JanetConsole.print("Row 2/9: "); String r2 = JanetConsole.readLine(); JanetConsole.print("Row 3/9: "); String r3 = JanetConsole.readLine(); JanetConsole.print("Row 4/9: "); String r4 = JanetConsole.readLine(); JanetConsole.print("Row 5/9: "); String r5 = JanetConsole.readLine(); JanetConsole.print("Row 6/9: "); String r6 = JanetConsole.readLine(); JanetConsole.print("Row 7/9: "); String r7 = JanetConsole.readLine(); JanetConsole.print("Row 8/9: "); String r8 = JanetConsole.readLine(); JanetConsole.print("Row 9/9: "); String r9 = JanetConsole.readLine(); int[,] parsedPuzzle = SudokuStore.loadBoardFromStrings(r1, r2, r3, r4, r5, r6, r7, r8, r9); if (parsedPuzzle != null) { trackPuzzleUndo(); puzzle = parsedPuzzle; } else { JanetConsole.println(">>> !!! Error - incorrect puzzle definition !!! <<<"); } }