ritchie/elements/meld

Types

Sum type for all kinds of melds. This is one of Chii, Pon, Kakan, Daiminkan, Ankan

pub type Meld {
  Chii(chii.Chii)
  Pon(pon.Pon)
  Kakan(kakan.Kakan)
  Daiminkan(daiminkan.Daiminkan)
  Ankan(ankan.Ankan)
}

Constructors

Values

pub fn all_closed(melds: List(Meld)) -> Bool

Returns whether every meld is closed, i.e. whether the hand is a closed hand.

pub fn called(m: Meld) -> option.Option(tile.Tile)

Returns the called tile for all melds except Ankan.

pub fn consume_from_hand(
  m: Meld,
  hand: tile_set37.TileSet37,
) -> tile_set37.TileSet37

Removes this meld’s “own tile(s)” from the closed hand. For Kakan, the added tile is removed, since the underlying Pon already exists.

pub fn dir(m: Meld) -> option.Option(player.Player)

Returns where this meld is called from, relative to this Player.

  • Chii: Always the previous Player (+3)
  • Ankan: Not called from anyone, so None.
pub fn is_closed(m: Meld) -> Bool

Returns true if meld is Ankan.

pub fn is_kan(m: Meld) -> Bool

Returns true is meld is a variety of Kan.

pub fn to_equivalent_group(m: Meld) -> hand_group.HandGroup

Maps to the equivalent closed-hand group. Useful for e.g. winning condition calculations.

  • Chii: Shuntsu
  • Pon/Kan: Koutsu (ignoring the 4th tile)
✨ Search Document