aaaaaaaaaaaaaaaaaaaaaaaaaaaa
All checks were successful
Linux arm64 / Build (push) Successful in 32s

This commit is contained in:
2025-02-02 20:17:54 +01:00
parent 9c72891048
commit b68fe81914

View File

@@ -45,6 +45,9 @@ public class MixedSolver implements Solver {
throw new CancellationException("User wants to stop the solver"); throw new CancellationException("User wants to stop the solver");
} }
if (doku.isSolved())
return true;
int symbolCount = doku.getSubGrid(0).getSize(); int symbolCount = doku.getSubGrid(0).getSize();
// on remplit les cases par déduction // on remplit les cases par déduction
@@ -56,12 +59,12 @@ public class MixedSolver implements Solver {
if (possibleSymbols.size() == 1) { if (possibleSymbols.size() == 1) {
cell.setSymbolIndex(possibleSymbols.getFirst()); cell.setSymbolIndex(possibleSymbols.getFirst());
addStep(cell, steps); addStep(cell, steps);
if (solve(doku, steps))
return true;
cell.setSymbolIndex(Cell.NOSYMBOL);
} }
} }
if (doku.isSolved())
return true;
// on ne peut plus remplir de cases, on tente de backtrack // on ne peut plus remplir de cases, on tente de backtrack
for (int maxPossibilities = 2; maxPossibilities <= symbolCount; maxPossibilities++) { for (int maxPossibilities = 2; maxPossibilities <= symbolCount; maxPossibilities++) {
List<Cell> backtrackCells = new ArrayList<>(); List<Cell> backtrackCells = new ArrayList<>();
@@ -81,15 +84,12 @@ public class MixedSolver implements Solver {
// on tente de placer chacun des symboles // on tente de placer chacun des symboles
for (int symbol : possibilities) { for (int symbol : possibilities) {
var state = doku.getStateManager().pushState();
backtrackCell.setSymbolIndex(symbol); backtrackCell.setSymbolIndex(symbol);
if (solve(doku, steps)) { if (solve(doku, steps)) {
// doku.getStateManager().forgetState();
return true; return true;
} }
doku.getStateManager().popState();
doku.getStateManager().restoreState(state);
} }
backtrackCell.setSymbolIndex(Cell.NOSYMBOL);
} }
} }
return doku.isSolved(); return doku.isSolved();