2 Commits

Author SHA1 Message Date
1f92c49f3c feat: select solve algorithm
All checks were successful
Linux arm64 / Build (push) Successful in 25m12s
2025-01-30 17:28:43 +01:00
c262007ca8 fix multithreading issue 2025-01-30 17:28:22 +01:00
2 changed files with 49 additions and 19 deletions

View File

@@ -126,7 +126,7 @@ public class SudokuRenderer {
ImGui.pushStyleColor(ImGuiCol.Button, new ImVec4(blockColor.r, blockColor.g, blockColor.b, 1.0f)); ImGui.pushStyleColor(ImGuiCol.Button, new ImVec4(blockColor.r, blockColor.g, blockColor.b, 1.0f));
String cellText = ""; String cellText = "";
if (symbol != -1) if (symbol != -1)
cellText += Options.Symboles.getSymbols().get(cell.getSymbolIndex()); cellText += Options.Symboles.getSymbols().get(symbol);
if (ImGui.button(cellText + "##" + index, cellSize) && cell.isMutable()) { if (ImGui.button(cellText + "##" + index, cellSize) && cell.isMutable()) {
ImGui.openPopup("editPopup"); ImGui.openPopup("editPopup");
currentCell = cell; currentCell = cell;

View File

@@ -66,34 +66,64 @@ public class SudokuView extends BaseView {
stopResolve(); stopResolve();
} }
private void renderSolveButton() { private void renderSolvePopup() {
if (resolveThread != null) if (ImGui.beginPopup("solve")) {
ImGui.beginDisabled(); if (ImGui.button("Résoudre avec backtrace")) {
boolean beginSolve = false;
if (!resolved && centeredButton("Résoudre")) {
beginSolve = true;
}
if (resolveThread != null)
ImGui.endDisabled();
if (beginSolve) {
resolveThread = new Thread(() -> { resolveThread = new Thread(() -> {
try { try {
Random rand = new Random(); Random rand = new Random();
Solver.randomSolve(doku, rand); Solver.randomSolve(doku, rand);
Thread.sleep(200); } catch (CancellationException e) {
} catch (CancellationException | InterruptedException e) {
System.out.println("The user is bored !"); System.out.println("The user is bored !");
} }
stopResolve(); stopResolve();
}); });
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();
});
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();
});
ImGui.closeCurrentPopup();
}
ImGui.endPopup();
}
} }
if (resolved) { private void renderSolveButton() {
if (resolveThread != null)
ImGui.beginDisabled();
if (!this.resolved && centeredButton("Résoudre")) {
// beginSolve = true;
ImGui.openPopup("solve");
}
if (resolveThread != null)
ImGui.endDisabled();
if (this.resolved) {
ImGui.text("Bravo !"); ImGui.text("Bravo !");
} }
renderSolvePopup();
} }
private void renderSaveButton() { private void renderSaveButton() {