CPSC 170 Post Lab 9
Sudoku
Due Before Class on Tuesday, March 29th

sudoku puzzle

Sudoku is a puzzle that has been found in most newspapers since it gained popularity in 2005. Typically, the puzzle is played with a 9x9 grid that is subdivided into nine 3x3 boxes. The object of the puzzle is to fill the grid such that the digits 1 to 9 are contained (without repeats) in each row, each column, and each box. Seed digits are initially placed in the grid to define the puzzle and to limit where additional digits can be added by the person solving the puzzle. When trying to solve a Sudoku, people rely on logical reasoning to determine where certain digits can and cannot be placed in the grid.

Details

Create a program that reads a puzzle text file and displays the puzzle in a window. There are two major design decisions that you need to make. The first is how to display the puzzle and get user input. One solution to this is to use GUI components (such as text fields or combo boxes). The advantage of this is that user selection and input is handled by the component. However, you will need to make sure that seed cells can not be changed. Another solution is to draw the puzzle in the paintComponent method using drawLine and drawString. If you choose this implementation you will have to devise a way to allow the user to select a cell (a mouse click or arrow keys for example) and specify a value (number key press or GUI button press).

The other design decision is how and when to provide feedback to the user. One solution would be to give no user input until the last cell is filled in, then verify the user's solution. This would require creating a new method in the puzzle class that could verify an entire puzzle for correctness. Another solution would be to inform the user after each input if a particular move is valid. This would require making the move validation method in the puzzle class public. A third solution would be to inform the user if a particular move is correct. This is possible because there is only one solution to the puzzle. However, it would require creating a method that solves the puzzle (this method would be very similar to the numberOfSolutions method). Information can be supplied to the user either via a dialog box or by drawing text on the window.


Submission: Tar and submit your code on the course blackboard site.

Extra

Scoring

Add score keeping to your program that rewards the player for entering cells both correctly and quickly.

Puzzle Generation

Instead of reading a puzzle from a text file, create a random puzzle every time the program is run. The puzzle generation would proceed very similar to determining the number of solutions to a puzzle. It should choose a random cell and generate a random seed value. If the puzzle has no solutions the cell should be set back to zero and a different random cell should be selected. If the puzzle has multiple solutions then another random cell should be selected. This should proceed until the puzzle has only one solution.