refactor HumanSolver
All checks were successful
Linux arm64 / Build (push) Successful in 39s

This commit is contained in:
2025-02-02 14:36:47 +01:00
parent 413201882b
commit 87727f39e8

View File

@@ -16,32 +16,25 @@ public class HumanSolver implements Solver {
*/ */
@Override @Override
public boolean solve(MultiDoku doku, List<SolverStep> steps) { public boolean solve(MultiDoku doku, List<SolverStep> steps) {
if (Thread.interrupted()) while (!doku.isSolved()) {
throw new CancellationException("User wants to stop the solver"); boolean filledCell = false;
for (Cell cell : doku.getCells()) {
if (!cell.isMutable() || !cell.isEmpty())
continue;
if (doku.isSolved()) { List<Integer> possibleSymbols = cell.getPossibleSymbols();
return true; if (possibleSymbols.size() == 1) {
cell.setSymbolIndex(possibleSymbols.getFirst());
addStep(cell, steps);
filledCell = true;
} }
}
List<Cell> cellsToFill = doku.getEmptyCells(); // on ne peut plus remplir de cases, on abandonne
if (cellsToFill.isEmpty()) { if (!filledCell)
return false; return false;
} }
for (Cell cellToFill : cellsToFill) { return true;
List<Integer> possibleSymbols = cellToFill.getPossibleSymbols();
if (possibleSymbols.size() != 1) {
continue;
}
cellToFill.setSymbolIndex(possibleSymbols.getFirst());
addStep(cellToFill, steps);
return this.solve(doku, steps);
}
return doku.isSolved();
} }
} }