diff --git a/app/src/main/java/sudoku/solver/Solver.java b/app/src/main/java/sudoku/solver/Solver.java index 6ae2a99..835c03a 100644 --- a/app/src/main/java/sudoku/solver/Solver.java +++ b/app/src/main/java/sudoku/solver/Solver.java @@ -42,6 +42,10 @@ public interface Solver { cellToFill.setSymbolIndex(symbol); if (solve(doku)) { result++; + if (result > 1) { + doku.getStateManager().popState(); + return result; + } } doku.getStateManager().popState(); } diff --git a/app/src/main/java/sudoku/structure/SudokuFactory.java b/app/src/main/java/sudoku/structure/SudokuFactory.java index 33e3a8c..252d374 100644 --- a/app/src/main/java/sudoku/structure/SudokuFactory.java +++ b/app/src/main/java/sudoku/structure/SudokuFactory.java @@ -142,21 +142,14 @@ public class SudokuFactory { List cellsThatCanBeEmptied = doku.getFilledCells(); - while (!cellsThatCanBeEmptied.isEmpty()) { - int index = random.nextInt(cellsThatCanBeEmptied.size()); - Cell cellToEmpty = cellsThatCanBeEmptied.get(index); + int index = random.nextInt(cellsThatCanBeEmptied.size()); + Cell cellToEmpty = cellsThatCanBeEmptied.get(index); - int oldSymbol = cellToEmpty.empty(); + cellToEmpty.empty(); - int nbDokuSultions = solver.countSolution(doku); - if (nbDokuSultions == 1) { - if (newDokuFromFilledOne(doku, --nbCellsToEmpty, solver)) { - return true; - } - } - - cellToEmpty.setSymbolIndex(oldSymbol); - cellsThatCanBeEmptied.remove(cellToEmpty); + int nbDokuSultions = solver.countSolution(doku); + if (nbDokuSultions == 1) { + return newDokuFromFilledOne(doku, --nbCellsToEmpty, solver); } return false; @@ -243,7 +236,7 @@ public class SudokuFactory { /* * 2 3 - * 1 + * 1 * 4 5 */ @@ -276,7 +269,7 @@ public class SudokuFactory { /* * 2 3 - * 1 + * 1 * 4 5 */