Skip to main content

Board

Struct Board 

Source
pub struct Board { /* private fields */ }
Expand description

The entire game state. No engine types, no floats, no hash maps: every tick is a pure function of prior state plus one action per seat, so the same seed and input list replays bit-identically on any platform.

Implementations§

Source§

impl Board

Source

pub fn spawn_crab( &mut self, x: u8, y: u8, dir: Direction, handed: Handedness, kind: CrabKind, )

Place a crab directly (puzzle setups and tests; spawner tiles handle the normal case). The crab immediately wall-resolves so it never starts a tick facing a wall.

Source§

impl Board

Source

pub fn force_lure(&mut self, owner: PlayerId)

Apply one tide event’s effects (split from the roulette so each event is unit-testable in isolation). Start a lure for owner, as banking a molting crab does.

Same reason as Self::force_tide_event: the dev hook and the tests need one on demand, and waiting for a molt to turn up and be banked is not a thing a screenshot can do.

Source

pub fn force_tide_event(&mut self, event: TideEvent, banker: PlayerId)

Fire a named tide event outright. The roulette is the only caller in play; this exists for the dev hook that has to show one on demand, and for the tests, which cannot wait for a sparkling crab.

Source§

impl Board

Source

pub fn step(&self, tile: u16, dir: Direction) -> Option<u16>

The tile one step away in dir, if there is one: across the seam on a wrapping arena, None off the edge otherwise. The public face of Board::neighbor for callers outside the board: the bot plans on the same beach the crabs walk, seam included.

Source

pub fn coords(&self, tile: u16) -> (i32, i32)

Tile index to (x, y), in the i32 the movement arithmetic speaks; Board::coords_u8 is the byte-sized form. The board’s arithmetic is the only copy: the bot, the solver, and the renderers all ask rather than re-derive.

Source

pub fn index_of(&self, x: u8, y: u8) -> u16

(x, y) back to the tile index, the inverse of Board::coords_u8.

Source§

impl Board

Source

pub fn spawn_gull(&mut self, x: u8, y: u8, dir: Direction)

Drop a gull onto the board, walking. Used by level setup and the periodic edge spawner.

Source§

impl Board

Source

pub fn state_hash(&self) -> u64

Fingerprint of the complete simulation state, in a fixed field order. Two boards fed the same seed and inputs must agree on this after every tick, on every platform: the determinism contract of spec §7.5.

Source§

impl Board

Source

pub fn can_place_signpost(&self, player: PlayerId, x: u8, y: u8) -> bool

Spec §3.3: signposts go on empty sand only, not on castles, rocks, spawners, or a tile that already has one. At the cap, the outcome depends on the board’s CapPolicy: evict the player’s oldest (versus) or reject the placement (puzzle inventory). Whether a placement at (x, y) would succeed, without mutating. Mirrors Board::place_signpost exactly; the UI uses it for instant denied feedback on a queued (not yet applied) action.

Source

pub fn place_signpost( &mut self, player: PlayerId, x: u8, y: u8, dir: Direction, ) -> bool

Source

pub fn signpost_fade(&self, sp: &Signpost) -> f32

Remaining life of a signpost as a 0..=1 fraction (always 1 under puzzle rules, where posts are permanent).

Source

pub fn newest_signpost_of(&self, player: PlayerId) -> Option<(u8, u8, u64)>

Where a player’s most recent signpost stands and when they placed it: (x, y, tick).

This is the anchor for a bot’s cursor (see crate::sim::bot_action): the last tile it reached, so the walk to the next one can be charged for. Reading it from the board keeps the bot a pure function of the state, so every peer of an online match derives the same move for an AI seat.

Source

pub fn signpost_count(&self, player: PlayerId) -> usize

How many signposts player currently has on the board.

Source

pub fn remove_signpost(&mut self, player: PlayerId, x: u8, y: u8) -> bool

Players may only remove their own signposts.

Source

pub fn signpost_at(&self, x: u8, y: u8) -> Option<Signpost>

Source

pub fn signpost_rule(&self) -> (u8, CapPolicy)

The current signpost cap rule, for serialization.

Source§

impl Board

Source

pub fn to_snapshot(&self) -> String

The whole board as text.

Source

pub fn parse_snapshot(text: &str) -> Result<Board, String>

Read a snapshot back, or say why it is not one.

Strict where the level format is lenient: a snapshot is written by this build for this build, so a line it cannot read is a corrupt save rather than a hand edit to shrug at.

Source§

impl Board

Source

pub fn new(width: u8, height: u8, seed: u64) -> Board

An empty all-sand board with walled borders (spec §3.1; wrap-around edges are a later, flag-gated variant).

Source

pub fn set_wall(&mut self, x: u8, y: u8, dir: Direction, present: bool)

Add or remove the wall on the dir side of tile (x, y). Walls are stored per-edge, so the neighbouring tile sees the same wall and the two tiles cannot disagree (spec §7.3).

Source

pub fn set_tile(&mut self, x: u8, y: u8, kind: TileKind)

Source

pub fn set_signpost_rule(&mut self, cap: u8, policy: CapPolicy)

Change the signpost cap and what happens at it. Versus keeps the default (3, evict-oldest); puzzle mode sets (inventory, reject).

Source

pub fn set_gull_period(&mut self, period: u32)

Auto-spawn a gull every period ticks (0 disables). Doubled during the final-scramble surge of a timed round.

Source

pub fn set_round_length(&mut self, ticks: Option<u32>)

Source

pub fn set_wrap(&mut self, wrap: bool)

Open (or close) the board edges. Opening removes the border walls so creatures walk and fly off one side and re-enter on the opposite one.

Source

pub fn wrap(&self) -> bool

Source

pub fn events_enabled(&self) -> bool

Enable tide events (the sparkling crab’s roulette). Off by default: puzzles and goal-checked challenges stay predictable.

Source

pub fn set_events_enabled(&mut self, enabled: bool)

Source

pub fn last_event(&self) -> Option<(TideEvent, u64)>

The most recent tide event and when it fired.

Source

pub fn golden_banked(&self) -> u32

Source

pub fn set_score(&mut self, player: PlayerId, score: u32)

Preload a score (editor, sandboxes, tests). Not used by live play: scores otherwise change only through banking and gull raids. A seat that does not exist takes no score: the callers that parse untrusted text already refuse it with a message, and this is the backstop.

Source

pub fn tick(&mut self, actions: &[PlayerAction; 6])

Advance one fixed 30 Hz step. Order within a tick is fixed and part of the ruleset: player actions (in the tick’s rotating seat order; on a same-tile conflict, whoever that order reaches first wins), then spawners, then crab movement, then gull movement, then gulls eat, in stable creature order throughout. A signpost placed this tick affects crabs arriving this tick. Once the tide is in (round_over), the sim is frozen and ticks are no-ops: scores locked at the wave (spec §3.6).

Source

pub fn seats_in_play(&self) -> u8

How many seats this board seats: one past the highest castle owner, so a four-castle beach rotates ties among four however wide the arrays.

Source

pub fn round_over(&self) -> bool

The tide has come in: the round is finished and the sim is frozen.

Source

pub fn remaining_ticks(&self) -> Option<u64>

Ticks left before the wave, if a round timer is set.

Source

pub fn in_surge(&self) -> bool

The final scramble: the last 30 s of a timed round, when gulls spawn at double rate.

Source

pub fn tick_idle(&mut self)

Advance one step with no player input.

Source

pub fn width(&self) -> u8

Source

pub fn height(&self) -> u8

Source

pub fn ticks(&self) -> u64

Source

pub fn crabs(&self) -> &[Crab]

Source

pub fn gulls(&self) -> &[Gull]

Source

pub fn gull_period(&self) -> u32

Source

pub fn round_length(&self) -> Option<u32>

Source

pub fn seed(&self) -> u64

The seed this board was constructed with.

Source

pub fn remove_crabs_at(&mut self, x: u8, y: u8)

Remove every crab standing on tile (x, y) (editor use).

Source

pub fn remove_gulls_at(&mut self, x: u8, y: u8)

Remove every gull standing on tile (x, y) (editor use).

Source

pub fn lure(&self) -> Option<(PlayerId, u32)>

Active molting lure, if any: (luring player, ticks left).

Source

pub fn crabs_banked(&self) -> u32

Crabs banked since the start, all players combined.

Source

pub fn crabs_spawned(&self) -> u32

Crabs ever spawned (initial, spawner-emitted, and castle-spilled).

Source

pub fn scores(&self) -> &[u32; 6]

Source

pub fn tile_at(&self, x: u8, y: u8) -> TileKind

Source

pub fn tiles(&self) -> impl Iterator<Item = (u8, u8, TileKind)> + '_

Every tile with its coordinates, in the board’s own row-major order.

Source

pub fn castle_of(&self, player: PlayerId) -> Option<(u8, u8)>

Where a seat’s castle stands, if it has one.

Source

pub fn castle_owners(&self) -> impl Iterator<Item = PlayerId> + '_

The highest seat number with a castle on the board: the seat count a recorded board implies.

Source

pub fn castle_seats(&self) -> u8

How many seats the board has castles for, counted by owner rather than by castle: a beach seats as many players as there are banks to run for. What the map dial measures a handmade beach against.

Source

pub fn first_signpost_of(&self, player: PlayerId) -> Option<(u8, u8)>

The first signpost owned by player in reading order (top-left to bottom-right), as tile coordinates. Drives the “clear one” input.

Source

pub fn coords_u8(&self, tile: u16) -> (u8, u8)

Tile index back to coordinates. Board::coords speaks i32 for the movement arithmetic; this is the public-facing form.

Source

pub fn wall_at(&self, x: u8, y: u8, dir: Direction) -> bool

Trait Implementations§

Source§

impl Clone for Board

Source§

fn clone(&self) -> Board

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 Board

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Board

§

impl RefUnwindSafe for Board

§

impl Send for Board

§

impl Sync for Board

§

impl Unpin for Board

§

impl UnsafeUnpin for Board

§

impl UnwindSafe for Board

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, U> AsBindGroupShaderType<U> for T
where U: ShaderType, &'a T: for<'a> Into<U>,

Source§

fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U

Return the T ShaderType for self. When used in AsBindGroup derives, it is safe to assume that all images in self exist.
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> ConditionalSend for T
where T: Send,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

impl<T> HitDataExtra for T
where T: Send + Sync + Debug + Any + 'static,

Source§

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

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoResult<T> for T

Source§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
Source§

impl<A> Is for A
where A: Any,

Source§

fn is<T>() -> bool
where T: Any,

Checks if the current type “is” another type, using a TypeId equality comparison. This is most useful in the context of generic logic. Read more
Source§

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

Source§

impl<T> Settings for T
where T: 'static + Send + Sync,

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> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

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

impl<T> TypeData for T
where T: 'static + Send + Sync + Clone,

Source§

fn clone_type_data(&self) -> Box<dyn TypeData>

Creates a type-erased clone of this value.
Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more