Compare commits
2 commits
26df774ca3
...
ffd1d4bd51
Author | SHA1 | Date | |
---|---|---|---|
![]() |
ffd1d4bd51 | ||
![]() |
5bf0c92d10 |
2 changed files with 11 additions and 1 deletions
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,8 @@ class SolverTest {
|
|||
assertTrue(solver.isLegal(0, 0, 1));
|
||||
solver.set(0, 0, 1);
|
||||
|
||||
IntStream.range(0, 9).forEach(i -> {
|
||||
// Start from one, since setting the same value is legal
|
||||
IntStream.range(1, 9).forEach(i -> {
|
||||
assertFalse(solver.isLegal(0, i, 1));
|
||||
assertFalse(solver.isLegal(i, 0, 1));
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue