This commit is contained in:
@@ -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 (doku.isSolved()) {
|
if (!cell.isMutable() || !cell.isEmpty())
|
||||||
return true;
|
continue;
|
||||||
}
|
|
||||||
|
List<Integer> possibleSymbols = cell.getPossibleSymbols();
|
||||||
List<Cell> cellsToFill = doku.getEmptyCells();
|
if (possibleSymbols.size() == 1) {
|
||||||
if (cellsToFill.isEmpty()) {
|
cell.setSymbolIndex(possibleSymbols.getFirst());
|
||||||
return false;
|
addStep(cell, steps);
|
||||||
}
|
filledCell = true;
|
||||||
|
}
|
||||||
for (Cell cellToFill : cellsToFill) {
|
|
||||||
|
|
||||||
List<Integer> possibleSymbols = cellToFill.getPossibleSymbols();
|
|
||||||
if (possibleSymbols.size() != 1) {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
// on ne peut plus remplir de cases, on abandonne
|
||||||
cellToFill.setSymbolIndex(possibleSymbols.getFirst());
|
if (!filledCell)
|
||||||
addStep(cellToFill, steps);
|
return false;
|
||||||
|
|
||||||
return this.solve(doku, steps);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return doku.isSolved();
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user