48 lines
1.2 KiB
Java
48 lines
1.2 KiB
Java
package sudoku.solver;
|
|
|
|
import java.util.List;
|
|
import java.util.logging.Logger;
|
|
|
|
import sudoku.structure.Cell;
|
|
import sudoku.structure.MultiDoku;
|
|
|
|
public interface Solver {
|
|
|
|
/**
|
|
* Log du Solver, qui garde trace des actions réalisées.
|
|
*/
|
|
public static final Logger logger = Logger.getLogger("SolverLogger");
|
|
|
|
boolean solve(MultiDoku doku);
|
|
|
|
/**
|
|
* Compte le nombre de solutions possibles au MultiDoku passé en paramètres.
|
|
*
|
|
* @param doku MultiDoku, MultiDoku dont on veut le nombre de solutions.
|
|
* @return int, nombre de solutions possibles.
|
|
*/
|
|
default int countSolution(MultiDoku doku) {
|
|
int result = 0;
|
|
|
|
if (doku.isSolved()) {
|
|
return 1;
|
|
}
|
|
|
|
Cell cellToFill = doku.getFirstEmptyCell();
|
|
assert (cellToFill != null);
|
|
|
|
List<Integer> possibleSymbols = cellToFill.getPossibleSymbols();
|
|
|
|
for (int symbol : possibleSymbols) {
|
|
doku.getStateManager().pushState();
|
|
cellToFill.setSymbolIndex(symbol);
|
|
if (solve(doku)) {
|
|
result++;
|
|
}
|
|
doku.getStateManager().popState();
|
|
}
|
|
return result;
|
|
}
|
|
|
|
}
|