refractoring
All checks were successful
Linux arm64 / Build (push) Successful in 33s

This commit is contained in:
Janet-Doe
2025-01-21 13:49:22 +01:00
parent 5a07f9347c
commit e5618b70c1
8 changed files with 60 additions and 36 deletions

View File

@@ -1,17 +1,16 @@
package sudoku.solver;
import sudoku.Cell;
import sudoku.MultiDoku;
import sudoku.MutableCell;
import sudoku.Sudoku;
import sudoku.constraint.IConstraint;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Stack;
public class Solver {
Caretaker stack;
Stack<MutableCell> stack;
public Solver() {
}
@@ -26,12 +25,21 @@ public class Solver {
while (!remainingCellsToCheck.isEmpty()) {
int indexCurrentCell = rand.nextInt(remainingCellsToCheck.size());
MutableCell currentCell = remainingCellsToCheck.get(indexCurrentCell);
if (currentCell.getHints().isEmpty()){
MutableCell modify = stack.undo();
modify.removeHint(modify.clear());
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);
//TODO check constraints integrity in sudoku
}
remainingCellsToCheck.remove(indexCurrentCell);
}
return doku;