pub struct HexwebGame { /* private fields */ }Expand description
The hexweb puzzle: pieces on a hexagonal lattice, moved until every arrow is met by the opposite arrow of the piece it points at.
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. The other way a piece can land is onto an
occupied node, swapping the two: see HexwebGame::can_swap.
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 can_swap(&self, a: usize, b: usize) -> bool
pub fn can_swap(&self, a: usize, b: usize) -> bool
Whether pieces a and b may be swapped right now: the game must be
unfinished and both pieces must be placed and distinct. Two pieces
with identical arrows may be swapped, but the swap is a free no-op
(see HexwebGame::swap_pieces).
Sourcepub fn swap_pieces(&mut self, a: usize, b: usize) -> bool
pub fn swap_pieces(&mut self, a: usize, b: usize) -> bool
Exchanges the nodes of the two placed pieces a and b. Returns
whether the swap happened; illegal swaps (see
HexwebGame::can_swap) leave the board unchanged. Counts the move
and latches the win when the board becomes solved. Pieces with
identical arrows are interchangeable, so swapping two of them leaves
the move counter alone.
Sourcepub fn satisfied(&self, piece: usize) -> bool
pub fn satisfied(&self, piece: usize) -> bool
Whether every arrow of piece currently forms a mutual pair.
Sourcepub fn unsatisfied_arrows(&self, piece: usize) -> Arrows
pub fn unsatisfied_arrows(&self, piece: usize) -> Arrows
The arrows of piece that do not yet form a mutual pair: their
target node is empty, off the board, or holds a piece that does not
point back with the opposite arrow. This is the live feedback the
widget paints in the accent color.
Sourcepub fn is_solved(&self) -> bool
pub fn is_solved(&self) -> bool
Whether every arrow of every piece is met by the opposite arrow of the piece it points at: a completed web of mutual pairs.
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
Auto 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