This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
package gui.menu;
|
package gui.menu;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.CancellationException;
|
import java.util.concurrent.CancellationException;
|
||||||
|
|
||||||
import gui.widget.SudokuRenderer;
|
import gui.widget.SudokuRenderer;
|
||||||
@@ -11,6 +13,7 @@ import sudoku.solver.HintHelper;
|
|||||||
import sudoku.solver.HumanSolver;
|
import sudoku.solver.HumanSolver;
|
||||||
import sudoku.solver.MixedSolver;
|
import sudoku.solver.MixedSolver;
|
||||||
import sudoku.solver.Solver;
|
import sudoku.solver.Solver;
|
||||||
|
import sudoku.solver.SolverStep;
|
||||||
import sudoku.solver.HintHelper.Hint;
|
import sudoku.solver.HintHelper.Hint;
|
||||||
import sudoku.structure.MultiDoku;
|
import sudoku.structure.MultiDoku;
|
||||||
|
|
||||||
@@ -90,8 +93,9 @@ public class SudokuView extends BaseView {
|
|||||||
|
|
||||||
private void startSolve(Solver solver) {
|
private void startSolve(Solver solver) {
|
||||||
resolveThread = new Thread(() -> {
|
resolveThread = new Thread(() -> {
|
||||||
|
List<SolverStep> steps = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
unresolved = !solver.solve(this.doku);
|
unresolved = !solver.solve(this.doku, steps);
|
||||||
} catch (CancellationException e) {
|
} catch (CancellationException e) {
|
||||||
System.out.println("The user is bored !");
|
System.out.println("The user is bored !");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ public class BacktrackingSolver implements Solver {
|
|||||||
for (int symbol : possibleSymbols) {
|
for (int symbol : possibleSymbols) {
|
||||||
cellToFill.setSymbolIndex(symbol);
|
cellToFill.setSymbolIndex(symbol);
|
||||||
addStep(cellToFill, steps);
|
addStep(cellToFill, steps);
|
||||||
if (this.solve(doku)) {
|
if (this.solve(doku, steps)) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
cellToFill.setSymbolIndex(Cell.NOSYMBOL);
|
cellToFill.setSymbolIndex(Cell.NOSYMBOL);
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public class HumanSolver implements Solver {
|
|||||||
cellToFill.setSymbolIndex(possibleSymbols.getFirst());
|
cellToFill.setSymbolIndex(possibleSymbols.getFirst());
|
||||||
addStep(cellToFill, steps);
|
addStep(cellToFill, steps);
|
||||||
|
|
||||||
return this.solve(doku);
|
return this.solve(doku, steps);
|
||||||
}
|
}
|
||||||
|
|
||||||
return doku.isSolved();
|
return doku.isSolved();
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public class MixedSolver implements Solver {
|
|||||||
if (possibleSymbols.size() == 1) {
|
if (possibleSymbols.size() == 1) {
|
||||||
cellToFill.setSymbolIndex(possibleSymbols.getFirst());
|
cellToFill.setSymbolIndex(possibleSymbols.getFirst());
|
||||||
addStep(cellToFill, steps);
|
addStep(cellToFill, steps);
|
||||||
if (this.solve(doku)) {
|
if (this.solve(doku, steps)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -61,7 +61,7 @@ public class MixedSolver implements Solver {
|
|||||||
|
|
||||||
cellToFill.setSymbolIndex(nextSymbol);
|
cellToFill.setSymbolIndex(nextSymbol);
|
||||||
addStep(cellToFill, steps);
|
addStep(cellToFill, steps);
|
||||||
if (this.solve(doku)) {
|
if (this.solve(doku, steps)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
cellToFill.setSymbolIndex(Cell.NOSYMBOL);
|
cellToFill.setSymbolIndex(Cell.NOSYMBOL);
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public class RandomSolver implements Solver {
|
|||||||
|
|
||||||
cellToFill.setSymbolIndex(nextSymbol);
|
cellToFill.setSymbolIndex(nextSymbol);
|
||||||
addStep(cellToFill, steps);
|
addStep(cellToFill, steps);
|
||||||
if (this.solve(doku)) {
|
if (this.solve(doku, steps)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
cellToFill.setSymbolIndex(Cell.NOSYMBOL);
|
cellToFill.setSymbolIndex(Cell.NOSYMBOL);
|
||||||
|
|||||||
Reference in New Issue
Block a user