fix : countSolutions
All checks were successful
Linux arm64 / Build (push) Successful in 36s

This commit is contained in:
Melvyn
2025-02-01 23:39:04 +01:00
parent 14d0521215
commit 129c3ef0b2
2 changed files with 12 additions and 15 deletions

View File

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

View File

@@ -142,21 +142,14 @@ public class SudokuFactory {
List<Cell> cellsThatCanBeEmptied = doku.getFilledCells();
while (!cellsThatCanBeEmptied.isEmpty()) {
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);
return newDokuFromFilledOne(doku, --nbCellsToEmpty, solver);
}
return false;