• Home
  • Skills
  • Work
  • Blog
  • About
  • Contact

Sudoku Puzzle Generator and Solver

Java

Requirements

Construct a visually pleasing sudoku game that exists in three different difficulty modes; utilizing the idea that the less numbers filled in the board increases the difficulty. The program should construct a randomized and solvable (at least one solution exists). The game should also have a time objective for the player to challenge themselves. The board should solve itself and display the result to the user.

Description

Built a Sudoku game UI incorporating the Java Swing library as the frontend and the backtracking algorithm for the backend. The java class SudokuGame performs the grunt work of generating and solving the puzzle using several common methods such as isValid and checkBoard. The SudokuGUI class displays the generated board and then creates a new window with the solution (in the process removing the old one). The time is recorded while the player is solving the puzzle and the final time is shown with the solved board.

Challenges

  1. Generating a solvable sudoku board with at least one solution
    1. SOLUTION: Using the isValid method when adding a random number to a space on the board, in order to check for the validity of the board otherwise chose another number to satisfy requirement.
  2. Solving sudoku board following the several requirements of a Sudoku board: unique numbers across, below, and within the 3x3 box.
    1. SOLUTION: Instead of brute forcing the sudoku board (which may require thousands of iterations) use the backtracking algorithm to return to the last working number and checking sudoku requirements on every space.


View on GitHub | ↩ Back to Projects

Site by Maxim Shelepov. Icons by Icons8.