[−][src]Struct sudoku_variants::Sudoku
A Sudoku represents a grid of numbers with an associated constraint. The numbers may or may not fulfill the constraint, but there is a method to check it.
There is no guarantee that the Sudoku is uniquely solveable or even
solveable at all, however there are ways to check that (see the solver
module).
Implementations
impl<C: Constraint + Clone> Sudoku<C>
[src]
pub fn new_empty(
block_width: usize,
block_height: usize,
constraint: C
) -> SudokuResult<Sudoku<C>>
[src]
block_width: usize,
block_height: usize,
constraint: C
) -> SudokuResult<Sudoku<C>>
Creates a new Sudoku with the provided constraint and an empty grid
of the given dimensions. The total width and height of the grid will be
equal to the product of block_width
and block_height
.
Arguments
block_width
: The horizontal dimension of one sub-block of the grid. To ensure a square grid, this is also the number of blocks that compose the grid vertically. For an ordinary Sudoku grid, this is 3. Must be greater than 0.block_height
: The vertical dimension of one sub-block of the grid. To ensure a square grid, this is also the number of blocks that compose the grid horizontally. For an ordinary Sudoku grid, this is 3. Must be greater than 0.constraint
: The constraint which is checked by this Sudoku. Grid configurations which violate this constraint will be seen as invalid by Sudoku.is_valid.
Errors
If block_width
or block_height
is invalid (zero).
pub fn new_with_grid(grid: SudokuGrid, constraint: C) -> Sudoku<C>
[src]
Creats a new Sudoku with the provided constraint and a given grid, which may already contain some numbers. Note that it is not checked whether the given grid fulfills the constraint - it is perfectly legal to create an invalid Sudoku here.
Arguments
grid
: The initial SudokuGrid which contains the numbers with which the Sudoku is filled.constraint
: The constraint which is checked by this Sudoku. Grid configurations which violate this constraint will be seen as invalid by Sudoku.is_valid.
pub fn parse(code: &str, constraint: C) -> SudokuParseResult<Sudoku<C>>
[src]
Parses the code into a SudokuGrid using SudokuGrid::parse and wraps the result in a Sudoku with the given constraint. Note that it is not required that the code matches the constraint. It is perfectly legal to parse an invalid Sudoku.
Arguments
code
: The code that specifies the grid. See SudokuGrid::parse for a language specification.constraint
: The constraint which is checked by this Sudoku. Grid configurations which violate this constraint will be seen as invalid by Sudoku.is_valid.
Errors
If the parsing fails. See SudokuGrid::parse for further information.
pub fn grid(&self) -> &SudokuGrid
[src]
Gets a reference to the SudokuGrid
of this Sudoku.
pub fn grid_mut(&mut self) -> &mut SudokuGrid
[src]
Gets a mutable reference to the SudokuGrid
of this Sudoku.
pub fn is_valid(&self) -> bool
[src]
Indicates whether the entire grid matches the constraint.
pub fn is_valid_cell(&self, column: usize, row: usize) -> SudokuResult<bool>
[src]
Indicates whether the cell at the given location matches the
constraint. That is, if the specified cell violates the constraint,
false
is returned, and true
otherwise.
Arguments
column
: The column (x-coordinate) of the checked cell. Must be in the range[0, size[
.row
: The row (y-coordinate) of the checked cell. Must be in the range[0, size[
.
pub fn is_valid_number(
&self,
column: usize,
row: usize,
number: usize
) -> SudokuResult<bool>
[src]
&self,
column: usize,
row: usize,
number: usize
) -> SudokuResult<bool>
Indicates whether the given number would be valid in the cell at the
given location. That is, if the number violated the constraint, false
is returned, and true
otherwise.
Arguments
column
: The column (x-coordinate) of the checked cell. Must be in the range[0, size[
.row
: The row (y-coordinate) of the checked cell. Must be in the range[0, size[
.number
: The number to check whether it is valid in the given cell.
Errors
SudokuError::OutOfBounds
If eithercolumn
orrow
are not in the specified range.SudokuError::InvalidNumber
Ifnumber
is not in the specified range.
pub fn is_valid_solution(&self, solution: &SudokuGrid) -> SudokuResult<bool>
[src]
Indicates whether the given SudokuGrid is a
valid solution to this puzzle. That is the case if all digits from this
Sudoku can be found in the solution
, it matches the constraint of
this Sudoku, and it is full.
Errors
If the dimensions of this Sudoku's grid and the solution
grid are not
the same. In that case, SudokuError::InvalidDimensions
is returned.
Trait Implementations
impl<C: Clone + Constraint> Clone for Sudoku<C>
[src]
Auto Trait Implementations
impl<C> RefUnwindSafe for Sudoku<C> where
C: RefUnwindSafe,
C: RefUnwindSafe,
impl<C> Send for Sudoku<C> where
C: Send,
C: Send,
impl<C> Sync for Sudoku<C> where
C: Sync,
C: Sync,
impl<C> Unpin for Sudoku<C> where
C: Unpin,
C: Unpin,
impl<C> UnwindSafe for Sudoku<C> where
C: UnwindSafe,
C: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,