From 5bf0c92d102e4c3ff8297e56f81ed09b381e5449 Mon Sep 17 00:00:00 2001 From: Imbus Date: Mon, 11 Dec 2023 15:53:22 +0100 Subject: [PATCH] Error checking inputs and reverting if illegal --- app/src/main/java/gui/SudokuController.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/src/main/java/gui/SudokuController.java b/app/src/main/java/gui/SudokuController.java index a283ab8..0d91eed 100644 --- a/app/src/main/java/gui/SudokuController.java +++ b/app/src/main/java/gui/SudokuController.java @@ -127,6 +127,15 @@ public class SudokuController { // Update the model and view model.set(row, col, value); + + // Warn if the board is not solvable (e.g. if the user has made a mistake) + // This is very messy, error prone and computationally expensive + if(!model.isSolvable()) { + model.set(row, col, 0); + view.showErrorMessage("Illegal move. The board is not solvable."); + } + + // Sync the view with the model view.updateView(model.getBoard()); } }