Skip to main content

NonogramGame

Struct NonogramGame 

Source
pub struct NonogramGame {
    pub width: usize,
    pub height: usize,
    pub cells: Vec<CellState>,
    pub row_clues: Vec<Clue>,
    pub col_clues: Vec<Clue>,
    pub status: GameStatus,
    /* private fields */
}
Expand description

The nonogram game state: board dimensions, the hidden solution, the player’s grid, derived clues, and undo/redo history.

There is no losing state — every action is reversible via Self::undo/Self::redo, and the game only ever transitions from GameStatus::Playing to GameStatus::Won (or back, if an undo reverts a winning move).

Fields§

§width: usize

Board width in cells.

§height: usize

Board height in cells.

§cells: Vec<CellState>

Flat row-major grid of the player’s current marks (cells[y * width + x]).

§row_clues: Vec<Clue>

Clue for each row, top to bottom.

§col_clues: Vec<Clue>

Clue for each column, left to right.

§status: GameStatus

Current game status.

Implementations§

Source§

impl NonogramGame

Source

pub fn from_grid(grid: Vec<Vec<bool>>) -> Self

Build a puzzle from an explicit solution grid (row-major, grid[y][x]). Every row must have the same width. Use this for curated/picture puzzles.

§Panics

Panics if grid is empty, any row is empty, or rows have differing lengths.

Source

pub fn random(width: usize, height: usize, density: f32, seed: u64) -> Self

Build a procedurally-generated puzzle: each cell is independently filled with probability density, reproducible via seed. Regenerates until the result isn’t degenerate (not all-empty, not all-filled), so the clues are always meaningful. density is clamped to 0.05..=0.95 — the exact extremes would make a non-degenerate result impossible (and the regeneration loop would never terminate).

§Panics

Panics if width or height is zero.

Source

pub fn reset(&mut self)

Clear the player’s grid and undo/redo history, keeping the same puzzle (solution and clues unchanged). To get a different puzzle, construct a new NonogramGame.

Source

pub fn idx(&self, x: usize, y: usize) -> usize

Source

pub fn is_solution_filled(&self, x: usize, y: usize) -> bool

Whether (x, y) is part of the hidden solution.

Source

pub fn toggle_fill(&mut self, x: usize, y: usize)

Toggle a cell between Filled and Empty (clearing any Crossed mark in the process). This is the left-click action.

Source

pub fn toggle_cross(&mut self, x: usize, y: usize)

Toggle a cell between Crossed and Empty (clearing any Filled mark in the process). This is the right-click action.

Source

pub fn clear_cell(&mut self, x: usize, y: usize)

Directly clear a cell back to Empty.

Source

pub fn fill(&mut self, x: usize, y: usize)

Directly set a cell to Filled, no toggling. Idempotent — a no-op (no undo entry pushed) if the cell is already Filled. Intended for click-and-drag painting, where the same target state is applied to every cell the pointer passes over.

Source

pub fn cross(&mut self, x: usize, y: usize)

Directly set a cell to Crossed, no toggling. Idempotent, for the same click-and-drag painting use case as Self::fill.

Source

pub fn row_satisfied(&self, y: usize) -> bool

Whether row y’s currently-filled cells already match its clue. Used both as a hint for the player (dim/strikethrough the clue) and, together with Self::col_satisfied, as the win condition.

Source

pub fn col_satisfied(&self, x: usize) -> bool

Whether column x’s currently-filled cells already match its clue. See Self::row_satisfied.

Source

pub fn can_undo(&self) -> bool

Source

pub fn can_redo(&self) -> bool

Source

pub fn undo(&mut self)

Source

pub fn redo(&mut self)

Source

pub fn random_logical( width: usize, height: usize, density: f32, seed: u64, ) -> Self

Generate a puzzle guaranteed solvable via line-solving only (no guessing). Uses rejection sampling: generates random puzzles and keeps only those that pass the line-solvability check.

§Panics

Panics if no logically solvable puzzle is found within 10_000 attempts (unlikely for reasonable densities on small grids).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.