You're reading the documentation for a development version. For the latest released version, please have a look at master.
queens_reasoner.reasoner
Functions
|
Eliminate queen candidates using whole-row/column color coverage. |
|
Deduce queen positions from single-candidate rows or columns. |
|
Deduce queen positions from single-color constraints. |
|
Generate a mask for a single queen placement. |
|
Reduce a list of masks to their consensus. |
|
Apply multi-color constraint reasoning. |
|
Yield subsets where the union of rows or columns is minimal. |
Module Contents
- queens_reasoner.reasoner.update_mask_whole_row_col(mat, mask)[source]
Eliminate queen candidates using whole-row/column color coverage.
If a single color index occupies an entire row or column (excluding elements that are already ruled out), then all other cells with the same color index outside that row or column cannot contain queens. Such cells are set to 0 in the returned mask.
- Parameters:
mat (np.ndarray) – 2D integer matrix of color indices.
mask (np.ndarray) – 2D mask matrix. Cells that cannot contain queens are set to 0.
- Returns:
Updated mask matrix.
- Return type:
np.ndarray
- queens_reasoner.reasoner.update_mask_other_row_col(mat, mask)[source]
Deduce queen positions from single-candidate rows or columns.
If all other candidate positions in a row or column are ruled out except one remaining position, that position must be a queen. After marking a queen, conflicting positions are eliminated.
- Mask values:
-1: candidate / unknown0: cannot be queen1: confirmed queen
- Parameters:
mat (np.ndarray) – 2D color matrix.
mask (np.ndarray) – 2D mask matrix.
- Returns:
Updated mask matrix.
- Return type:
np.ndarray
- queens_reasoner.reasoner.update_mask_single_color(mat, mask)[source]
Deduce queen positions from single-color constraints.
For each color with no confirmed queen, considers all possible queen placements and identifies cells that must or cannot contain a queen.
- Parameters:
mat (np.ndarray) – 2D integer matrix of color indices.
mask (np.ndarray) – 2D mask matrix.
- Returns:
Updated mask matrix.
- Return type:
np.ndarray
- queens_reasoner.reasoner.gen_mask_single_queen(shape, row, col)[source]
Generate a mask for a single queen placement.
Marks the given position as a queen (1) and eliminates all conflicting positions in the same row, column, and diagonally adjacent cells.
- Parameters:
shape (tuple[int, int]) – Board shape as
(rows, cols).row (int) – Row index of the queen.
col (int) – Column index of the queen.
- Returns:
Mask matrix with queen and non-queen positions marked.
- Return type:
np.ndarray
- Raises:
AssertionError – If
roworcolis out of bounds.
- queens_reasoner.reasoner.reduce_masks(masks)[source]
Reduce a list of masks to their consensus.
At each position, if all masks agree on the value, keep it; otherwise set to -1 (unknown).
- Parameters:
masks (list[np.ndarray]) – List of ndarrays with identical shapes.
- Returns:
Reduced mask.
- Return type:
np.ndarray
- queens_reasoner.reasoner.update_mask_multi_color(mat, mask)[source]
Apply multi-color constraint reasoning.
If k colors have all their possible queen positions confined to k rows or k columns, then other colors cannot place queens in those rows or columns.
- Parameters:
mat (np.ndarray) – 2D integer matrix of color indices.
mask (np.ndarray) – 2D mask matrix.
- Returns:
Updated mask matrix.
- Return type:
np.ndarray
- queens_reasoner.reasoner.iter_min_subset(lst)[source]
Yield subsets where the union of rows or columns is minimal.
For each k from 1 to n, examines all k-combinations of arrays and yields those where the number of unique rows or unique columns is at most k.
- Parameters:
lst (list[np.ndarray]) – List of 2D position arrays, each with shape
(N, 2)where columns are[row, col].- Yields:
tuple[str, tuple[int], tuple[int]] – A tuple of
(orientation, unique_indices, selected_array_indices)where orientation is"row"or"column".- Return type:
collections.abc.Iterator[tuple[str, tuple[int], tuple[int]]]