This commit is contained in:
@@ -42,6 +42,10 @@ public interface Solver {
|
|||||||
cellToFill.setSymbolIndex(symbol);
|
cellToFill.setSymbolIndex(symbol);
|
||||||
if (solve(doku)) {
|
if (solve(doku)) {
|
||||||
result++;
|
result++;
|
||||||
|
if (result > 1) {
|
||||||
|
doku.getStateManager().popState();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
doku.getStateManager().popState();
|
doku.getStateManager().popState();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,21 +142,14 @@ public class SudokuFactory {
|
|||||||
|
|
||||||
List<Cell> cellsThatCanBeEmptied = doku.getFilledCells();
|
List<Cell> cellsThatCanBeEmptied = doku.getFilledCells();
|
||||||
|
|
||||||
while (!cellsThatCanBeEmptied.isEmpty()) {
|
|
||||||
int index = random.nextInt(cellsThatCanBeEmptied.size());
|
int index = random.nextInt(cellsThatCanBeEmptied.size());
|
||||||
Cell cellToEmpty = cellsThatCanBeEmptied.get(index);
|
Cell cellToEmpty = cellsThatCanBeEmptied.get(index);
|
||||||
|
|
||||||
int oldSymbol = cellToEmpty.empty();
|
cellToEmpty.empty();
|
||||||
|
|
||||||
int nbDokuSultions = solver.countSolution(doku);
|
int nbDokuSultions = solver.countSolution(doku);
|
||||||
if (nbDokuSultions == 1) {
|
if (nbDokuSultions == 1) {
|
||||||
if (newDokuFromFilledOne(doku, --nbCellsToEmpty, solver)) {
|
return newDokuFromFilledOne(doku, --nbCellsToEmpty, solver);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cellToEmpty.setSymbolIndex(oldSymbol);
|
|
||||||
cellsThatCanBeEmptied.remove(cellToEmpty);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user