Skip to content
Snippets Groups Projects
Commit b05dda14 authored by tmp1u19's avatar tmp1u19 :octopus:
Browse files

Add the hint functionality and the solver of the board

parent be4cb1b3
No related branches found
No related tags found
No related merge requests found
import javafx.animation.*;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.control.Button;
......@@ -717,10 +719,29 @@ public class Handler {
return true;
}
public void solveBoard(Button solve, GridPane grid, int n) {
solve.setOnAction(actionEvent -> {
Solver solver = new Solver(n, grid);
solver.backtracking(1, 1);
public void solveBoard(GridPane grid) {
Solver solver = new Solver(n, grid);
solver.backtracking(1, 1);
clear(grid);
}
public void hint(Button hint, GridPane grid) {
hint.setOnAction(actionEvent -> {
boolean found = false;
for(int i = 0; i < n && !found; i ++) {
for(int j = 0; j < n; j ++) {
if(cellValues[i][j] != Solver.solved[i][j]) {
getCell(grid, i, j).setValue(Solver.solved[i][j]);
cellValues[i][j] = Solver.solved[i][j];
found = true;
break;
}
}
}
});
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment