whoa
Some checks failed
Linux arm64 / Build (push) Failing after 23s

This commit is contained in:
Janet-Doe
2025-01-10 17:04:58 +01:00
parent d849f3afc4
commit e2c8253f4a
4 changed files with 97 additions and 3 deletions

View File

@@ -0,0 +1,39 @@
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;
public class Solver {
Caretaker stack;
public Solver() {
}
public MultiDoku solve(MultiDoku doku, List<IConstraint> constraints) throws Exception {
if (!doku.isValid(constraints)) {
throw new Exception("Invalid doku");
}
List<MutableCell> allMutableCells = doku.getMutableCells();
List<MutableCell> remainingCellsToCheck = new ArrayList<>(allMutableCells);
Random rand = new Random();
while (!remainingCellsToCheck.isEmpty()) {
int indexCurrentCell = rand.nextInt(remainingCellsToCheck.size());
MutableCell currentCell = remainingCellsToCheck.get(indexCurrentCell);
if (currentCell.getHints().isEmpty()){
MutableCell modify = allMutableCells.get(stack.undo());
modify.clear(modify.getSymboleIndex());
}
remainingCellsToCheck.remove(indexCurrentCell);
}
return doku;
}
}