pub struct HexwebGame { /* private fields */ }Expand description
The hexweb puzzle: pieces on a hexagonal lattice, moved until every arrow points at another piece.
Implementations§
Source§impl HexwebGame
impl HexwebGame
Sourcepub fn random(params: Params, seed: u64) -> Self
pub fn random(params: Params, seed: u64) -> Self
Generates a new puzzle from params with a deterministic seed.
The generator lays a solved configuration down first, then verifies
with an exact counting solver that exactly one placement of the pieces
solves it (repairing by adding arrows if not), and finally scrambles
the board with legal moves. See crate::generator.
Panics (see Params and [validate_params]) on impossible
parameters: duplicate or isolated nodes, a piece count outside
1..nodes.len(), or an arrow range outside 1..=6 with
min <= max.
Sourcepub fn nodes(&self) -> &[Node]
pub fn nodes(&self) -> &[Node]
The board’s nodes, in the order of the coordinates passed to
Params.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Total node count (occupied + empty).
Sourcepub fn piece_count(&self) -> usize
pub fn piece_count(&self) -> usize
How many pieces the board holds.
Sourcepub fn empty_count(&self) -> usize
pub fn empty_count(&self) -> usize
How many nodes are currently empty.
Sourcepub fn node_at(&self, q: i32, r: i32) -> Option<usize>
pub fn node_at(&self, q: i32, r: i32) -> Option<usize>
The node with axial coordinates (q, r), if it exists on the board.
Sourcepub fn can_move(&self, piece: usize, to: usize) -> bool
pub fn can_move(&self, piece: usize, to: usize) -> bool
Whether piece may be moved to to right now: the game must be
unfinished, to must be an in-board node, and it must be empty and
not piece’s own node.
Sourcepub fn move_piece(&mut self, piece: usize, to: usize) -> bool
pub fn move_piece(&mut self, piece: usize, to: usize) -> bool
Moves piece to the empty node to. Returns whether the move
happened; illegal moves (see HexwebGame::can_move) leave the board
unchanged. Counts the move and latches the win when the board becomes
solved.
Sourcepub fn satisfied(&self, piece: usize) -> bool
pub fn satisfied(&self, piece: usize) -> bool
Whether every arrow of piece currently points at an occupied node.
Sourcepub fn unsatisfied_arrows(&self, piece: usize) -> Arrows
pub fn unsatisfied_arrows(&self, piece: usize) -> Arrows
The arrows of piece whose target node is empty or off the board.
This is the live feedback the widget paints in the accent color.
Sourcepub fn status(&self) -> GameStatus
pub fn status(&self) -> GameStatus
Whether the game is finished. Latched: once GameStatus::Won, it
stays won until HexwebGame::reset or a new game.
Sourcepub fn solution_count(&self, cap: usize) -> usize
pub fn solution_count(&self, cap: usize) -> usize
How many distinct placements of the pieces solve the board, capped at
cap. Counts the multiset: identical pieces are interchangeable, so
swapping two of them is not a second solution. Runs in microseconds
on the shipped board sizes; see crate::solver.
Trait Implementations§
Source§impl Clone for HexwebGame
impl Clone for HexwebGame
Source§fn clone(&self) -> HexwebGame
fn clone(&self) -> HexwebGame
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for HexwebGame
impl RefUnwindSafe for HexwebGame
impl Send for HexwebGame
impl Sync for HexwebGame
impl Unpin for HexwebGame
impl UnsafeUnpin for HexwebGame
impl UnwindSafe for HexwebGame
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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