merge
Some checks failed
Linux arm64 / Build (push) Failing after 20s

This commit is contained in:
Janet-Doe
2025-01-21 19:10:06 +01:00
parent 963cea897c
commit 4bd55d4ce4
9 changed files with 151 additions and 37 deletions

View File

@@ -12,7 +12,10 @@ import java.util.Stack;
public class Solver {
Stack<MutableCell> stack;
public Solver() {
public Solver() {}
private void rollBack() {
stack.pop();
}
public MultiDoku solve(MultiDoku doku, List<IConstraint> constraints) throws Exception {
@@ -25,26 +28,16 @@ public class Solver {
while (!remainingCellsToCheck.isEmpty()) {
int indexCurrentCell = rand.nextInt(remainingCellsToCheck.size());
MutableCell currentCell = remainingCellsToCheck.get(indexCurrentCell);
if (currentCell.getPossibleSymbols().isEmpty()){
MutableCell modify = stack.pop();
modify.removeSymbolFromPossibilities(modify.clearCurrentSymbol());
} else {
int symbol = currentCell.getPossibleSymbols().get(0);
currentCell.setSymbolIndex(symbol);
stack.push(currentCell);
try {
doku.updateSymbolsPossibilities();
} catch (Exception e) {
//TODO rollback
}
//TODO check constraints integrity in sudoku
int symbol = currentCell.getPossibleSymbols().get(0);
currentCell.setSymbolIndex(symbol);
stack.push(new MutableCell(currentCell));
try {
doku.updateSymbolsPossibilities();
} catch (Exception e) {
this.rollBack();
System.out.println(this.stack);
}
remainingCellsToCheck.remove(indexCurrentCell);
}
return doku;