[][src]Struct sudoku_backend::ops::SudokuBoard

pub struct SudokuBoard {
    pub id: Option<i32>,
    pub full_board: String,
    pub difficulty: i32,
    pub creation_time: NaiveDateTime,
}

Refer to doc/sudoku.md for more details.

Fields

Unique board ID.

Actually not optional, but this allows us to get an ID from the database.

The full "solved" board repr.

Board "difficulty", between one and three.

Time the board was generated.

Methods

impl SudokuBoard
[src]

Create a new, unique, sudoku board.

Put it in the database to get an ID.

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),
});

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');

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 Clone for SudokuBoard
[src]

Performs copy-assignment from source. Read more

impl Ord for SudokuBoard
[src]

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

impl Eq for SudokuBoard
[src]

impl PartialOrd<SudokuBoard> for SudokuBoard
[src]

impl Debug for SudokuBoard
[src]

impl Hash for SudokuBoard
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl Serialize for SudokuBoard
[src]

impl<'de> Deserialize<'de> for SudokuBoard
[src]

impl<'insert> Insertable<table> for SudokuBoard
[src]

The VALUES clause to insert these records Read more

Insert self into a given table. Read more

impl<'insert> Insertable<table> for &'insert SudokuBoard
[src]

The VALUES clause to insert these records Read more

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]

The Rust type you'd like to map from. Read more

impl<'update> AsChangeset for &'update SudokuBoard
[src]

The table which Self::Changeset will be updating

The update statement this type represents

impl<'update> AsChangeset for SudokuBoard
[src]

The table which Self::Changeset will be updating

The update statement this type represents

impl<'insert> UndecoratedInsertRecord<table> for SudokuBoard
[src]

Auto Trait Implementations

impl Send for SudokuBoard

impl Sync for SudokuBoard

Blanket Implementations

impl<T> From for T
[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]

impl<T> Typeable for T where
    T: Any
[src]

Get the TypeId of this object.

impl<T> IntoSql for T
[src]

Convert self to an expression for Diesel's query builder. Read more

Convert &self to an expression for Diesel's query builder. Read more