feat : solver + test
All checks were successful
Linux arm64 / Build (push) Successful in 5m9s

This commit is contained in:
Melvyn
2025-01-23 23:20:16 +01:00
parent 6902321101
commit 483b286bac
13 changed files with 292 additions and 183 deletions

View File

@@ -1,13 +1,10 @@
package sudoku.solver;
import sudoku.MultiDoku;
import sudoku.MutableCell;
import sudoku.constraint.IConstraint;
import sudoku.Cell;
import sudoku.io.SudokuPrinter;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Stack;
public class Solver {
@@ -18,11 +15,15 @@ public class Solver {
* @return boolean, true s'il est résolut ou false s'il ne l'est pas.
*/
public static boolean solve(MultiDoku doku) {
MutableCell cellToFill = doku.getFirstEmptyMutableCell();
if (cellToFill == null) {
if (doku.isValid()) {
return true;
}
Cell cellToFill = doku.getFirstEmptyCell();
if (cellToFill == null) {
return false;
}
List<Integer> possibleSymbols = doku.getPossibleSymbolsOfCell(cellToFill);
if (possibleSymbols.isEmpty()) {
return false;
@@ -30,7 +31,11 @@ public class Solver {
for (int symbol : possibleSymbols) {
cellToFill.setSymbolIndex(symbol);
return Solver.solve(doku);
if (Solver.solve(doku)) {
return true;
} else {
cellToFill.setSymbolIndex(Cell.NOSYMBOL);
}
}
return false;
}