diff --git a/Justfile b/Justfile index 6ed91e0..675b9de 100644 --- a/Justfile +++ b/Justfile @@ -11,7 +11,7 @@ clean: fd -td -I build -x rm -r watch: - watchexec -r -c -w app/src "just test && just run" + watchexec -c -w app/src "just test && just run" watchdoc: - watchexec -r -c -w app/src "just doc" + watchexec -c -w app/src "just doc" diff --git a/app/src/main/java/gui/SudokuController.java b/app/src/main/java/gui/SudokuController.java index a283ab8..a95f1a4 100644 --- a/app/src/main/java/gui/SudokuController.java +++ b/app/src/main/java/gui/SudokuController.java @@ -26,13 +26,13 @@ public class SudokuController { public void actionPerformed(ActionEvent e) { // Solve the board boolean solved = model.solve(); - // Update the view - view.updateView(model.getBoard()); if (!solved) { view.showErrorMessage("Could not solve the board."); System.out.println("Could not solve the board."); System.out.println(model.toString()); } else { + // Update the view + view.updateView(model.getBoard()); } } @@ -70,13 +70,6 @@ public class SudokuController { if (newBoard != null) { // Set the model model.setBoard(newBoard); - - // Warn and clear if the board is not solvable - if(!model.isSolvable()) { - view.showErrorMessage("The board is not solvable."); - model.clear(); - } - // Update the view view.updateView(model.getBoard()); } @@ -120,7 +113,7 @@ public class SudokuController { } // If the input is invalid, value < 0 indicates parse error - if (value != 0 && !model.isLegal(row, col, value) || value < 0) { + if (!model.isLegal(row, col, value) || value < 0) { value = 0; view.showErrorMessage("Invalid input. Try again."); } diff --git a/app/src/main/java/sudoku/Solver.java b/app/src/main/java/sudoku/Solver.java index 95a77b3..89d24cf 100644 --- a/app/src/main/java/sudoku/Solver.java +++ b/app/src/main/java/sudoku/Solver.java @@ -29,12 +29,7 @@ public class Solver implements SudokuSolver { /** Resets the board to all zeros */ @Override public void clear() { - for (int[] row : board) { - for (int i = 0; i < row.length; ++i) { - row[i] = 0; - } - } - // board = new int[9][9]; + board = new int[9][9]; } /* {@inheritDoc} */ @@ -149,11 +144,6 @@ public class Solver implements SudokuSolver { return false; } - // Ihe the number is already present in the cell - if (board[row][col] == num) { - return true; - } - // Check both the row and column for (int i = 0; i < 9; i++) { if (board[row][i] == num || board[i][col] == num) {