pub struct Puzzle { /* private fields */ }
Expand description
This structure represents a generated board and its solution
This struct can only be created by calling the generate
function, which will create
a random board with a unique solution.
Implementations§
source§impl Puzzle
impl Puzzle
sourcepub fn generate(board_size: BoardSize) -> Puzzle
pub fn generate(board_size: BoardSize) -> Puzzle
Generate a new sudoku puzzle with a unique solution.
The generate function creates a random board with a unique solution. It does this by “solving” the empty board using random guesses whenever it cannot find the correct solution. Once the empty board is solved, it iterates over each of the guesses and removes it if that guess is the only valid option for that cell.
use sudokugen::{Puzzle, BoardSize};
let puzzle = Puzzle::generate(BoardSize::NineByNine);
println!("{}", puzzle.board());
println!("{}", puzzle.solution());
sourcepub fn board(&self) -> &Board
pub fn board(&self) -> &Board
Returns the minimal board generated
use sudokugen::{Puzzle, BoardSize};
let gen = Puzzle::generate(BoardSize::NineByNine);
println!("{}", gen.board());
sourcepub fn solution(&self) -> &Board
pub fn solution(&self) -> &Board
Returns the solution for the generated board
use sudokugen::{Puzzle, BoardSize};
let gen = Puzzle::generate(BoardSize::NineByNine);
println!("{}", gen.solution());
sourcepub fn is_solution_unique(&self) -> bool
pub fn is_solution_unique(&self) -> bool
Verify that the solution for the generated board is unique.
use sudokugen::{Puzzle, BoardSize};
let gen = Puzzle::generate(BoardSize::NineByNine);
assert!(gen.is_solution_unique());
Auto Trait Implementations§
impl Freeze for Puzzle
impl RefUnwindSafe for Puzzle
impl Send for Puzzle
impl Sync for Puzzle
impl Unpin for Puzzle
impl UnwindSafe for Puzzle
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more