fix : MultiDoku.getCells

This commit is contained in:
Melvyn
2025-01-29 18:42:58 +01:00
parent 9213a10c17
commit cd4d01e1e6
7 changed files with 132 additions and 50 deletions

View File

@@ -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();