Skip to content
Michael Dunn edited this page Nov 2, 2013 · 4 revisions

Sudoku GUI

Assignment 8 - Sudoku Solver does not require the use of a GUI. However, I have provided one that allows you to interact with the sudoku board using a GUI.

This GUI does not require any changes to the original assignment and simply acts as a front end to the original assignment. The GUI provides the following features:

Using the GUI

  • Add the SudokuGUI.java class to the same directory as Sudoku.java and SudokuTest.java
  • Important: Remove or rename the package to the correct package
  • Compile and run the SudokuGUI class

Opening and Saving Sudoku Boards

  • The Open button allows the user to choose a sudoku file to load
  • The Save button allows the user to save the current state of the sudoku board to a file
Sudoku File Format
  • The file format is a comma separated value (CSV) text file
  • Each row in the sudoku board is delimited by a new line in the text file
  • Each column in the sudoku board is delimited by a comma in the text file
  • Files with a invalid file format will not be read in and an error message will be displayed
  • The following is a representation of the file format where each N represents a digit 0 - 9 and 0 represents an empty space
N,N,N,N,N,N,N,N,N
N,N,N,N,N,N,N,N,N
N,N,N,N,N,N,N,N,N
N,N,N,N,N,N,N,N,N
N,N,N,N,N,N,N,N,N
N,N,N,N,N,N,N,N,N
N,N,N,N,N,N,N,N,N
N,N,N,N,N,N,N,N,N
N,N,N,N,N,N,N,N,N

A valid partially filled sudoku file might look like:

7,8,0,0,9,0,0,2,0
1,0,0,0,0,0,9,6,4
0,0,0,2,5,1,0,0,0
0,0,6,1,8,5,0,0,0
5,0,4,0,0,0,3,0,2
0,0,0,3,4,2,5,0,0
0,0,0,9,6,3,0,0,0
6,4,1,0,0,0,0,0,3
0,9,0,0,1,0,0,5,7

I've already created the three example sudoku boards provided in SudokuTest. They are listed below.

Solving the Puzzle

The Solve button takes the current state of the board and:

  • Produces a 2d integer array representing the sudoku board in accordance with the assignment
  • Passes that array to Sudoku.fillSudoku
  • Checks the return status of fillSudoku
  • Displays "Solution found" if a valid solution was found and updates the board
  • Displays "Solution NOT found" if a solution is not found and does not update the board
Link to a Sudoku solver algorithm

Sudoku Solver Algorithm - Authored by Michael Dunn

Board Validity

The Verify button takes the current state of the board and:

  • Produces a 2d integer array representing the sudoku board in accordance with the assignment
  • Passes that array to Sudoku.checkSudoku
  • Checks the return status of checkSudoku
  • Displays "Sudoku rules do hold." if the current state of the board doesn't violate any invariants
  • Displays "Sudoku rules do NOT hold." if the current state of the board does violate invariants
  • Remember that cells with a "0" in them are not checked

Altering the Board State

It would be best if the user simply loaded files and hit the Solve button. However, users can hit the Unlock button which will allow them to edit the board directly (rather than through an algorithm).

Keep in mind that I didn't include any error checking or validation with editing the text fields directly. This means that you can enter items that are not a digit (0-9), and the results of doing so are undefined.

Clone this wiki locally