Comp211 HW11 Supporting Code Details
Core Data Structures
The main data structures are represented by only a few interfaces:
ICell
-- a single square on the Sudoku board.- A cell has a set of integer values, which are accessible either as a
HashSet<Integer>
- A cell also has a collection (Vector<ICell>) of
ICellSets
to which it belongs. These are the cell's row, column and block, in that order.- Don't forget that the cell is also a member of every ICellSet that it references.
- A cell can be in one of three logical states:
- Empty - there are no values contained in the cell. This corresponds to the situation where the board is unsolvable because a cell has no possible value.
Solved - the cell contains exactly one value. If and only if you know for sure that the cell is in this state, then the single value can be accessed as
aCell.getValueArray()[0]
.- Unsolved - the cell contains multiple possible values. At most, a cell could contain
order*order
values.
Cell
is a concrete implementation ofICell
.- An
ICell
accepts anICellVisitor
which has cases for each of the 3 logical states, described above.- The
ACellVisitor
class is an abstract convenience class that provide a default return value for any cases that the developer does not which to override. There is no requirement to use this class, though it may simplify certain code.
- The
- A cell has a set of integer values, which are accessible either as a
ICellSet
-- A collection ofICells
that represents a row, column or block.- For convenience sake, the cells are in a distinct order (i.e. left-to right for a row) and thus each cell is addressable by an index value.
- An
ICellSet
isIterable
which means that it can be used in for-each loops, e.g. {{for(ICell c : aCellSet) { ... } }}
Board
-- A set of 3 Vector<ICellSet>'s where each element of the vector is anICellSet
. These vectors represent the entire set of rows, columns or blocks in a game.- A
Board
has the ability to make a "deep" copy of itself, where everything, all the way down to the individual cells, is copied. This is theclone()
method. - The
Board
also has a utility method for generating empty cell sets, which is used during initialization.
- A
Utility Data Structures
Model-View-Controller Architecture
Puzzle Generation Utilities