Error checking inputs and reverting if illegal

This commit is contained in:
Imbus 2023-12-11 15:53:22 +01:00
parent 26df774ca3
commit 5bf0c92d10

View file

@ -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());
}
}