fix : MixedSolver
All checks were successful
Linux arm64 / Build (push) Successful in 40s

This commit is contained in:
Melvyn
2025-01-31 18:26:44 +01:00
parent f47e4cc309
commit b7f9ca8a98
2 changed files with 26 additions and 39 deletions

View File

@@ -17,8 +17,6 @@ public class MixedSolver implements Solver{
* backtracking.
*
* @param doku MultiDoku, MultiDoku à résoudre.
* @param rand Random, pour tester aléatoirement les symboles, lors du
* backtracking.
* @return boolean, valant true si le MultiDoku est résolu, false sinon.
*/
@Override
@@ -40,29 +38,20 @@ public class MixedSolver implements Solver{
return true;
}
List<Cell> cellsToFill = doku.getEmptyCells();
if (cellsToFill.isEmpty()) {
Cell cellToFill = doku.getFirstEmptyCell();
if (cellToFill == null) {
return false;
}
// Règles de déduction
for (Cell cellToFill : cellsToFill) {
List<Integer> possibleSymbols = cellToFill.getPossibleSymbols();
if (possibleSymbols.size() != 1) {
continue;
}
cellToFill.setSymbolIndex(possibleSymbols.getFirst());
return this.solve(doku);
}
// Si ça ne marche pas
// On fait du backtracking
Cell cellToFill = doku.getRandomEmptyCell(rand);
List<Integer> possibleSymbols = cellToFill.getPossibleSymbols();
if (possibleSymbols.size() == 1) {
cellToFill.setSymbolIndex(possibleSymbols.getFirst());
if (this.solve(doku)) {
return true;
}
}
while (!possibleSymbols.isEmpty()) {
int nextPossibleSymbolIndex = rand.nextInt(possibleSymbols.size());
int nextSymbol = possibleSymbols.get(nextPossibleSymbolIndex);
@@ -71,9 +60,9 @@ public class MixedSolver implements Solver{
if (this.solve(doku)) {
return true;
}
cellToFill.setSymbolIndex(Cell.NOSYMBOL);
possibleSymbols.remove(nextPossibleSymbolIndex);
}
return false;