Algorithm:
This a backtracking algorithm that employs a recursive, depth-first search strategy to explore potential solutions to the Sudoku puzzle.
It operates by systematically filling in cells with potential values and backtracking when a conflict arises,
i.e., when a number cannot be placed in a certain cell without violating the rules of the game.
solveWithAnimation Function:
This function serves as the core of the backtracking algorithm.
It iterates through each cell of the Sudoku grid and checks if it is empty.
If it is, the algorithm iterates through the numbers 1 to 9 to find a valid number for that cell.
If a valid number is found, it is placed in the cell and the function is called recursively.
If a solution is found, true is returned; otherwise, the cell is reset and the algorithm continues its search.
isSafe Function:
This function is crucial for determining if a number can be safely placed in a specific cell without violating the Sudoku rules.
It checks the candidate number against the corresponding row, column,
and 3x3 subgrid to ensure that it does not already exist in any of those locations.
If the number is found to be safe, the function returns true; otherwise, it returns false.
Dynamic Speed Adjustment:
The algorithm also incorporates visual updates and a sleep function for animation purposes.
This allows the user to visualize the process of solving the Sudoku puzzle step by step, enhancing the interactive experience.
The algorithm includes a mechanism to adjust the animation speed based on the number of guesses made,
enhancing user experience by gradually speeding up the solving process as the algorithm progresses.
If you want to read more about the rules of the Sudoku game, click here
If you want to play my other game, MasterMind, click here
If you want to learn more about me, click here