feat : Solver.solve()

This commit is contained in:
Melvyn
2025-01-23 16:28:41 +01:00
parent e19a9c7b27
commit fc7ae02387
5 changed files with 80 additions and 9 deletions

View File

@@ -10,14 +10,41 @@ import java.util.Random;
import java.util.Stack;
public class Solver {
Stack<MutableCell> stack;
public Solver() {}
/**
* Résout le multidoku passé en paramètre si c'est possible.
* En testant toutes les possibilités avec un algorithme de backtracking.
* @param doku Multidouke, à résoudre
* @return boolean, true s'il est résolut ou false s'il ne l'est pas.
*/
public boolean solve(MultiDoku doku) {
MutableCell cellToFill = doku.getFirstEmptyMutableCell();
if (cellToFill == null) {
return true;
}
List<Integer> possibleSymbols = doku.getPossibleSymbolsOfCell(cellToFill);
if (possibleSymbols.isEmpty()) {
return false;
}
for (int symbol : possibleSymbols) {
cellToFill.setSymbolIndex(symbol);
return this.solve(doku);
}
return false;
}
/*
Ancien algo abandonné pour le moment
private void rollBack() {
stack.pop();
}
public MultiDoku solve(MultiDoku doku, List<IConstraint> constraints) throws Exception {
List<MutableCell> allMutableCells = doku.getMutableCells();
List<MutableCell> remainingCellsToCheck = new ArrayList<>(allMutableCells);
@@ -39,4 +66,6 @@ public class Solver {
}
return doku;
}
*/
}