This commit is contained in:
@@ -16,7 +16,8 @@ public class Solver {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Résout le multidoku passé en paramètre si c'est possible.
|
* Résout le multidoku passé en paramètre si c'est possible.
|
||||||
* En testant toutes les possibilités, de manière aléatoire, avec un algorithme de backtracking.
|
* En testant toutes les possibilités, de manière aléatoire, avec un algorithme
|
||||||
|
* de backtracking.
|
||||||
*
|
*
|
||||||
* @param doku Multidoku, à résoudre
|
* @param doku Multidoku, à résoudre
|
||||||
* @param rand Random, pour tester aléatoirement les symboles
|
* @param rand Random, pour tester aléatoirement les symboles
|
||||||
@@ -24,10 +25,13 @@ public class Solver {
|
|||||||
*/
|
*/
|
||||||
public static boolean solveRandom(MultiDoku doku, Random rand) {
|
public static boolean solveRandom(MultiDoku doku, Random rand) {
|
||||||
if (Thread.interrupted())
|
if (Thread.interrupted())
|
||||||
throw new CancellationException("User wants to stop the solver");
|
throw new CancellationException("User wants to stop the solver");
|
||||||
|
|
||||||
Sudoku sudoku = doku.getSubGrid(0);
|
Sudoku sudoku = doku.getSubGrid(0);
|
||||||
logger.log(Level.INFO, '\n'+SudokuPrinter.toStringRectangleSudoku(sudoku, sudoku.getSize(), sudoku.getSize()));
|
logger.log(Level.INFO,
|
||||||
|
'\n' + SudokuPrinter.toStringRectangleSudoku(sudoku,
|
||||||
|
sudoku.getBlockWidth() == 0 ? sudoku.getSize() : sudoku.getBlockWidth(),
|
||||||
|
sudoku.getBlockWidth() == 0 ? sudoku.getSize() : sudoku.getSize() / sudoku.getBlockWidth()));
|
||||||
|
|
||||||
if (doku.isValid()) {
|
if (doku.isValid()) {
|
||||||
return true;
|
return true;
|
||||||
@@ -83,7 +87,7 @@ public class Solver {
|
|||||||
|
|
||||||
public static boolean solve(MultiDoku doku) {
|
public static boolean solve(MultiDoku doku) {
|
||||||
if (Thread.interrupted())
|
if (Thread.interrupted())
|
||||||
throw new CancellationException("User wants to stop the solver");
|
throw new CancellationException("User wants to stop the solver");
|
||||||
|
|
||||||
if (doku.isValid()) {
|
if (doku.isValid()) {
|
||||||
return true;
|
return true;
|
||||||
@@ -99,7 +103,7 @@ public class Solver {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int symbol : possibleSymbols){
|
for (int symbol : possibleSymbols) {
|
||||||
|
|
||||||
cellToFill.setSymbolIndex(symbol);
|
cellToFill.setSymbolIndex(symbol);
|
||||||
if (Solver.solve(doku)) {
|
if (Solver.solve(doku)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user