Skip to main content

Module sim

Module sim 

Source
Expand description

Headless game simulation. No engine types allowed in this module tree.

Structs§

Board
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.
Crab
One crab. Position is integer-only: the crab is progress subunits past the centre of tile, moving toward the centre of the next tile in dir. prev_* hold last tick’s position for render-side interpolation (spec §7.4) and are never read by the simulation itself.
Gull
One gull. Moves on the grid exactly like a crab while walking (walls, signposts, handedness), slower than a common crab.
InputMsg
A message to put on the wire: this player’s action for a future frame. 8 bytes packed via InputMsg::encode.
Level
Lockstep
Transport-agnostic lockstep state machine for one peer.
Pcg32
Minimal PCG32 (XSH-RR 64/32): the Board’s seeded, deterministic PRNG.
Replay
Signpost
Spawner

Enums§

BotLevel
Bot difficulty. Levels differ in reaction cadence and search radii; Hard additionally plays offense, steering gulls at the leading rival’s castle. All levels stay pure functions of the board.
CapPolicy
What happens when a player places a signpost at their cap.
CrabKind
Direction
A grid direction in screen space: row 0 is the top of the board, so Up decreases y. “Left of” and “right of” are from the walking agent’s point of view (facing Up, the agent’s left is Left).
Effort
How hard a search may work before it admits defeat.
Goal
What a stage asks of the player. AllCrabs is classic puzzle mode; the rest are Beach Day challenge goals (the original’s Stage Challenge, re-themed).
GullState
Gull behaviour state (spec §3.5). Walking is the default and the whole offensive layer: a walking gull is steerable with signposts. Flight is a brief, occasional hop that exists so no corner can be permanently safe.
Handedness
Which claw is oversized, i.e. which side this crab tries first when its forward path is blocked. The one-bit divergence from ChuChu Rocket that turns herding puzzles into sorting puzzles (spec §2).
LevelKind
What a level was built to be.
PlayerAction
One player’s input for one tick. Coordinates are the cursor’s tile. The wire packs this into 2 bytes (spec §7.6); see crate::transport.
PuzzleOutcome
SignpostHealth
SolveOutcome
What a search found, and when it found nothing, whether that is a proof.
TideEvent
The sparkling crab’s roulette (the original’s “?”-mouse events, re-themed for the beach).
TileKind

Constants§

DEFAULT_DELAY
Input delay in frames: 3 at 30 Hz = 100 ms, the spec’s 2–3 frame range.
DEFAULT_NODE_BUDGET
Boards a budgeted search may simulate before it gives up.
EVENT_TICKS
Tide-event durations (manias, tempo shifts): 10 s.
HASH_INTERVAL
How often peers exchange state hashes for desync detection.
INPUT_BYTES
Bytes an InputMsg occupies on the wire.
LURE_TICKS
Molting-crab lure duration: 10 s at 30 Hz (spec §3.2).
MAX_PLAYERS
Seats a board can hold. Six is the current cut: four corners and two long-edge castles on a generated arena (see castle_spots). The handcrafted classic arena is a four-castle beach and stays one.
MAX_SIGNPOSTS_PER_PLAYER
Spec §3.3: placing a fourth signpost removes that player’s oldest.
PUZZLE_TICK_LIMIT
Sim ticks a puzzle may run before it counts as failed (60 s at 30 Hz). Generous: it exists to catch crabs orbiting forever, not to add pressure.
SIGNPOST_LIFETIME
Versus signposts fade away after this many ticks (10 s, the original’s balance valve against stale fortifications). Puzzle-rule boards (CapPolicy::Reject) keep posts forever: a fixed inventory implies permanence.
SPILL_CAP
Most live crabs a single castle hit can spill back onto the sand. The score still drops a full tier (spec §3.4’s legible loss); crabs beyond the cap are lost to the flock rather than flooding the board.
SUBUNITS_PER_TILE
Spec §4.2: one tile is 256 subunits; all movement is integer arithmetic.
SURGE_TICKS
The final-scramble threshold: with a round timer set, gull spawning doubles in rate when this many ticks remain (spec §3.6: 30 s).
TICKS_PER_SECOND
The canonical simulation rate. Everything that converts ticks to seconds (round lengths, clocks, speed settings) goes through this.
TIER_FLOORS
Castle tier thresholds by banked score (spec §3.4).

Functions§

bot_action
What the bot wants to do this tick, and whether its hand could get there in time to do it.
campaign_levels
Parse the whole campaign. Panics on a malformed level; the validation test fails first, so a shipped binary never hits this.
castle_spots
A castle spot per seat for a board of the given size.
castle_tier
Castle tier (0–3) for a banked-crab score.
challenge_levels
classic_arena
The handcrafted Turf War arena for 2-4 seats: a corner castle per player, two side spawners feeding the middle, rocks to route around, gulls on a timer, and a 3-minute tide. preload_scores stocks two castles for sandbox screenshots.
classic_arena_seeded
The classic layout on an arbitrary PRNG seed. The layout is identical; only the in-round random stream (spawn kinds, gull entry points, events) differs. Online play uses the canonical seed so peers agree by construction; local play may vary it for round-to-round freshness.
decode_action
encode_action
Pack an action for the wire: byte 0 is the cursor column, byte 1 the row, byte 2 is op (bits 0-1: 0 none, 1 place, 2 remove) and direction (bits 2-3, as Direction::id).
generate_arena
Generate a versus arena for seats players (2–MAX_PLAYERS) from a seed, at any size from 9×7 up.
solve
Search for a signpost set (within the level’s inventory) that meets the level’s goal, under DEFAULT_NODE_BUDGET. Prefers fewer posts.
solve_with
solve, with the ceiling named by the caller.
validate
Convenience: validate a level exhaustively, returning the solution found (also checks an authored level’s claim that it is solvable).

Type Aliases§

Placement
A signpost as an instruction: where it goes and which way it points.
PlayerId