This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user