@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user