feat: add history

This commit is contained in:
2025-02-01 22:54:02 +01:00
parent 3e30332245
commit 78bdefebe5
6 changed files with 54 additions and 15 deletions

View File

@@ -11,17 +11,17 @@ import sudoku.structure.Cell;
import sudoku.structure.MultiDoku;
import sudoku.structure.Sudoku;
public class MixedSolver implements Solver{
public class MixedSolver implements Solver {
/**
/**
* Résout le MultiDoku passé en paramètre, avec règles de déduction et
* backtracking.
*
* @param doku MultiDoku, MultiDoku à résoudre.
* @return boolean, valant true si le MultiDoku est résolu, false sinon.
*/
@Override
public boolean solve(MultiDoku doku) {
@Override
public boolean solve(MultiDoku doku, List<SolverStep> steps) {
Random rand = new Random();
if (Thread.interrupted()) {
@@ -49,6 +49,7 @@ public class MixedSolver implements Solver{
if (possibleSymbols.size() == 1) {
cellToFill.setSymbolIndex(possibleSymbols.getFirst());
addStep(cellToFill, steps);
if (this.solve(doku)) {
return true;
}
@@ -59,10 +60,12 @@ public class MixedSolver implements Solver{
int nextSymbol = possibleSymbols.get(nextPossibleSymbolIndex);
cellToFill.setSymbolIndex(nextSymbol);
addStep(cellToFill, steps);
if (this.solve(doku)) {
return true;
}
cellToFill.setSymbolIndex(Cell.NOSYMBOL);
addStep(cellToFill, steps);
possibleSymbols.remove(nextPossibleSymbolIndex);
}