This commit is contained in:
@@ -9,9 +9,9 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import sudoku.io.SudokuSerializer;
|
||||
|
||||
import sudoku.constraint.Constraint;
|
||||
import sudoku.io.SudokuSerializer;
|
||||
import sudoku.solver.RandomSolver;
|
||||
import sudoku.solver.Solver;
|
||||
|
||||
public class SudokuFactory {
|
||||
@@ -116,7 +116,7 @@ public class SudokuFactory {
|
||||
* @return boolean, valant true si un MultiDoku de difficulté donnée peut être créée, false sinon.
|
||||
* @throws Exception si la difficulté n'est pas compatible avec la taille du MultiDoku.
|
||||
*/
|
||||
public static boolean newDokuFromFilledOne(MultiDoku doku, int nbCellsToEmpty) throws Exception {
|
||||
public static boolean newDokuFromFilledOne(MultiDoku doku, int nbCellsToEmpty, Solver solver) throws Exception {
|
||||
|
||||
if (nbCellsToEmpty >= doku.getCells().size()) {
|
||||
throw new Exception();
|
||||
@@ -134,9 +134,9 @@ public class SudokuFactory {
|
||||
|
||||
int oldSymbol = cellToEmpty.empty();
|
||||
|
||||
int nbDokuSultions = Solver.countSolution(doku);
|
||||
int nbDokuSultions = solver.countSolution(doku);
|
||||
if (nbDokuSultions == 1) {
|
||||
if (newDokuFromFilledOne(doku, --nbCellsToEmpty)) {
|
||||
if (newDokuFromFilledOne(doku, --nbCellsToEmpty, solver)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -145,7 +145,7 @@ public class SudokuFactory {
|
||||
cellsThatCanBeEmptied.remove(cellToEmpty);
|
||||
}
|
||||
|
||||
return newDokuFromFilledOne(doku, --nbCellsToEmpty);
|
||||
return newDokuFromFilledOne(doku, --nbCellsToEmpty, solver);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -272,9 +272,10 @@ public class SudokuFactory {
|
||||
}
|
||||
|
||||
public static void fillDoku(MultiDoku doku, Difficulty difficulty) throws Exception {
|
||||
Solver.randomSolve(doku, random);
|
||||
Solver solver = new RandomSolver();
|
||||
solver.solve(doku);
|
||||
int nbCellsToEmpty = (int) (difficulty.getFactor() * doku.getNbCells());
|
||||
boolean successfull = newDokuFromFilledOne(doku, nbCellsToEmpty);
|
||||
boolean successfull = newDokuFromFilledOne(doku, nbCellsToEmpty, solver);
|
||||
if (!successfull) {
|
||||
throw new Exception("Canno't create this doku with this difficulty");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user