fix: serialize
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
package sudoku.solver;
|
||||
|
||||
import sudoku.io.SudokuPrinter;
|
||||
import sudoku.structure.MultiDoku;
|
||||
import sudoku.structure.Cell;
|
||||
import sudoku.structure.Sudoku;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import sudoku.io.SudokuPrinter;
|
||||
import sudoku.structure.Cell;
|
||||
import sudoku.structure.MultiDoku;
|
||||
import sudoku.structure.Sudoku;
|
||||
|
||||
public class Solver {
|
||||
|
||||
/**
|
||||
@@ -46,7 +46,7 @@ public class Solver {
|
||||
return false;
|
||||
}
|
||||
|
||||
List<Integer> possibleSymbols = doku.getPossibleSymbolsOfCell(cellToFill);
|
||||
List<Integer> possibleSymbols = cellToFill.getPossibleSymbols();
|
||||
|
||||
while (!possibleSymbols.isEmpty()) {
|
||||
int nextPossibleSymbolIndex = rand.nextInt(possibleSymbols.size());
|
||||
@@ -78,18 +78,13 @@ public class Solver {
|
||||
}
|
||||
|
||||
Cell cellToFill = doku.getFirstEmptyCell();
|
||||
if (cellToFill == null) {
|
||||
System.out.println("AAAAAAAAAAAAAA");
|
||||
return 0;
|
||||
}
|
||||
assert(cellToFill != null);
|
||||
|
||||
List<Integer> possibleSymbols = doku.getPossibleSymbolsOfCell(cellToFill);
|
||||
List<Integer> possibleSymbols = cellToFill.getPossibleSymbols();
|
||||
|
||||
for (int symbol : possibleSymbols) {
|
||||
cellToFill.setSymbolIndex(symbol);
|
||||
System.out.println("symbol : "+symbol);
|
||||
System.out.println("doku.isSolved() || Solver.solve(doku) ? "+ (doku.isSolved() || Solver.solve(doku)));
|
||||
if (doku.isSolved() || Solver.solve(doku)) {
|
||||
if (Solver.solve(doku) != null) {
|
||||
result++;
|
||||
}
|
||||
cellToFill.setSymbolIndex(Cell.NOSYMBOL);
|
||||
@@ -103,35 +98,37 @@ public class Solver {
|
||||
* @param doku MultiDoku, MultiDoku à résoudre.
|
||||
* @return boolean, valant true si le MultiDoku est résolu, false sinon.
|
||||
*/
|
||||
public static boolean solve(MultiDoku doku) {
|
||||
public static MultiDoku solve(MultiDoku oldDoku) {
|
||||
if (Thread.interrupted())
|
||||
throw new CancellationException("User wants to stop the solver");
|
||||
|
||||
MultiDoku doku = oldDoku.clone();
|
||||
|
||||
if (doku.isSolved()) {
|
||||
return true;
|
||||
return doku;
|
||||
}
|
||||
|
||||
Cell cellToFill = doku.getFirstEmptyCell();
|
||||
if (cellToFill == null) {
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
List<Integer> possibleSymbols = doku.getPossibleSymbolsOfCell(cellToFill);
|
||||
List<Integer> possibleSymbols = cellToFill.getPossibleSymbols();
|
||||
if (possibleSymbols.isEmpty()) {
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
for (int symbol : possibleSymbols) {
|
||||
|
||||
cellToFill.setSymbolIndex(symbol);
|
||||
if (Solver.solve(doku)) {
|
||||
return true;
|
||||
if (Solver.solve(doku) != null) {
|
||||
return doku;
|
||||
} else {
|
||||
cellToFill.setSymbolIndex(Cell.NOSYMBOL);
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -156,7 +153,7 @@ public class Solver {
|
||||
boolean blocked = true;
|
||||
for (Cell cellToFill : cellsToFill) {
|
||||
|
||||
List<Integer> possibleSymbols = doku.getPossibleSymbolsOfCell(cellToFill);
|
||||
List<Integer> possibleSymbols = cellToFill.getPossibleSymbols();
|
||||
if (possibleSymbols.size() != 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user