Skip to main content

HexwebGame

Struct HexwebGame 

Source
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

Source

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.

Source

pub fn nodes(&self) -> &[Node]

The board’s nodes, in the order of the coordinates passed to Params.

Source

pub fn node_count(&self) -> usize

Total node count (occupied + empty).

Source

pub fn piece_count(&self) -> usize

How many pieces the board holds.

Source

pub fn empty_count(&self) -> usize

How many nodes are currently empty.

Source

pub fn pieces(&self) -> &[Piece]

The pieces, in piece-id order.

Source

pub fn piece_at(&self, node: usize) -> Option<usize>

The piece sitting on node, if any.

Source

pub fn node_of(&self, piece: usize) -> Option<usize>

The node piece currently occupies.

Source

pub fn node_at(&self, q: i32, r: i32) -> Option<usize>

The node with axial coordinates (q, r), if it exists on the board.

Source

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.

Source

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.

Source

pub fn satisfied(&self, piece: usize) -> bool

Whether every arrow of piece currently points at an occupied node.

Source

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.

Source

pub fn is_solved(&self) -> bool

Whether every arrow of every piece points at an occupied node.

Source

pub fn moves(&self) -> usize

How many moves have been played since the last reset/new game.

Source

pub fn status(&self) -> GameStatus

Whether the game is finished. Latched: once GameStatus::Won, it stays won until HexwebGame::reset or a new game.

Source

pub fn reset(&mut self)

Restores the initial scramble, zeroing the move counter.

Source

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.

Source

pub fn solution(&self) -> Option<Vec<usize>>

One solving placement, as the node each piece occupies (indexed by piece id), or None if the board has no solution.

Trait Implementations§

Source§

impl Clone for HexwebGame

Source§

fn clone(&self) -> HexwebGame

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HexwebGame

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> SerializableAny for T
where T: 'static + Any + Clone + for<'a> Send + Sync,

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.