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

View File

@@ -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;
@@ -243,7 +236,7 @@ public class SudokuFactory {
/* /*
* 2 3 * 2 3
* 1 * 1
* 4 5 * 4 5
*/ */
@@ -276,7 +269,7 @@ public class SudokuFactory {
/* /*
* 2 3 * 2 3
* 1 * 1
* 4 5 * 4 5
*/ */