feat : humanSolve
All checks were successful
Linux arm64 / Build (push) Successful in 50s

This commit is contained in:
Melvyn
2025-01-29 09:55:14 +01:00
parent c7217894b2
commit cd45d1c22c
4 changed files with 53 additions and 3 deletions

View File

@@ -95,7 +95,7 @@ public class Solver {
}
/**
* Résout le MultiDoku passé en paramètre.
* Résout le MultiDoku passé en paramètre, avec backtracking.
* @param doku MultiDoku, MultiDoku à résoudre.
* @return boolean, valant true si le MultiDoku est résolu, false sinon.
*/
@@ -129,4 +129,38 @@ public class Solver {
}
return false;
}
/**
* Résout le MultiDoku passé en paramètre, sans backtracking.
* @param doku MultiDoku, MultiDoku à résoudre.
* @return boolean, valant true si le MultiDoku est résolu, false sinon.
*/
public static boolean humanSolve(MultiDoku doku) {
if (Thread.interrupted())
throw new CancellationException("User wants to stop the solver");
List<Cell> cellsToFill = doku.getEmptyCells();
while (!cellsToFill.isEmpty()) {
boolean blocked = true;
for (Cell cellToFill : cellsToFill) {
List<Integer> possibleSymbols = doku.getPossibleSymbolsOfCell(cellToFill);
if (possibleSymbols.size() != 1) {
continue;
}
cellToFill.setSymbolIndex(possibleSymbols.getFirst());
cellsToFill.remove(cellToFill);
blocked = false;
break;
}
if (blocked) {
break;
}
}
return doku.isValid();
}
}