ritchie/elements/tile_set37

Histogram for all 37 kinds of tiles (including reds). Backed by a 37-byte BitArray: one unsigned byte per tile kind, laid out in encoding order (1m-9m, 1p-9p, 1s-9s, 1z-7z, then red 5m, 5p, 5s).

Types

pub opaque type TileSet37

Values

pub fn add(set: TileSet37, t: tile.Tile, delta: Int) -> TileSet37

Adds a delta (may be negative) to a tile’s count. Panics on under/overflow.

pub fn complete_set(num_reds: #(Int, Int, Int)) -> TileSet37

The complete set of tiles in a game, given the number of red 5’s in play as #(reds_m, reds_p, reds_s). Each red 5 replaces its corresponding normal 5, the total number of tiles remains 136 (34 x 4).

pub fn count(set: TileSet37, t: tile.Tile) -> Int

Returns how many of the given tile are in the set.

pub fn empty() -> TileSet37
pub fn from_bit_array(bits: BitArray) -> Result(TileSet37, Nil)

Wrap an existing bit array. Must be exactly 37 bytes.

pub fn from_list(counts: List(Int)) -> Result(TileSet37, Nil)

Builds a tile set from a list of all counts, each in 0..=255.

pub fn from_tiles(tiles: List(tile.Tile)) -> TileSet37

Counts every tile in the list, and returns it as a tile set.

pub fn num_tiles(set: TileSet37) -> Int

Returns the total number of tiles in the set.

pub fn set_count(
  set: TileSet37,
  t: tile.Tile,
  n: Int,
) -> TileSet37

Replaces the count for a tile. Panics if n isn’t in 0..=255.

pub fn to_bit_array(set: TileSet37) -> BitArray

Returns the inner bit array.

pub fn to_list(set: TileSet37) -> List(Int)

Returns all counts as a list, in encoding order.

pub fn to_string(set: TileSet37) -> String

Renders as five comma-terminated groups: manzu, pinzu, souzu, honors, reds. e.g. "300000000,000000000,000000000,0000000,000,"

pub fn to_tile_set34(set: TileSet37) -> tile_set34.TileSet34

Packs the TileSet37 into a TileSet34, collapsing red tiles into normal ones.

pub fn to_tiles(set: TileSet37) -> List(tile.Tile)

Returns the set as a list of all tiles in this set, in encoding order (i.e. reds come after honors).

✨ Search Document