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