Trait sudoku_variants::constraint::RelativeCellConstraint [−][src]
A trait for Constraint
s that are defined by having no forbidden numbers
in some relative configuration to the reference cell. Whether a number is
forbidden is defined by RelativeCellConstraint::is_forbidden, which is a
boolean relation between the reference cell and the other cell. By default,
this checks for equality.
As an example, the constraint that no diagonally adjacent cells have the
same number may be formulated as a RelativeCellConstraint
with the
relative coordinates [(-1, -1), (-1, +1), (+1, -1), (+1, +1)]
, with the
default equality being used for is_forbidden
.
Associated Constants
const RELATIVE_COORDINATES: &'static [(isize, isize)]
[src]
A slice of coordinates relative to the cell in question that must not contain the same number.
Provided methods
fn is_forbidden(&self, reference_cell: usize, other_cell: usize) -> bool
[src]
Given the contents of the reference cell and one other cell that is removed by one set of coordinates specified in RelativeCellConstraint::RELATIVE_COORDINATES, this method determines whether the reference cell violates the constraint. Since it is assumed that an empty cell cannot violate the constraint, this method is only called if both cells contain a number.
As an example, for ordinary constraints such as the no-knight’s-move- constraint, this is usually an equality check. A cell removed by a knight’s move may not be equal to the reference cell. This is actually the default behavior for this method.
However, in some situations this may be different. As an example, for the no-adjacent-consecutive-constraint, this is a predicate that determines whether the two numbers are consecutive.
Arguments
reference_cell
: The cell which is currently tested, i.e. relative to which the coordinates are defined.other_cell
: A cell removed from thereference_cell
by a set of coordinates from RelativeCellConstraint::RELATIVE_COORDINATES.