CS 340 - Software Design

Spring 2006


MP 1 - Sudoku Solver

Due: Thursday January 26, 2006 at 11:59 pm
Turnin will be disable on the morning of 1/30/2006.

Note: "MP" stands for "Machine Problem". This is an another term for a programming assignment.

Sudoku is a puzzle that often uses a 9x9 grid of 81 squares. The grid is divided into rows, columns and boxes. The boxes are 3x3 sub-grids of 9 squares. Thus each row, column and box contains 9 squares. The object is the fill in the numbers from 1 to 9 so that each row, column and box contain each number from 1 to 9 only once. For more information, check out the wikipedia entry for Sudoku. Note that the wikipedia uses the term "region" instead of "box". The following is an example of such a puzzle.

When solving a sudoku puzzle, the solver attempts to find a situation that will resolve (or help resolve) a value in a square. For this assignment, your solver only needs to find the following situations as defined in the Step-by-Step Guide to Solving Sudoku by Angus Johnson.

The general algorithm that most solvers use (and that will be expected for this program) is to begin with a list of all possible values (i.e. 1 through 9) in each square of the grid. This list is often called the candidate list. As each square is resolved, remove that value from the candidate list for the squares that share a row, column or box with the square that is resolved. For a nice application that can show a Sudoku puzzle being solved check out Sudoku Solver by Logic. You can step thought the resolution of all 81 squares using this page. The default puzzle on the page will show examples of recognizing the situations of singles, hidden singles/values and locked candidates.

The four situations

Description of Input and Output

The input for your program will be an ASCII text file that will have 3 values per line:
  1. a row position (listed first)
  2. a column position (listed second)
  3. a value (listed last)
This information will give the beginning layout of the puzzle. The filename is to be given to the program using a command line argument. If any of the row, columns or values is outside of the range from 1 to 9, print an appropriate error message and ignore that line of input for the puzzle. If the input attempts to place a value in a square that is invalid (the value is not one of the values contained in the square's candidate list), print an appropriate error message and ignore that line of input for the puzzle. Below are some example data files:

Once the puzzle is read in, the initial state of the puzzle is to be displayed to standard output in a 9x9 grid. The squares that need to be resovled should listed with a period.

When the program has finished working on the puzzle, it is to display a message whether the puzzled was completely solved or not and then it is to print out the final state of the puzzle. This will be done by printing the puzzle in a 9x9 format. If the puzzle was not completely solved, the squares that still need to be resolved should be listed with a period as was done with the initial state of the puzzle.

Your program is also to allow a flag of -v on the command line to put the program in verbose mode. When run in this mode, your program is to print out to standard output some message about each situation that is being resolved. If the puzzle is solved by the program, at least 81 messages would be displayed. This message must specify the situation that is being resolved, the row and column of the square(s) involved and the value(s) involved. If this command line value is not given, this information should not be displayed by your program.

Your program is also to allow a flag of -o on the command line. When this flag is used the final state of the puzzle is to be written to a file. The filename would be given as the command line argument immediately following the -o flag. The format of this output should be the same as the format used to read in a puzzle (an ASCII text file that will have 3 values per line: a row position, a column position and a value).

Submission of the Program

Your program is to be submitted electronically via the turnin command on the LINUX machines. The project name for this is mp1. All programs are expected to be written in good programming style.

Turnin your program electronically using the "turnin" command from your CS account as follows:

turnin -c cs340 -p mp1  [your project directory]
where the [your project directory] is the directory name under which you have all your files related to this programming problem. The turnin command will automatically compress the data under your directory, so there is no need to do the compression by yourself.

Notice you can only invoke turnin command on the Linux machines in the lab or after logging into the server machine oscar.cs.uic.edu.

If you want to verify that your project was turned in, look in the turnin directory for a file with your userid. For instance for this project, from your CS account you would type:

turnin -c cs340 -p mp1 -v

Note that you can execute turnin as many times as you would like, up until the program deadline when turnin will be disabled for this project. Each time you execute turnin for a project, you overwrite all of what you had turned in previously for that project. It does not work in an incremental way.

CS 340 - Fall 2005