Fixes #12
Some checks failed
Linux arm64 / Build (push) Has been cancelled

This commit is contained in:
2025-02-01 21:16:36 +01:00
parent d09bf6e9ce
commit 3a009256c5

View File

@@ -22,6 +22,8 @@ public class SudokuView extends BaseView {
private String lastSavePath = null; private String lastSavePath = null;
private boolean resolved = false; private boolean resolved = false;
// if the solver can't solve
private volatile boolean unresolved = false;
public SudokuView(StateMachine stateMachine, MultiDoku doku) { public SudokuView(StateMachine stateMachine, MultiDoku doku) {
super(stateMachine); super(stateMachine);
@@ -80,10 +82,16 @@ public class SudokuView extends BaseView {
} }
} }
private void renderUnsolvableText() {
if (this.unresolved)
ImGui.text("Impossible de résoudre avec l'algorithme actuel !");
}
private void startSolve(Solver solver) { private void startSolve(Solver solver) {
resolveThread = new Thread(() -> { resolveThread = new Thread(() -> {
try { try {
solver.solve(this.doku); unresolved = !solver.solve(this.doku);
} catch (CancellationException e) { } catch (CancellationException e) {
System.out.println("The user is bored !"); System.out.println("The user is bored !");
} }
@@ -91,6 +99,11 @@ public class SudokuView extends BaseView {
}); });
} }
private void renderResolvedText() {
if (this.resolved)
ImGui.text("Bravo !");
}
private void renderSolvePopup() { private void renderSolvePopup() {
if (ImGui.beginPopup("solve")) { if (ImGui.beginPopup("solve")) {
if (ImGui.button("Résoudre avec backtrace")) { if (ImGui.button("Résoudre avec backtrace")) {
@@ -120,9 +133,8 @@ public class SudokuView extends BaseView {
if (resolveThread != null) if (resolveThread != null)
ImGui.endDisabled(); ImGui.endDisabled();
if (this.resolved) { renderResolvedText();
ImGui.text("Bravo !"); renderUnsolvableText();
}
renderSolvePopup(); renderSolvePopup();
} }