This commit is contained in:
@@ -27,7 +27,7 @@ public class Solver {
|
||||
* @param rand Random, pour tester aléatoirement les symboles
|
||||
* @return boolean, true s'il est résolu ou false s'il ne l'est pas.
|
||||
*/
|
||||
public static boolean solveRandom(MultiDoku doku, Random rand) {
|
||||
public static boolean randomSolve(MultiDoku doku, Random rand) {
|
||||
if (Thread.interrupted())
|
||||
throw new CancellationException("User wants to stop the solver");
|
||||
|
||||
@@ -53,7 +53,7 @@ public class Solver {
|
||||
int nextSymbol = possibleSymbols.get(nextPossibleSymbolIndex);
|
||||
|
||||
cellToFill.setSymbolIndex(nextSymbol);
|
||||
if (Solver.solveRandom(doku, rand)) {
|
||||
if (Solver.randomSolve(doku, rand)) {
|
||||
return true;
|
||||
}
|
||||
cellToFill.setSymbolIndex(Cell.NOSYMBOL);
|
||||
@@ -65,7 +65,7 @@ public class Solver {
|
||||
|
||||
/**
|
||||
* Compte le nombre de solutions possibles au MultiDoku passé en paramètres.
|
||||
* @param oldDoku MultiDoku, MultiDoku dont on veut le nombre de solutions.
|
||||
* @param doku MultiDoku, MultiDoku dont on veut le nombre de solutions.
|
||||
* @return int, nombre de solutions possibles.
|
||||
*/
|
||||
public static int countSolution(MultiDoku doku) {
|
||||
@@ -130,7 +130,7 @@ public class Solver {
|
||||
}
|
||||
|
||||
/**
|
||||
* Résout le MultiDoku passé en paramètre, sans backtracking.
|
||||
* Résout le MultiDoku passé en paramètre, avec règles de déduction.
|
||||
* @param doku MultiDoku, MultiDoku à résoudre.
|
||||
* @return boolean, valant true si le MultiDoku est résolu, false sinon.
|
||||
*/
|
||||
@@ -169,4 +169,45 @@ public class Solver {
|
||||
|
||||
return doku.isSolved();
|
||||
}
|
||||
|
||||
/**
|
||||
* Résout le MultiDoku passé en paramètre, avec règles de déduction et backtracking.
|
||||
* @param doku MultiDoku, MultiDoku à résoudre.
|
||||
* @return boolean, valant true si le MultiDoku est résolu, false sinon.
|
||||
*/
|
||||
public static boolean mixedSolve(MultiDoku doku) {
|
||||
if (Thread.interrupted())
|
||||
throw new CancellationException("User wants to stop the solver");
|
||||
|
||||
List<Cell> cellsToFill = doku.getEmptyCells();
|
||||
|
||||
while (!cellsToFill.isEmpty()) {
|
||||
|
||||
Sudoku sudoku = doku.getSubGrid(0);
|
||||
logger.log(Level.FINE,
|
||||
'\n' + SudokuPrinter.toStringRectangleSudoku(sudoku,
|
||||
sudoku.getBlockWidth() == 0 ? sudoku.getSize() : sudoku.getBlockWidth(),
|
||||
sudoku.getBlockWidth() == 0 ? sudoku.getSize() : sudoku.getSize() / sudoku.getBlockWidth()));
|
||||
|
||||
boolean blocked = true;
|
||||
for (Cell cellToFill : cellsToFill) {
|
||||
|
||||
List<Integer> possibleSymbols = cellToFill.getPossibleSymbols();
|
||||
if (possibleSymbols.size() != 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
cellToFill.setSymbolIndex(possibleSymbols.getFirst());
|
||||
cellsToFill.remove(cellToFill);
|
||||
blocked = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (blocked) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return doku.isSolved();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user