Base Encodings
noqx.puzzle
Definitions of the base encodings.
Modules:
Classes:
-
Color–Enumeration for colors.
-
Direction–Enumeration for directions.
-
Puzzle–Base class for puzzle encodings.
Functions:
-
Point–A factory function to create a point tuple.
Color
Enumeration for colors.
-
Currently, only one color can be shaded on a single cell. Each cell can be categorized into two types, shaded or unshaded. The unshaded cells are represented by the green color, while the shaded cells can be either gray or black to distinguish region edges.
-
For compatiblity issue with the web version, the enumeration class is altered to a simple class.
Attributes:
-
WHITE(int) –Represents the white color on shaded cells or unshaded cells.
-
GRAY(int) –Represents the gray color on shaded cells.
-
BLACK(int) –Represents the black color on shaded cells.
-
BLUE(int) –Represents the blue color on shaded cells or unshaded cells, mostly for water-relevant puzzles.
-
DARK(Tuple[int, int]) –A tuple representing dark colors (gray and black).
Source code in noqx/puzzle/__init__.py
Direction
Enumeration for directions.
-
This
Directionenumeration involves with the relative direction between the elements (i.e., edges, lines, arrows, etc.) and the center of a cell. Currently, it supports the following directions: center, top, left, bottom, right, top-left (downwards-diagonal), top-right (upwards-diagonal), bottom-left, and bottom-right. -
For edge visualizations, the upwards-diagonal and downwards-diagonal directions are transformed into the top-right and top-left directions respectively.
-
For compatiblity issue with the web version, the enumeration class is altered to a simple class.
Attributes:
-
CENTER(str) –The center direction. This is the default direction for most cells. Using this direction will not have effects on visualizations.
-
TOP(str) –The top direction. This indicates something is on the top side of a cell. Also, this direction is used for horizontal edge visualizations.
-
LEFT(str) –The left direction. This indicates the something is on the left side of a cell.Also, this direction is used for vertical edge visualizations.
-
BOTTOM(str) –The bottom direction. This indicates the something is on the bottom side of a cell.
-
RIGHT(str) –The right direction. This indicates the something is on the right side of a cell.
-
TOP_LEFT(str) –The top-left/downwards-diagonal direction. This indicates the something is on the top-left side of a cell.
-
TOP_RIGHT(str) –The top-right/upwards-diagonal direction. This indicates the something is on the top-right side of a cell.
-
BOTTOM_LEFT(str) –The bottom-left direction. This indicates the something is on the bottom-left side of a cell.
-
BOTTOM_RIGHT(str) –The bottom-right direction. This indicates the something is on the bottom-right side of a cell.
-
TOP_BOTTOM(str) –The top-bottom direction. This indicates something is on both the top and bottom sides of a cell.
-
LEFT_RIGHT(str) –The left-right direction. This indicates something is on both the left and right sides of a cell.
Source code in noqx/puzzle/__init__.py
Puzzle
Base class for puzzle encodings.
- The
decodeandencodemethod should be implemented in an inherited class, such as thePenpaPuzzle.
Methods:
-
__init__–Initialize the puzzle.
-
clear–Clear the puzzle structure.
-
decode–Decode the source content to a puzzle object.
-
encode–Encode the puzzle object to the target content.
Source code in noqx/puzzle/__init__.py
__init__
Initialize the puzzle.
-
The atom element of a puzzle is a cell, and the data structures are all crafted around a cell. In detail, a puzzle has the following elements:
puzzle_name: the name of the puzzle, should be the same as the filename of the solver.param: the parameters of the puzzle.row: the number of rows in the puzzle.col: the number of columns in the puzzle.margin: the margin of the puzzle, the order is a tuple of (top-margin,bottom-margin,left-margin,right-margin).surface: the shaded cells in the puzzle stored in a dictionary.text: the text clues in the puzzle stored in a dictionary.symbol: the symbols in the puzzle stored in a dictionary.edge: the borders in the puzzle stored in a dictionary.line: the lines in the puzzle stored in a dictionary.
Parameters:
-
(namestr) –The name of the puzzle.
-
(contentstr) –The content of the puzzle.
-
(paramOptional[Dict[str, Any]], default:None) –Optional parameters for the puzzle.
Source code in noqx/puzzle/__init__.py
clear
Clear the puzzle structure.
- This function is often used before initializating a new solver instance.
decode
Decode the source content to a puzzle object.
Raises:
-
NotImplementedError–If this method is not implemented.
encode
Encode the puzzle object to the target content.
Raises:
-
NotImplementedError–If this method is not implemented.
Point
A factory function to create a point tuple.
-
For compatiblity issue with the web version, the NamedTuple class is altered to a factory function.
-
The label descriptor is used for elements inside an cell. Common labels include:
normal: The normal label. This is the default label for most elements. Using this label will not have effects on visualizations.tapa_x: The tapa label with index x (x = 0 ~ 3). This label is often used for tapa-like clues to indicate their positions inside a cell.corner_x: The corner label with index its direction x. This label is often used for sudoku-like clues to indicate a number in the corner inside a cell.arrow_x: The arrow label with index its direction x. This label is often used for yaji-like clues to indicate an arrow in the cell.multiple: The symbol label with style x (x = 0 ~ n). This label is often used for indicating multiple symbols inside a cell.delete: The delete label. This label is often used for erased edges.- other labels may be defined in specific puzzles, such as
hashiandnondango.
Parameters:
-
(rint) –The row index of the point.
-
(cint) –The column index of the point.
-
(dstr, default:CENTER) –The direction of the point (default is
Direction.CENTER). -
(labelstr, default:'normal') –The label of the point (default is
"normal").