For this assignment, you will write both a Java application and an
applet to solve Sudoku puzzles. A Sudoku puzzle requires logic alone
to solve and is very amenable to computer solution. In case you
haven't seen one before, consider the following example (courtesy
Milwaukee Journal Sentinel):
(ignore the letters
,
and
)
| 3 | 9 | 5 | ||||||
| 5 | 8 | 9 | 2 | |||||
| 2 | 5 | |||||||
| 6 | 2 | 7 | ||||||
| 8 | 4 | 5 | 3 | |||||
| 7 | 1 | 6 | ||||||
| 3 | 6 | |||||||
| 5 | 6 | 2 | 7 | |||||
| 8 | 3 | 1 |
For this assignment you will write a Sudoku solver that uses at least these strategies to solve problems. The Sudoku solver will have two interfaces: one command-line and textual and the other graphical.
Undergraduate students may work in teams of 2 for this homework. Use AFS to give both of you permission to access a homework directory before you start work.
The first task for this homework is to write a Sudoku solver that works as a Java command-line application. It will read in a Sudoku problem file (named on the command-line) which uses a simple format to express the boards. An example of the format is the following
___ 395 ___which is for the board shown on the first page of this homework.
__5 __8 9_2
___ _2_ __5
6_2 ___ __7
_84 ___ 53_
7__ ___ 1_6
3__ _6_ ___
5_6 2__ 7__
___ 831 ___
The solver will consist of applying strategies to the board (in order, the easiest first) until one is able to find a spot to solve. A strategy thus has the following definition:
public interface SudokuCellStrategy {(The ``intelligence'' level is one, two or three respectively for strategies
/**
* Try a Sudoku strategy. Return a solution for
* a cell, or null if nothing can be done
* @return cell solution if done, or null if no work possible
*/
public abstract SudokuCellSolution work(SudokuBoard board);
/**
* Return the "intelligence" level of this strategy
* @return intelligence level of strategy.
*/
public abstract int getLevel();
}
Your SudokuSolver class should be neutral with respect to whether the program is textual or an applet. The specifically textual part of the program (opening files and printing boards) should be done in a separate class TextSudokuSolver. This class should print the board at the beginning and after every step.
The second part of your homework is writing an animation applet that accepts a Sudoku problem as an applet parameter and then solves it graphically. It should also handle the other parameters (such as ``delay'') to indicate the speed of doing the puzzle.
You will need to use the refactoring of the animation applet hierarchy
done in lecture. These files will be available in the
$CLASSHOME/src/lecture/ directory as usual. Delay starting on
this part until you have finished the textual Sudoku solver.
As well as solving the problem step by step, you should also use color
to indicate the ``intelligence'' level of the strategy that was used
to fill in the digit. It also desirable, but not required, that
alternate 3x3 boxes be shaded darker. The method darker() in
the Color class is useful here. (The pale green used in the
solution is defined as Color(192,255,192).)
An important aspect of this part of the Homework in ensuring that the two solvers share all code that is used for solving problems and only need to provide the medium-specific aspects.
Please put your Java files for your solution in a package named
sudoku in your homework3 directory, except for the
strategies themselves which should be in a package
sudoku.strategy.
Some major parts of the Homework are already done for you:
the Sudoku board class itself, as well as the two helper classes
SudokuCellStrategy
(already shown in this homework) and SudokuCellSolution.
In particular, you will not need to write the code to parse the Sudoku
board format.
We also provide several Sudoku problems for your textual solver (files
with a prb extension) and for your applet solver (files with a
html extension). These files are all in the
$CLASSHOME/src/homework3 directory.
Both projects must be runnable from within their respective directories. In other words, on a grid, it must be possible to
grid.cs: cd homework3/bin grid.cs: java sudoku/TextSudokuSolver ../2005-10-4.prb ... grid.cs: appletviewer Sudoku95.htmlAs usual, all work must be completed by 12:30pm, Tuesday, October 16th.