[−][src]Struct sudoku_backend::ops::SudokuBoard
Refer to doc/sudoku.md
for more details.
Fields
id: Option<i32>
Unique board ID.
Actually not optional, but this allows us to get an ID from the database.
full_board: String
The full "solved" board repr.
difficulty: i32
Board "difficulty", between one and three.
creation_time: NaiveDateTime
Time the board was generated.
Methods
impl SudokuBoard
[src]
impl SudokuBoard
pub fn new(difficulty: BoardDifficulty) -> SudokuBoard
[src]
pub fn new(difficulty: BoardDifficulty) -> SudokuBoard
Create a new, unique, sudoku board.
Put it in the database to get an ID.
pub fn get(id: i32, db: &SqliteConnection) -> Result<SudokuBoard, &'static str>
[src]
pub fn get(id: i32, db: &SqliteConnection) -> Result<SudokuBoard, &'static str>
Retrieve the board with the specified ID.
Examples
Given:
INSERT INTO "sudoku_boards"
VALUES(
1,
'269574813534918726781263594395846271478129365126357948857491632913682457642735189',
3,
'2018-08-01 23:50:14');
The following holds:
let board = SudokuBoard::get(1, &db).unwrap(); assert_eq!(board, SudokuBoard { id: Some(1), full_board: "269574813534918726781263594395846271478129365126357948857491632913682457642735189".to_string(), difficulty: 3, creation_time: NaiveDate::from_ymd(2018, 8, 1).and_hms(23, 50, 14), });
pub fn insert(&mut self, db: &SqliteConnection) -> Result<(), &'static str>
[src]
pub fn insert(&mut self, db: &SqliteConnection) -> Result<(), &'static str>
Insert this board into the specified DB, updating its id.
Examples
Assuming empty table:
let mut board = SudokuBoard::new(difficulty); assert!(board.id.is_none()); board.insert(&db).unwrap(); assert_eq!(board.id, Some(1));
After, example:
INSERT INTO "sudoku_boards"
VALUES(
1,
'269574813534918726781263594395846271478129365126357948857491632913682457642735189',
3,
'2018-08-01 23:50:14');
pub fn generate_skeleton(&self) -> Result<String, SudokuLineFormatParseError>
[src]
pub fn generate_skeleton(&self) -> Result<String, SudokuLineFormatParseError>
Get а board skeleton adjusted for the difficulty.
Quoth the Raven Animu_x63
:
The absolute measures of sudoku difficulty are the average sparsity of squares (over all gamestates) that can logically be resolved, and the maximum amount of logical deductions required to fill in the easiest square along states leading to the solution.
But that's hard. However:
Most other measurements of difficulty are just arbitrary and you can approximate difficult by sparsity.
And that is what we do here: get a unique solution, then partially fill it back in according to
BoardDifficulty::additional_squares()
.
Examples
let easy_board = SudokuBoard::new(BoardDifficulty::Easy); let easy_skeleton = easy_board.generate_skeleton().unwrap(); let medium_board = SudokuBoard::new(BoardDifficulty::Medium); let medium_skeleton = medium_board.generate_skeleton().unwrap(); assert!( easy_skeleton.chars().filter(|&c| c != '.').count() > medium_skeleton.chars().filter(|&c| c != '.').count()); let hard_board = SudokuBoard::new(BoardDifficulty::Hard); let hard_skeleton = hard_board.generate_skeleton().unwrap(); assert!(medium_skeleton.chars().filter(|&c| c != '.').count() > hard_skeleton.chars().filter(|&c| c != '.').count());
Trait Implementations
impl PartialEq<SudokuBoard> for SudokuBoard
[src]
impl PartialEq<SudokuBoard> for SudokuBoard
fn eq(&self, other: &SudokuBoard) -> bool
[src]
fn eq(&self, other: &SudokuBoard) -> bool
fn ne(&self, other: &SudokuBoard) -> bool
[src]
fn ne(&self, other: &SudokuBoard) -> bool
impl Clone for SudokuBoard
[src]
impl Clone for SudokuBoard
fn clone(&self) -> SudokuBoard
[src]
fn clone(&self) -> SudokuBoard
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl Ord for SudokuBoard
[src]
impl Ord for SudokuBoard
fn cmp(&self, other: &SudokuBoard) -> Ordering
[src]
fn cmp(&self, other: &SudokuBoard) -> Ordering
fn max(self, other: Self) -> Self
1.21.0[src]
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
impl Eq for SudokuBoard
[src]
impl Eq for SudokuBoard
impl PartialOrd<SudokuBoard> for SudokuBoard
[src]
impl PartialOrd<SudokuBoard> for SudokuBoard
fn partial_cmp(&self, other: &SudokuBoard) -> Option<Ordering>
[src]
fn partial_cmp(&self, other: &SudokuBoard) -> Option<Ordering>
fn lt(&self, other: &SudokuBoard) -> bool
[src]
fn lt(&self, other: &SudokuBoard) -> bool
fn le(&self, other: &SudokuBoard) -> bool
[src]
fn le(&self, other: &SudokuBoard) -> bool
fn gt(&self, other: &SudokuBoard) -> bool
[src]
fn gt(&self, other: &SudokuBoard) -> bool
fn ge(&self, other: &SudokuBoard) -> bool
[src]
fn ge(&self, other: &SudokuBoard) -> bool
impl Debug for SudokuBoard
[src]
impl Debug for SudokuBoard
impl Hash for SudokuBoard
[src]
impl Hash for SudokuBoard
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl Serialize for SudokuBoard
[src]
impl Serialize for SudokuBoard
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
impl<'de> Deserialize<'de> for SudokuBoard
[src]
impl<'de> Deserialize<'de> for SudokuBoard
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
impl<'insert> Insertable<table> for SudokuBoard
[src]
impl<'insert> Insertable<table> for SudokuBoard
type Values = <(Option<Eq<id, i32>>, Option<Eq<full_board, String>>, Option<Eq<difficulty, i32>>, Option<Eq<creation_time, NaiveDateTime>>) as Insertable<table>>::Values
The VALUES
clause to insert these records Read more
fn values(self) -> Self::Values
[src]
fn values(self) -> Self::Values
fn insert_into(
self,
table: T
) -> InsertStatement<T, Self::Values, Insert, NoReturningClause>
[src]
fn insert_into(
self,
table: T
) -> InsertStatement<T, Self::Values, Insert, NoReturningClause>
Insert self
into a given table. Read more
impl<'insert> Insertable<table> for &'insert SudokuBoard
[src]
impl<'insert> Insertable<table> for &'insert SudokuBoard
type Values = <(Option<Eq<id, &'insert i32>>, Option<Eq<full_board, &'insert String>>, Option<Eq<difficulty, &'insert i32>>, Option<Eq<creation_time, &'insert NaiveDateTime>>) as Insertable<table>>::Values
The VALUES
clause to insert these records Read more
fn values(self) -> Self::Values
[src]
fn values(self) -> Self::Values
fn insert_into(
self,
table: T
) -> InsertStatement<T, Self::Values, Insert, NoReturningClause>
[src]
fn insert_into(
self,
table: T
) -> InsertStatement<T, Self::Values, Insert, NoReturningClause>
Insert self
into a given table. Read more
impl<__DB: Backend, __ST> Queryable<__ST, __DB> for SudokuBoard where
(Option<i32>, String, i32, NaiveDateTime): Queryable<__ST, __DB>,
[src]
impl<__DB: Backend, __ST> Queryable<__ST, __DB> for SudokuBoard where
(Option<i32>, String, i32, NaiveDateTime): Queryable<__ST, __DB>,
type Row = <(Option<i32>, String, i32, NaiveDateTime) as Queryable<__ST, __DB>>::Row
The Rust type you'd like to map from. Read more
fn build(row: Self::Row) -> Self
[src]
fn build(row: Self::Row) -> Self
impl<'update> AsChangeset for &'update SudokuBoard
[src]
impl<'update> AsChangeset for &'update SudokuBoard
type Target = table
The table which Self::Changeset
will be updating
type Changeset = <(Eq<full_board, &'update String>, Eq<difficulty, &'update i32>, Eq<creation_time, &'update NaiveDateTime>) as AsChangeset>::Changeset
The update statement this type represents
fn as_changeset(self) -> Self::Changeset
[src]
fn as_changeset(self) -> Self::Changeset
impl<'update> AsChangeset for SudokuBoard
[src]
impl<'update> AsChangeset for SudokuBoard
type Target = table
The table which Self::Changeset
will be updating
type Changeset = <(Eq<full_board, String>, Eq<difficulty, i32>, Eq<creation_time, NaiveDateTime>) as AsChangeset>::Changeset
The update statement this type represents
fn as_changeset(self) -> Self::Changeset
[src]
fn as_changeset(self) -> Self::Changeset
impl<'insert> UndecoratedInsertRecord<table> for SudokuBoard
[src]
impl<'insert> UndecoratedInsertRecord<table> for SudokuBoard
Auto Trait Implementations
impl Send for SudokuBoard
impl Send for SudokuBoard
impl Sync for SudokuBoard
impl Sync for SudokuBoard
Blanket Implementations
impl<T> From for T
[src]
impl<T> From for T
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
impl<T, U> TryFrom for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId
[src]
fn get_type_id(&self) -> TypeId
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
impl<T> BorrowMut for T where
T: ?Sized,
[src]
impl<T> BorrowMut for T where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
fn borrow_mut(&mut self) -> &mut T
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
impl<T> Typeable for T where
T: Any,
[src]
impl<T> Typeable for T where
T: Any,
impl<T> IntoSql for T
[src]
impl<T> IntoSql for T
fn into_sql<T>(self) -> Self::Expression where
Self: AsExpression<T>,
[src]
fn into_sql<T>(self) -> Self::Expression where
Self: AsExpression<T>,
Convert self
to an expression for Diesel's query builder. Read more
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression where
&'a Self: AsExpression<T>,
[src]
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression where
&'a Self: AsExpression<T>,
Convert &self
to an expression for Diesel's query builder. Read more