Introduction to Computer Science II

Project 8 for 2007-Dec-12

Sudoku solver


The game of Sudoku

Sudoku is (I am told) an old game that is currently quite popular and giving crossword puzzles a run for their money in newspapers. It's a game well suited for computers because it is a matter of finding legal placements for numbers on the board.

The game: Sudoku is played on a 9 x 9 grid. Initially, a few of the cells of that grid contain a numbers, all integers between 1 and 9. The goal for the player is to fill in the remaining cells of the grid, also with integers between 1 and 9, given the following constraints:

A valid Sudoku game begins with initial numbers that, when combined with the constraints above, admit exactly one complete solution. That is, the initial numbers cannot make it impossible to fill in the board legal, nor can they allow multiple solutions.


Part A

The first part of your project is to write a Sudoku verifier. That is, you must write a method that accepts an allegedly solved Sudoku grid and then verifies whether the solution is valid.

For this part of the project, you will be given three pre-made solvers. One of the solvers works correctly, the other two do not. You must use your verifier to determine which solver works. You should also try to figure out in what way the other two solvers fail.

Details: This program is split into a number of files. Some of them are code that I have written that you will simply use. Others are files that you must modify or write.

Files that you need: You must copy some files from my directory to get started on this project:

cp -v ~sfkaplan/public/cs12/project-8/*.* .

Here is a quick description of the files:

Running the program: Once you have written a Verifier class, you can compile your .java files and run the program like so:

java -server Sudoku sudoku.board A

First, note the use of -server. The (unsatisfying) explanation for this addition is that it will make the program run faster -- I'll explain how during lab. Second, note the two command-line arguments passed to the program. sudoku.board is the name of the file that contains the initial description of the board, and A is the name of the solver to use (that is, this example will call on SolverA to compute a solution).

HINT: Before you change the check method in Verifier.java, try compiling all of the .java files and running the program. It should work, and you can see how the thing is going to operate. Then begin modifying the check method so that it actually performs its intended task.


Part B

As described above, there is an additional, fourth solver, namely SolverX. Armed with a working verifier, you should now write your own solve method within SolverX.java. It will accept an initial grid (as an int[][]), and its job it then to fill in the empty cells of the grid with values. Your method must of course obey the constraints on those values, thus producing a correct solution.


What you must submit

Part A: Use the cs12-submit command to turn in your Verifier.java file as project-8a. Also submit a text file named observations.txt that indicates which solver you think is the correct one. Also describe what types of errors the two flawed solvers produce.

Part B: Use the cs12-submit command to turn in your SolverX.java file as project-8b.


Both Parts A and B are due Wednesday, 2007-Dec-12, at 11:59 pm

Scott F. H. Kaplan
Last modified: Mon Dec 3 13:24:18 EST 2007