Class
IpuzCrossword
Description [src]
class Ipuz.Crossword : Ipuz.Grid
implements Ipuz.Clues {
/* No available fields */
}
Crosswords are a word puzzle consisting of a grid of open cells and blocks into which answers are written. It has clues in both the Across and Down directions to lead the solver to the answer. Crosswords are frequently symmetric, and use numbers to identify clues.
The IpuzCrossword
class is intended to model Standard
Crosswords. These are also sometimes known as American
Crosswords or Traditional Crosswords.
As a matter of convention, standard crosswords tend to have shorter
clues and denser grids. The example above is a good representative
example of what a dense grid could look like. It also features
cells with IpuzStyle
s to set circles around some of the letters.
Representation
Grid
Crosswords are built with a grid of IpuzCell
s. These can
be accessed through the parent class of IpuzGrid
. The
cell_type
of the cell determines how the cell is interpreted:
IPUZ_CELL_NORMAL
— A normal light cell. This contains a solution for the player to figure out and fill in.IPUZ_CELL_BLOCK
— A block. This will separate clues and contains no letters.IPUZ_CELL_NULL
— An null cell. Similar to blocks, it also separates clues and contains no letters. However, it is omitted during rendering
Note
A null cell can be used to make a shaped puzzle. This is less common than regular crosswords. But as an interesting sidenote, that the very first crossword was shaped and uses nulls to render correctly.
Clues
Clues can be accessed through the IpuzClues
interface. In
general, IpuzEnumeration
s are not used with these
clues. As a result, IpuzCrossword:show-enumerations
is
FALSE
by default.
While not required, it’s generally a good idea to store the
coordinates associated with a clue. If it doesn’t exist, they can
be inferred using ipuz_crossword_fix_clues()
.
Guesses
When used with an IpuzGuesses
object, guesses are tested
against the solution of the cell to indicate a block was guessed
correctly. Block and null cells are mirrored in the guesses but are
generally ignored.
Variants
The IpuzCrossword
class was written to model standard
crosswords and its _fix()
functions enforce those
conventions. However, it’s possible to use this class to represent
variants of the standard crossword. Common ones (such as
IpuzArrowword
and IpuzBarred
) have dedicated
subclasses for them. Others can be done by manually modifying the puzzle.
As some examples:
- Cross figures: Use strings of numbers instead of letters
- Rebus crosswords: multi-character words in the solution field of cells
Editing
The IpuzCrossword
class has five different fix functions
to help maintain conventions.
ipuz_crossword_fix_symmetry()
: Makes the grid symmetric with respect tocell_type
.ipuz_crossword_fix_numbering()
: Updates the numbering of cells to match clue numbersipuz_crossword_fix_clues()
: Makes sure a clue exists for each numberipuz_crossword_fix_enumerations()
: Makes sure an enumeration for each clue existsipuz_crossword_fix_styles()
: Removes unused styles
In addition, there is a ipuz_crossword_fix_all()
method that
will call these all sequentially. It is not available to language bindings.
Instance methods
ipuz_crossword_check_mirror
Checks the cell at dest_coord
to see if it’s the symmetric
opposite of the cell at src_coord
. For normal crosswords, this
just checks that the cell_type
is the same, and symmetry is
largely ignored. However, for barred crosswords this implementation
is quite complex as it needs to rotate and adjust the bars.
ipuz_crossword_clue_continues_down
Returns TRUE
if the down clue crossing coord
can be continued down.
ipuz_crossword_clue_continues_left
Returns TRUE
if the down clue crossing coord
can be continued left.
ipuz_crossword_clue_continues_right
Returns TRUE
if the down clue crossing coord
can be continued right.
ipuz_crossword_fix_all
Convenience function for calling all the _fix()
functions in
crosswords sequentially. This is not available for language bindings.
ipuz_crossword_fix_clues
Ensures that there are IpuzClue
s for every sequenctial
run of across or down normal cells of two or more. This will
potentially add or remove existing clues as necessary.
ipuz_crossword_fix_enumerations
Ensures that every clue has an enumeration if
IpuzCrossword:show-enumerations
is set to TRUE
. If not
set already set, an enumeration the apparent length of the clue
will be created.
ipuz_crossword_fix_numbering
Goes through all the normal cells in the grid and calculates the numbers for clues. This will clear any existing numbers or labels associated with cells.
ipuz_crossword_fix_styles
Clears empty IpuzStyle
s from all the cells in self
. See
ipuz_style_is_empty()
for more information on empty styles.
ipuz_crossword_fix_symmetry
Enforce the board symmetry of the cells in summetry_coords
in the
direction of symmetry
. That is to say, go through each cell in
symmetry_coords
and make sure that the appropriate cell at the
point(s) of symmetry have the same IpuzCellType
.
ipuz_crossword_get_clue_placement
Returns an indication of how to display the clues relative to the grid.
ipuz_crossword_get_solution_chars
Returns an IpuzCharset
consisting of all the characters
in the puzzle.
ipuz_crossword_mirror_cell
Makes the cell at dest_coord
match the appearance of the cell at
src_coord
while maintaining symmetry. For normal crosswords, this
just matches their cell_type
and symmetry is largely
ignored. However, for barred crosswords this implementation is
quite complex as it needs to rotate and adjust the bars to keep symmetry.
ipuz_crossword_set_clue_placement
Sets an indication of how to display the clues relative to the grid.
Methods inherited from IpuzGrid (11)
ipuz_grid_check_cell
Invokes the operation determined by check_type
on cell
and
guesses
at coord
.
ipuz_grid_check_stride
Invokes the operation determined by check_type
on the stride guess
determined by direction
and index
.
ipuz_grid_create_guesses
Creates a fresh IpuzGuesses
. It will be initialized to
the current state of the grid.
ipuz_grid_fix_guesses
Fixes the guesses associated with self
. The result will be a
playable IpuzGuesses
struct.
ipuz_grid_foreach_cell
Calls func
for each IpuzCell
in self
.
ipuz_grid_get_cell
Retrieves the cell at coord
. If the coordinates are
outside the bounds of the grid then NULL
will be returned.
ipuz_grid_get_guesses
Returns the IpuzGuesses
associated with self
.
ipuz_grid_get_height
Returns the number of rows in self
.
ipuz_grid_get_width
Returns the number of columns in self
.
ipuz_grid_resize
Resizes self
to the new size.
ipuz_grid_set_guesses
Sets guesses
for self
. If there’s a mismatch in the cell types
between guesses
and self
then FALSE
is returned. guesses
will
be set regardless of the return value.
Methods inherited from IpuzPuzzle (55)
Please see IpuzPuzzle for a full list of methods.
Methods inherited from IpuzClues (18)
ipuz_clues_add_clue_set
Adds a new clue set to clues
. This clue set will be in the
direction of direction
, and will be empty. If label
is set, then
it will set the label of the newly created clue set.
ipuz_clues_clear_clue_sets
Removes all the clues and clue sets of clues
.
ipuz_clues_clue_guessed
Returns TRUE
if clue
has a user guess for every cell. If all the
user guesses are correct, then correct
is set to TRUE
as well.
ipuz_clues_clue_set_get_dir
Returns the direction of the clueset at index
.
ipuz_clues_clue_set_get_label
Returns the label of the clueset at direction
.
ipuz_clues_find_clue_by_coord
[ RETHINK THIS FUNCTION. CANT WE GET IT FROM THE CELL?].
ipuz_clues_find_clue_by_label
Searches for and returns the clue with direction
and label
.
ipuz_clues_find_clue_by_number
Searches for and returns the clue with direction
and number
.
ipuz_clues_foreach_clue
Calls func
for each IpuzClue
in clues
.
ipuz_clues_get_clue_by_id
Returns the clue at clue_id
, or NULL
.
ipuz_clues_get_clue_string_by_id
Returns a string containing the solution of the puzzle for a given clue. This string will have ‘?’ characters embedded within it if there are cells without solutions set yet.
ipuz_clues_get_clues
Returns an array of all clues in the direction of direction
.
ipuz_clues_get_guess_string_by_id
Returns a string containing the guess in the puzzle for a given clue. This string will have ‘?’ characters embedded within it if there are cells not completely filled out.
ipuz_clues_get_id_by_clue
Finds the IpuzClueId
of clue
within clues
.
ipuz_clues_get_n_clue_sets
Returns the number of clue sets associated with clues
.
ipuz_clues_get_n_clues
Returns the number of clues in direction
.
ipuz_clues_remove_clue
Removes clue
from clues
. The clue will also be unlinked from the grid.
ipuz_clues_remove_clue_set
Removes the clue set in the direction of direction
. All the clues
associated with that clue set will be unreffed.
Properties
Properties inherited from IpuzGrid (3)
Ipuz.Grid:guesses
The IpuzGuesses
associated with the grid.
Ipuz.Grid:height
Number of rows in the grid.
Ipuz.Grid:width
Number of columns in the grid.
Properties inherited from IpuzPuzzle (24)
Ipuz.Puzzle:annotation
Non-displayed annotation.
Ipuz.Puzzle:author
Author of the puzzle.
Ipuz.Puzzle:block
The text value that represents a block in the saved file.
Ipuz.Puzzle:charset
Characters that can be entered in the puzzle. Setting this
explicitly will override the charset defined by
IpuzPuzzle:locale
.
Ipuz.Puzzle:charset-str
Characters that can be entered in the puzzle, in string form.
Setting this explicitly will override the charset defined by
IpuzPuzzle:locale
.
Ipuz.Puzzle:copyright
Copyright information for the puzzle.
Ipuz.Puzzle:date
Date of puzzle or publication date.
Ipuz.Puzzle:difficulty
Difficulty of the puzzle. Advisory only, as there is no standard for difficulty.
Ipuz.Puzzle:editor
Editor of the puzzle.
Ipuz.Puzzle:empty
Text value that represents an empty cell.
Ipuz.Puzzle:explanation
Text to be displayed after a successful solve.
Ipuz.Puzzle:intro
Text displayed above the puzzle.
Ipuz.Puzzle:license
License of the puzzle.
Ipuz.Puzzle:locale
Locale of the puzzle.
Ipuz.Puzzle:notes
Notes about the puzzle.
Ipuz.Puzzle:origin
Program-specific information about the program that wrote the puzzle file.
Ipuz.Puzzle:publication
Bibliographic reference for a published puzzle.
Ipuz.Puzzle:publisher
Name and/or reference for a publisher.
Ipuz.Puzzle:puzzle-kind
The kind type of the puzzle.
Ipuz.Puzzle:styles
A GHash
table containing all the named styles for the puzzle. These can be added or removed by calling ipuz_puzzle_set_style()
.
Ipuz.Puzzle:title
Title of the puzzle.
Ipuz.Puzzle:uniqueid
Globally unique identifier for the puzzle.
Ipuz.Puzzle:url
Permanent URL for the puzzle.
Ipuz.Puzzle:version
Version of the ipuz spec used for the puzzle.
Signals
Signals inherited from GObject (1)
GObject::notify
The notify signal is emitted on an object when one of its properties has its value set through g_object_set_property(), g_object_set(), et al.
Class structure
struct IpuzCrosswordClass {
IpuzGridClass parent_class;
void (* fix_symmetry) (
IpuzCrossword* self,
IpuzSymmetry symmetry,
GArray* symmetry_coords
);
void (* fix_numbering) (
IpuzCrossword* self
);
void (* fix_clues) (
IpuzCrossword* self
);
void (* fix_enumerations) (
IpuzCrossword* self
);
void (* fix_styles) (
IpuzCrossword* self
);
void (* fix_all_valist) (
IpuzCrossword* self,
va_list var_args
);
gboolean (* clue_continues_up) (
IpuzCrossword* self,
const IpuzCellCoord* coord
);
gboolean (* clue_continues_down) (
IpuzCrossword* self,
const IpuzCellCoord* coord
);
gboolean (* clue_continues_left) (
IpuzCrossword* self,
const IpuzCellCoord* coord
);
gboolean (* clue_continues_right) (
IpuzCrossword* self,
const IpuzCellCoord* coord
);
void (* mirror_cell) (
IpuzCrossword* self,
const IpuzCellCoord* src_coord,
const IpuzCellCoord* dest_coord,
IpuzSymmetry symmetry,
IpuzSymmetryOffset symmetry_offset
);
gboolean (* check_mirror) (
IpuzCrossword* self,
const IpuzCellCoord* src_coord,
const IpuzCellCoord* dest_coord,
IpuzSymmetry symmetry,
IpuzSymmetryOffset symmetry_offset
);
}
The class structure for IpuzCrossword
s.
Class members
parent_class: IpuzGridClass
The grid class structure representing the parent.
fix_symmetry: void (* fix_symmetry) ( IpuzCrossword* self, IpuzSymmetry symmetry, GArray* symmetry_coords )
Vfunc that enforces the board symmetry of the cells in
summetry_coords
in the direction ofsymmetry
.fix_numbering: void (* fix_numbering) ( IpuzCrossword* self )
Vfunc that goes through all the normal cells in the grid and calculates the numbers for clues. This will clear any existing numbers or labels associated with cells.
fix_clues: void (* fix_clues) ( IpuzCrossword* self )
Vfunc that ensures that there are
IpuzClue
s for every sequenctial run of across or down normal cells of two or more. This will potentially add or remove existing clues as necessary.fix_enumerations: void (* fix_enumerations) ( IpuzCrossword* self )
Vfunc that ensures that every clue has an enumeration if
IpuzCrossword:show-enumerations
is set toTRUE
. If not set already set, an enumeration the apparent length of the clue will be created.fix_styles: void (* fix_styles) ( IpuzCrossword* self )
Vfunc that clears empty
IpuzStyle
s from all the cells.fix_all_valist: void (* fix_all_valist) ( IpuzCrossword* self, va_list var_args )
Convenience vfunc for calling all the
_fix()
functions in crosswords sequentially. This is not available for language bindings.clue_continues_up: gboolean (* clue_continues_up) ( IpuzCrossword* self, const IpuzCellCoord* coord )
Vfunc that returns
TRUE
if the down clue crossingcoord
can be continued up.clue_continues_down: gboolean (* clue_continues_down) ( IpuzCrossword* self, const IpuzCellCoord* coord )
Vfunc that returns
TRUE
if the down clue crossingcoord
can be continued down.clue_continues_left: gboolean (* clue_continues_left) ( IpuzCrossword* self, const IpuzCellCoord* coord )
Vfunc that returns
TRUE
if the down clue crossingcoord
can be continued left.clue_continues_right: gboolean (* clue_continues_right) ( IpuzCrossword* self, const IpuzCellCoord* coord )
Vfunc that returns
TRUE
if the down clue crossingcoord
can be continued right.mirror_cell: void (* mirror_cell) ( IpuzCrossword* self, const IpuzCellCoord* src_coord, const IpuzCellCoord* dest_coord, IpuzSymmetry symmetry, IpuzSymmetryOffset symmetry_offset )
Vfunc that makes the cell at
dest_coord
match the appearance of the cell atsrc_coord
while maintaining symmetry.check_mirror: gboolean (* check_mirror) ( IpuzCrossword* self, const IpuzCellCoord* src_coord, const IpuzCellCoord* dest_coord, IpuzSymmetry symmetry, IpuzSymmetryOffset symmetry_offset )
Vfunc that checks the cell at
dest_coord
to see if it’s the symmetric opposite of the cell atsrc_coord
.
Virtual methods
Ipuz.CrosswordClass.check_mirror
Checks the cell at dest_coord
to see if it’s the symmetric
opposite of the cell at src_coord
. For normal crosswords, this
just checks that the cell_type
is the same, and symmetry is
largely ignored. However, for barred crosswords this implementation
is quite complex as it needs to rotate and adjust the bars.
Ipuz.CrosswordClass.clue_continues_down
Returns TRUE
if the down clue crossing coord
can be continued down.
Ipuz.CrosswordClass.clue_continues_left
Returns TRUE
if the down clue crossing coord
can be continued left.
Ipuz.CrosswordClass.clue_continues_right
Returns TRUE
if the down clue crossing coord
can be continued right.
Ipuz.CrosswordClass.clue_continues_up
Returns TRUE
if the down clue crossing coord
can be continued up.
Ipuz.CrosswordClass.fix_all_valist
Convenience vfunc for calling all the _fix()
functions in crosswords sequentially. This is not available for
language bindings.
Ipuz.CrosswordClass.fix_clues
Ensures that there are IpuzClue
s for every sequenctial
run of across or down normal cells of two or more. This will
potentially add or remove existing clues as necessary.
Ipuz.CrosswordClass.fix_enumerations
Ensures that every clue has an enumeration if
IpuzCrossword:show-enumerations
is set to TRUE
. If not
set already set, an enumeration the apparent length of the clue
will be created.
Ipuz.CrosswordClass.fix_numbering
Goes through all the normal cells in the grid and calculates the numbers for clues. This will clear any existing numbers or labels associated with cells.
Ipuz.CrosswordClass.fix_styles
Clears empty IpuzStyle
s from all the cells in self
. See
ipuz_style_is_empty()
for more information on empty styles.
Ipuz.CrosswordClass.fix_symmetry
Enforce the board symmetry of the cells in summetry_coords
in the
direction of symmetry
. That is to say, go through each cell in
symmetry_coords
and make sure that the appropriate cell at the
point(s) of symmetry have the same IpuzCellType
.
Ipuz.CrosswordClass.mirror_cell
Makes the cell at dest_coord
match the appearance of the cell at
src_coord
while maintaining symmetry. For normal crosswords, this
just matches their cell_type
and symmetry is largely
ignored. However, for barred crosswords this implementation is
quite complex as it needs to rotate and adjust the bars to keep symmetry.