This commit is contained in:
@@ -1,13 +1,10 @@
|
||||
package sudoku.solver;
|
||||
|
||||
import sudoku.MultiDoku;
|
||||
import sudoku.MutableCell;
|
||||
import sudoku.constraint.IConstraint;
|
||||
import sudoku.Cell;
|
||||
import sudoku.io.SudokuPrinter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.Stack;
|
||||
|
||||
public class Solver {
|
||||
|
||||
@@ -18,11 +15,15 @@ public class Solver {
|
||||
* @return boolean, true s'il est résolut ou false s'il ne l'est pas.
|
||||
*/
|
||||
public static boolean solve(MultiDoku doku) {
|
||||
MutableCell cellToFill = doku.getFirstEmptyMutableCell();
|
||||
if (cellToFill == null) {
|
||||
if (doku.isValid()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Cell cellToFill = doku.getFirstEmptyCell();
|
||||
if (cellToFill == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
List<Integer> possibleSymbols = doku.getPossibleSymbolsOfCell(cellToFill);
|
||||
if (possibleSymbols.isEmpty()) {
|
||||
return false;
|
||||
@@ -30,7 +31,11 @@ public class Solver {
|
||||
|
||||
for (int symbol : possibleSymbols) {
|
||||
cellToFill.setSymbolIndex(symbol);
|
||||
return Solver.solve(doku);
|
||||
if (Solver.solve(doku)) {
|
||||
return true;
|
||||
} else {
|
||||
cellToFill.setSymbolIndex(Cell.NOSYMBOL);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user