...
Milestone 2 Due: Friday 22 April 2011 at 9:59:59 am
Tip: Out of Memory Error
Try the following: Go to Edit/Preferences/Micellaneous/JVMs
and add the -Xss64M
option to the "JVM Args for Interactions JVM
" line to increase th amount of memory used.
The Sudoku Game
Sudoku is a 9x9 grid-based puzzle in which the goal is to place numbers from 1 to 9 in the grid squares taking into account specific constraints. The 9 x 9 puzzle grid can be seen as divided into 9 sub-grids of size 3x3. The 3 main conditions in the classic version of Sudoku state are that each square in the grid contains a number from 1 to 9 and a number cannot be repeated:
...
The purpose of this assignment is to build a Java solver that finds all one of the different any possible solutions of the game using a constraint-based approach.
...
- An empty board is fully determined by a single value, it's "
order
", which for a 9x9 board is 3. - The board is viewable in terms of rows, columns and blocks.
- Each row, column and block has exactly
order
2
cells, e.g. fororder
= 3, each row, column and block has 9 cells. - Each board has exactly
order
2
rows, columns and blocks.
- Each row, column and block has exactly
- Each cell is a member of exactly one row, one column and one block.
- No rows share the same cell. Likewise, no columns or blocks share cells. This forces the square matrix layout of rows, columns, and
order
^2
sub-matrix of blocks if one were to display the rows, columns and blocks where each cell is only shown once.
- No rows share the same cell. Likewise, no columns or blocks share cells. This forces the square matrix layout of rows, columns, and
- The rules of Sudoku stipluate that the value in any given cell has very specific constraints:
The valid values are {{Wiki Markup 1...order
{}}}{{{}{^}2{^}}} (2
(inclusive), e.g. for order=2, the allowed values are \ [1, 2, 3, 4\]- Any valid value in a cell cannot appear in another cell in the row, column or block to which that cell belongs. Conversely, each row, column or block must contain every valid value exactly once.
...
Note: Your Sudoku solver should be able to solve a completely blank puzzle (all dashes, not empty)!
Programming Tips
Updating the View
At the end of the reduceBoard
and solve
methods, be sure to add the line
...
Code Block |
---|
final int[] x = new int[]{0}; final ICell[] aCell = new ICell[]{ new Cell() }; |
An anonymous inner class can thus access these variables by using the array syntax: {{x\[0\]}} and {{aCell\[0\]}} An anonymous inner class can thus access these variables by using the array syntax: Wiki Markup x[0]
and aCell[0]
You may find that in order to keep track of several properties as you loop through cells and cell sets, that you may need to create multiple one-element array values.
...
Your code must work for ANY order puzzle! (To within machine limits, of course.)
Testing Procedures
...
The supplied code contains a simple test routine that gives you examples on how to instantiate a {{GameModel
}}, {\[Board}} and test them.
It is reasonable to test your code by the following process:
...
(10 pts) Incorporate the supplied GeneratePuzzle
utility capability into the main Sudoku solver, both in the view and the model, to enable the user to generate and solve any of the 50,000 supplied puzzles. Remember that the view and the model MUST be kept separate--the only way they can communicate is via IModelAdapter
and IViewAdapter
, their respective adapters. Neither GameFrame
nor GameModel
may contain a reference to the other! (It is actually possible to add this feature without modifying GameModel
at all, though you are not required to do this.)
...