Interface

IpuzClues

Description [src]

interface Ipuz.Clues : Ipuz.Grid

An interface to access and modify the clues of a crossword-like puzzle. It is intended to be used with IpuzClue clues only, and will not work with other clue types.

Clue Sets

The IpuzClues interface is organized around the concept of clue sets. Clue sets have an ordered list of clues, and are identified by an IpuzClueDirection. In general, it’s expected to have one clue set in a given physical direction. It is possible to have multiple clue sets with the same direction, but they must have different labels.

Here is an examples of adding clues to a standard crossword from scratch:

IpuzPuzzle *puzzle;

puzzle = ipuz_crossword_new ();

...

// Add across and down clue sets to a grid
ipuz_clues_clue_add_clue_set (IPUZ_CLUES (puzzle), IPUZ_CLUE_DIRECTION_ACROSS, NULL);
ipuz_clues_clue_add_clue_set (IPUZ_CLUES (puzzle), IPUZ_CLUE_DIRECTION_DOWN, NULL);

// Add a clue in the across direction
ipuz_clues_append_clue (IPUZ_CLUES (puzzle), IPUZ_CLUE_DIRECTION_ACROSS, clue);

Referring to clue sets

Clue sets are referred to by their direction. Here’s an example of creating a puzzle with two custom clue sets:

// This puzzle has two sets of clues, both spiraling in different directions
cw_direction = ipuz_clues_clue_add_clue_set (clues, IPUZ_CLUE_DIRECTION_CLUES, "Clockwise");
ccw_direction = ipuz_clues_clue_add_clue_set (clues, IPUZ_CLUE_DIRECTION_CLUES, "Counter Clockwise");

// Add a clue who's cells of spiral in the clockwise direction
ipuz_clues_append_clue (clues, cw_direction, clue);

In this example, the direction returned by ipuz_clues_add_clue_set() can be used to work with the clue set later on. They will have different values. In addition, ccw_direction will have a value equal to or greater than IpuzClueDirection.

Itemizing clue sets

It is also possible to iterate through all the clue sets in a puzzle. That can be done through a combination of ipuz_clues_get_n_clue_sets() and ipuz_clues_clue_set_get_dir().

g_print ("Puzzle has the following clue directions:\n")
for (guint i = 0; i < ipuz_clues_get_n_clue_sets (clues))
  {
    IpuzClueDirection direction;
    const gchar *label;

    direction = ipuz_clues_clue_set_get_dir (clues, i);
    label = ipuz_clue_sets_get_direction (direction);
    g_print ("\t%s\n", label);
  }

Note

The index of a clue set is not guaranteed to be stable and should only be used to iterate through all clue sets. It shouldn’t be used to refer to a clue set anywhere else.

Hiden Clue Sets

Most clue sets are displayed to the user. However, there are times that it’s convenient to indicate the cells of clues without revealing them to the users — such as with an alphabetical crossword. In that instance, it’s useful to have a mirror of user visible clues with a direction of IpuzClueDirection.

By convention, these clues are never shown to the user.

Prerequisite

In order to implement Clues, your type must inherit fromIpuzGrid.

Instance methods

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.

Interface structure

struct IpuzCluesInterface {
  GTypeInterface g_iface;
  IpuzClueDirection (* add_clue_set) (
    IpuzClues* clues,
    IpuzClueDirection direction,
    const gchar* label
  );
  void (* remove_clue_set) (
    IpuzClues* clues,
    IpuzClueDirection direction
  );
  void (* clear_clue_sets) (
    IpuzClues* clues
  );
  guint (* get_n_clue_sets) (
    IpuzClues* clues
  );
  IpuzClueDirection (* clue_set_get_dir) (
    IpuzClues* clues,
    guint index
  );
  const gchar* (* clue_set_get_label) (
    IpuzClues* clues,
    IpuzClueDirection direction
  );
  GArray* (* get_clues) (
    IpuzClues* clues,
    IpuzClueDirection direction
  );
  void (* foreach_clue) (
    IpuzClues* clues,
    IpuzCluesForeachClueFunc func,
    gpointer user_data
  );
  guint (* get_n_clues) (
    IpuzClues* clues,
    IpuzClueDirection direction
  );
  IpuzClue* (* get_clue_by_id) (
    IpuzClues* clues,
    IpuzClueId* clue_id
  );
  void (* remove_clue) (
    IpuzClues* clues,
    IpuzClue* clue
  );
  gboolean (* get_id_by_clue) (
    IpuzClues* clues,
    const IpuzClue* clue,
    IpuzClueId* clue_id
  );
  gchar* (* get_clue_string_by_id) (
    IpuzClues* clues,
    IpuzClueId* clue_id
  );
  gchar* (* get_guess_string_by_id) (
    IpuzClues* clues,
    IpuzClueId* clue_id
  );
  gboolean (* clue_guessed) (
    IpuzClues* clues,
    IpuzClue* clue,
    gboolean* correct
  );
  IpuzClue* (* find_clue_by_number) (
    IpuzClues* clues,
    IpuzClueDirection direction,
    gint number
  );
  IpuzClue* (* find_clue_by_label) (
    IpuzClues* clues,
    IpuzClueDirection direction,
    const char* label
  );
  IpuzClue* (* find_clue_by_coord) (
    IpuzClues* clues,
    IpuzClueDirection direction,
    const IpuzCellCoord* coord
  );
  
}
No description available.
Interface members
g_iface
GTypeInterface
 No description available.
add_clue_set
IpuzClueDirection (* add_clue_set) (
    IpuzClues* clues,
    IpuzClueDirection direction,
    const gchar* label
  )
 No description available.
remove_clue_set
void (* remove_clue_set) (
    IpuzClues* clues,
    IpuzClueDirection direction
  )
 No description available.
clear_clue_sets
void (* clear_clue_sets) (
    IpuzClues* clues
  )
 No description available.
get_n_clue_sets
guint (* get_n_clue_sets) (
    IpuzClues* clues
  )
 No description available.
clue_set_get_dir
IpuzClueDirection (* clue_set_get_dir) (
    IpuzClues* clues,
    guint index
  )
 No description available.
clue_set_get_label
const gchar* (* clue_set_get_label) (
    IpuzClues* clues,
    IpuzClueDirection direction
  )
 No description available.
get_clues
GArray* (* get_clues) (
    IpuzClues* clues,
    IpuzClueDirection direction
  )
 No description available.
foreach_clue
void (* foreach_clue) (
    IpuzClues* clues,
    IpuzCluesForeachClueFunc func,
    gpointer user_data
  )
 No description available.
get_n_clues
guint (* get_n_clues) (
    IpuzClues* clues,
    IpuzClueDirection direction
  )
 No description available.
get_clue_by_id
IpuzClue* (* get_clue_by_id) (
    IpuzClues* clues,
    IpuzClueId* clue_id
  )
 No description available.
remove_clue
void (* remove_clue) (
    IpuzClues* clues,
    IpuzClue* clue
  )
 No description available.
get_id_by_clue
gboolean (* get_id_by_clue) (
    IpuzClues* clues,
    const IpuzClue* clue,
    IpuzClueId* clue_id
  )
 No description available.
get_clue_string_by_id
gchar* (* get_clue_string_by_id) (
    IpuzClues* clues,
    IpuzClueId* clue_id
  )
 No description available.
get_guess_string_by_id
gchar* (* get_guess_string_by_id) (
    IpuzClues* clues,
    IpuzClueId* clue_id
  )
 No description available.
clue_guessed
gboolean (* clue_guessed) (
    IpuzClues* clues,
    IpuzClue* clue,
    gboolean* correct
  )
 No description available.
find_clue_by_number
IpuzClue* (* find_clue_by_number) (
    IpuzClues* clues,
    IpuzClueDirection direction,
    gint number
  )
 No description available.
find_clue_by_label
IpuzClue* (* find_clue_by_label) (
    IpuzClues* clues,
    IpuzClueDirection direction,
    const char* label
  )
 No description available.
find_clue_by_coord
IpuzClue* (* find_clue_by_coord) (
    IpuzClues* clues,
    IpuzClueDirection direction,
    const IpuzCellCoord* coord
  )
 No description available.

Virtual methods

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.