fix : MultiDoku.getCells
This commit is contained in:
@@ -32,12 +32,12 @@ public class Solver {
|
||||
throw new CancellationException("User wants to stop the solver");
|
||||
|
||||
Sudoku sudoku = doku.getSubGrid(0);
|
||||
logger.log(Level.INFO,
|
||||
logger.log(Level.FINE,
|
||||
'\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.isSolved()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ public class Solver {
|
||||
|
||||
/**
|
||||
* Compte le nombre de solutions possibles au MultiDoku passé en paramètres.
|
||||
* @param doku MultiDoku, MultiDoku dont on veut le nombre de solutions.
|
||||
* @param oldDoku MultiDoku, MultiDoku dont on veut le nombre de solutions.
|
||||
* @return int, nombre de solutions possibles.
|
||||
*/
|
||||
public static int countSolution(MultiDoku oldDoku) {
|
||||
@@ -73,21 +73,23 @@ public class Solver {
|
||||
|
||||
MultiDoku doku = oldDoku.clone();
|
||||
|
||||
if (doku.isValid()) {
|
||||
if (doku.isSolved()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
Cell cellToFill = doku.getFirstEmptyCell();
|
||||
if (cellToFill == null) {
|
||||
System.out.println("AAAAAAAAAAAAAA");
|
||||
return 0;
|
||||
}
|
||||
|
||||
List<Integer> possibleSymbols = doku.getPossibleSymbolsOfCell(cellToFill);
|
||||
|
||||
for (int symbol : possibleSymbols) {
|
||||
|
||||
cellToFill.setSymbolIndex(symbol);
|
||||
if (Solver.solve(doku)) {
|
||||
System.out.println("symbol : "+symbol);
|
||||
System.out.println("doku.isSolved() || Solver.solve(doku) ? "+ (doku.isSolved() || Solver.solve(doku)));
|
||||
if (doku.isSolved() || Solver.solve(doku)) {
|
||||
result++;
|
||||
}
|
||||
cellToFill.setSymbolIndex(Cell.NOSYMBOL);
|
||||
@@ -105,7 +107,7 @@ public class Solver {
|
||||
if (Thread.interrupted())
|
||||
throw new CancellationException("User wants to stop the solver");
|
||||
|
||||
if (doku.isValid()) {
|
||||
if (doku.isSolved()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -144,6 +146,13 @@ public class 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) {
|
||||
|
||||
@@ -163,6 +172,6 @@ public class Solver {
|
||||
}
|
||||
}
|
||||
|
||||
return doku.isValid();
|
||||
return doku.isSolved();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user