refactor solvers
All checks were successful
Linux arm64 / Build (push) Successful in 42s

This commit is contained in:
2025-01-30 18:05:18 +01:00
parent 1f92c49f3c
commit a74bf42e59
11 changed files with 299 additions and 249 deletions

View File

@@ -1,12 +1,14 @@
package gui.menu;
import java.util.Random;
import java.util.concurrent.CancellationException;
import gui.SudokuRenderer;
import imgui.ImGui;
import imgui.ImGuiStyle;
import sudoku.io.SudokuSerializer;
import sudoku.solver.BacktrackingSolver;
import sudoku.solver.HumanSolver;
import sudoku.solver.MixedSolver;
import sudoku.solver.Solver;
import sudoku.structure.MultiDoku;
@@ -66,41 +68,29 @@ public class SudokuView extends BaseView {
stopResolve();
}
private void startSolve(Solver solver) {
resolveThread = new Thread(() -> {
try {
solver.solve(this.doku);
} catch (CancellationException e) {
System.out.println("The user is bored !");
}
stopResolve();
});
}
private void renderSolvePopup() {
if (ImGui.beginPopup("solve")) {
if (ImGui.button("Résoudre avec backtrace")) {
resolveThread = new Thread(() -> {
try {
Random rand = new Random();
Solver.randomSolve(doku, rand);
} catch (CancellationException e) {
System.out.println("The user is bored !");
}
stopResolve();
});
startSolve(new BacktrackingSolver());
ImGui.closeCurrentPopup();
}
if (ImGui.button("Résoudre avec déduction")) {
resolveThread = new Thread(() -> {
try {
Solver.humanSolve(doku);
} catch (CancellationException e) {
System.out.println("The user is bored !");
}
stopResolve();
});
startSolve(new HumanSolver());
ImGui.closeCurrentPopup();
}
if (ImGui.button("Résoudre avec déduction et backtrace")) {
resolveThread = new Thread(() -> {
try {
Random rand = new Random();
Solver.mixedSolve(doku, rand);
} catch (CancellationException e) {
System.out.println("The user is bored !");
}
stopResolve();
});
startSolve(new MixedSolver());
ImGui.closeCurrentPopup();
}
ImGui.endPopup();