fix : MultiDoku.getCells
This commit is contained in:
@@ -10,6 +10,7 @@ import sudoku.constraint.BlockConstraint;
|
||||
import sudoku.constraint.ColumnConstraint;
|
||||
import sudoku.constraint.IConstraint;
|
||||
import sudoku.constraint.LineConstraint;
|
||||
import sudoku.io.SudokuPrinter;
|
||||
import sudoku.solver.Solver;
|
||||
|
||||
public class SudokuFactory {
|
||||
@@ -121,7 +122,8 @@ public class SudokuFactory {
|
||||
*/
|
||||
public static boolean newDokuFromFilledOne (MultiDoku doku, int nbCellsToEmpty) throws Exception {
|
||||
|
||||
if (nbCellsToEmpty > doku.getCells().size()) {
|
||||
System.out.println("nbCellsToEmpty : "+nbCellsToEmpty);
|
||||
if (nbCellsToEmpty >= doku.getCells().size()) {
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
@@ -137,7 +139,9 @@ public class SudokuFactory {
|
||||
|
||||
int oldSymbol = cellToEmpty.empty();
|
||||
|
||||
if (Solver.countSolution(doku) == 1) {
|
||||
int nbDokuSultions = Solver.countSolution(doku);
|
||||
System.out.println("oldSymbol : "+oldSymbol);
|
||||
if (nbDokuSultions == 1) {
|
||||
if (newDokuFromFilledOne(doku, --nbCellsToEmpty)) {
|
||||
return true;
|
||||
}
|
||||
@@ -239,9 +243,13 @@ public class SudokuFactory {
|
||||
|
||||
public static void fillDoku(MultiDoku doku, Difficulty difficulty) throws Exception {
|
||||
Solver.solveRandom(doku, random);
|
||||
//SudokuPrinter.printRectangleSudoku(doku.getSubGrid(0), 3, 3);
|
||||
int nbCellsToEmpty = (int)(difficulty.getFactor()*doku.getNbCells());
|
||||
boolean successfull = newDokuFromFilledOne(doku, nbCellsToEmpty);
|
||||
if (!successfull) {
|
||||
//System.out.println(nbCellsToEmpty);
|
||||
boolean successful = newDokuFromFilledOne(doku, nbCellsToEmpty);
|
||||
|
||||
|
||||
if (!successful) {
|
||||
throw new Exception("Canno't create this doku with this difficulty");
|
||||
}
|
||||
doku.setFilledCellsImmutable();
|
||||
|
||||
Reference in New Issue
Block a user