Here is an entity-relationship diagram illustrating the relationships between puzzles, cells, and slots.
We represent the puzzle internally using instances of four corresponding classes.
An instance of class
the entire puzzle, and contains the primary logic for
solving it. It is a container for a collection of
multiple cells, slots, and words.
Cell instance represents the location
of one cell of the puzzle. A given cell may be related
to two slots (if it is the intersection between a
horizontal slot and a vertical slot), or it may be
related to only one slot.
Slot instance represents the location
of one word slot in the puzzle.
Word instance represents one of the
words that fits in some slot.
To describe the geometry of the puzzle, we will use row and
column indexes. An instance of helper class
Coord represents one location in the puzzle as a
row index and a column index, both counting from zero.
The upper left corner of the puzzle is row 0, column 0.
For various reasons, we'll define a complete ordering
Coord instances. This
ordering is the usual scan order for European languages:
starting in the upper left corner, across the first row,
then left to right in the second row, and so on.
We also define a complete ordering for
Slot instances. Slots are ordered according to the row and
column coordinates of their first cell, with their
orientation as a secondary key: if two slots share the
same first cell, the horizontal slot is considered
before the vertical slot. We define numbers for
the two orientations: 0 for horizontal, 1 for vertical.