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 constraints) throws Exception { if (!doku.isValid(constraints)) { throw new Exception("Invalid doku"); } List allMutableCells = doku.getMutableCells(); List 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 = stack.undo(); modify.removeHint(modify.clear()); } remainingCellsToCheck.remove(indexCurrentCell); } return doku; } }