pub struct CellLoc { /* private fields */ }
Expand description
Represents a cell location in the board.
CellLoc structures are a shallow abstraction of the indice of the cell in the board, using them allows access helper functions to navigate the board and access each cell by a more intuitive line/column pair
Implementations§
source§impl CellLoc
impl CellLoc
sourcepub fn at(l: usize, c: usize, board_size: BoardSize) -> Self
pub fn at(l: usize, c: usize, board_size: BoardSize) -> Self
Returns a cell representing the location at line l
and column c
.
The third argument represents the size of the board.
use sudokugen::BoardSize;
use sudokugen::board::CellLoc;
let cell = CellLoc::at(0, 0, BoardSize::NineByNine);
assert_eq!(cell.line(), 0);
assert_eq!(cell.col(), 0);
sourcepub fn new(idx: usize, board_size: BoardSize) -> Self
pub fn new(idx: usize, board_size: BoardSize) -> Self
Reference a new location in the board. idx
is the 0 based flat ordering of all cells
in the board.
use sudokugen::board::CellLoc;
use sudokugen::BoardSize;
let cell = CellLoc::new(9, BoardSize::NineByNine);
assert_eq!((cell.line(), cell.col()), (1, 0));
sourcepub fn get_index(&self) -> usize
pub fn get_index(&self) -> usize
Returns the 0 based flat index of this cell location
use sudokugen::BoardSize;
use sudokugen::board::CellLoc;
let cell = CellLoc::new(9, BoardSize::NineByNine);
assert_eq!(cell.get_index(), 9);
sourcepub fn get_possible_values(&self, board: &Board) -> Option<BTreeSet<u8>>
pub fn get_possible_values(&self, board: &Board) -> Option<BTreeSet<u8>>
Given a board this returns all the possible values for this cell location
within that board.
If the cell is not empty then it returns None
use sudokugen::board::CellLoc;
use sudokugen::{Board, BoardSize};
let cell = CellLoc::at(0, 1, BoardSize::FourByFour);
let board: Board = "
1 . | . .
. . | . .
---------
. 2 | . .
. . | . .
".parse().unwrap();
assert_eq!(cell.get_possible_values(&board), Some(vec![3, 4].into_iter().collect()));
sourcepub fn line(&self) -> usize
pub fn line(&self) -> usize
Returns the 0 based line number for this cell location
use sudokugen::board::CellLoc;
use sudokugen::BoardSize;
let cell = CellLoc::at(0, 0, BoardSize::NineByNine);
assert_eq!(cell.line(), 0);
sourcepub fn col(&self) -> usize
pub fn col(&self) -> usize
Returns the 0 based column number for this cell location
use sudokugen::BoardSize;
use sudokugen::board::CellLoc;
let cell = CellLoc::at(0, 0, BoardSize::NineByNine);
assert_eq!(cell.col(), 0);
sourcepub fn square(&self) -> usize
pub fn square(&self) -> usize
Returns the 0 based square number for this cell location. Squares are numbered line first and then columns.
use sudokugen::BoardSize;
use sudokugen::board::CellLoc;
let cell = CellLoc::at(4, 3, BoardSize::NineByNine);
assert_eq!(cell.square(), 4);
sourcepub fn iter_line(&self) -> impl Iterator<Item = CellLoc>
pub fn iter_line(&self) -> impl Iterator<Item = CellLoc>
Iterates over all cells in the same line as this one.
use sudokugen::board::CellLoc;
use sudokugen::BoardSize;
let cell = CellLoc::at(0, 0, BoardSize::FourByFour);
assert_eq!(
cell.iter_line().collect::<Vec<CellLoc>>(),
vec![
CellLoc::at(0, 0, BoardSize::FourByFour),
CellLoc::at(0, 1, BoardSize::FourByFour),
CellLoc::at(0, 2, BoardSize::FourByFour),
CellLoc::at(0, 3, BoardSize::FourByFour),
]
);
sourcepub fn iter_col(&self) -> impl Iterator<Item = CellLoc>
pub fn iter_col(&self) -> impl Iterator<Item = CellLoc>
Iterates over all cells in the same column as this one.
use sudokugen::board::CellLoc;
use sudokugen::BoardSize;
let cell = CellLoc::at(0, 0, BoardSize::FourByFour);
assert_eq!(
cell.iter_col().collect::<Vec<CellLoc>>(),
vec![
CellLoc::at(0, 0, BoardSize::FourByFour),
CellLoc::at(1, 0, BoardSize::FourByFour),
CellLoc::at(2, 0, BoardSize::FourByFour),
CellLoc::at(3, 0, BoardSize::FourByFour),
]
);
sourcepub fn iter_square(&self) -> impl Iterator<Item = CellLoc>
pub fn iter_square(&self) -> impl Iterator<Item = CellLoc>
Iterates over all cells in the same square as this one.
use sudokugen::board::CellLoc;
use sudokugen::BoardSize;
let cell = CellLoc::at(0, 0, BoardSize::FourByFour);
assert_eq!(
cell.iter_square().collect::<Vec<CellLoc>>(),
vec![
CellLoc::at(0, 0, BoardSize::FourByFour),
CellLoc::at(0, 1, BoardSize::FourByFour),
CellLoc::at(1, 0, BoardSize::FourByFour),
CellLoc::at(1, 1, BoardSize::FourByFour),
]
);
Trait Implementations§
source§impl Ord for CellLoc
impl Ord for CellLoc
source§impl PartialEq for CellLoc
impl PartialEq for CellLoc
source§impl PartialOrd for CellLoc
impl PartialOrd for CellLoc
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl Copy for CellLoc
impl Eq for CellLoc
impl StructuralPartialEq for CellLoc
Auto Trait Implementations§
impl Freeze for CellLoc
impl RefUnwindSafe for CellLoc
impl Send for CellLoc
impl Sync for CellLoc
impl Unpin for CellLoc
impl UnwindSafe for CellLoc
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
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>
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>
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