Class

IpuzNonogram

Description [src]

class Ipuz.Nonogram : Ipuz.Grid
{
  /* No available fields */
}

A nonogram is a picture-based logic puzzle in which the player uses hints on the edge of the puzzle to reveal a picture.

Example of a nonogram Example of a solved nonogram

Nonograms can either be monochrome or have color groups. Monochrome puzzles are more common, but both are suppported. Color nonograms are represented by IpuzNonogramColor, which is a subclass of IpuzNonogram.

Warning

Nonogram puzzles are currently a libipuz-only extension. As such, it’s not currently expected that other programs will be able to parse them.

Representation

The IpuzCellType is used to determine whether an IpuzCell is filled in or blank. If it’s a BLOCK, then it’s filled in, while NORMAL indicates a blank cell. A NULL cell could indicate a shaped puzzle, though is not traditionally used with nonograms. In addition, the solution field is set to IpuzPuzzle:block, though can generally be ignored with monochromatic puzzles.

The cell’s IpuzStyle is set by default to a background of black, although puzzle authors can override it.

Other fields in the cell are undefined.

See IpuzNonogramColor for information on how color nonograms are represented.

Guesses

Nonograms use the following convention with an IpuzGuesses struct to record player progress solving a puzzle in its grid:

  • A guess of IpuzPuzzle:block is used to indicate a block was guessed correctly. This defaults to the string "#"
  • A guess of IpuzNonogram:space is used to indicate that a cell has been eliminated as a possible block. This defaults to the string ".".
  • A guess of NULL is used to indicate that the player has yet to determine if a cell is a block or not.

IpuzNonogram also uses the stride_guess of the guesses struct to keep track of whether the cells for the number hints have been found. This is required for nonogram implementations that let the user manually cross off numbers.

The stride guess should be a UTF-8 string with the same number of characters as the number of hints in that row/column. By convention, it uses the IpuzPuzzle:block and IpuzPuzzle:empty properties to indicate if a number has been crossed off or not.

To make it easier to work with the stride, the following convenience functions are provided:

Guesses Example

For example, consider the following row being guessed from a nonogram puzzle:

Example of a nonogram guess row A row guessed from a nonogram

In this example, the guess strings in the row would be set to:

[ NULL, ".", NULL, ".", "#", "#", "#", "#", ".", NULL ]

And the stride_guess for that row would be:

// The stride guesses are 1 and 4 in this example
"0#"

This indicates that the blocks for the number 4 have been found and should be rendered as being eliminated.

Editing

Nonograms have one fix function — ipuz_nonogram_fix_clues(). This should be called after any changes to block polarity or grouping. It will update the internal clues and styles.

Note that not every grid can be uniquely solved as a nonogram. Some nonogram puzzles can result in multiple valid solutions. When creating a nonogram, care must be taken to be sure it’s solvable.

Descendants

Constructors

ipuz_nonogram_new

Returns a newly created nonogram puzzle.

Instance methods

ipuz_nonogram_fix_clues

Fixes the clues of self to match the current grid state.

ipuz_nonogram_get_cells_by_group

Returns all the cells that are set to group. For monochrome nonograms, the group should be IpuzPuzzle:block.

ipuz_nonogram_get_clues

Returns an array containing the run of IpuzNonogramClue indicated by index and direction.

ipuz_nonogram_get_count_crossed_off

Returns TRUE if the number identified by the arguments should be crossed off. This function is essentially a wrapper around parsing the stride_guess directly.

ipuz_nonogram_get_group

Returns the group at index.

ipuz_nonogram_get_n_groups

Returns the number of different groups within self.

ipuz_nonogram_get_space

Returns the text value that represents a space in IpuzGuesses. That is to say, a cell that has been eliminated from possibly being a block.

ipuz_nonogram_print

Prints self to stdout. This method is meant to be used for debugging.

ipuz_nonogram_set_count_crossed_off

Crosses off a number within the guesses in the IpuzGuesses associated with self.

ipuz_nonogram_set_space

Sets the text value that represents a space. That is to say, a cell that has been eliminated from possibly being a block.

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 GObject (43)

Please see GObject for a full list of methods.

Properties

Ipuz.Nonogram:space

The text value that represents a space in the saved file.

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 IpuzNonogramClass {
  IpuzGridClass parent_class;
  
}

The class structure for IpuzNonograms.

Class members
parent_class: IpuzGridClass

The grid class structure representing the parent.