ritchie/hand/agari

Agari (winning hand) detection.

A hand wins when its waiting tiles include the winning tile (the discarded tile for a ron, or the drawn tile for a tsumo). decompose already finds every waiting interpretation of a hand, so agari detection takes those interpretations and returns one candidate per interpretation that makes sense. Multiple candidates mean the hand can be read in several ways, which is important for scoring later on. This module doesn’t concern itself with yakus or scoring in any way.

Types

One way the hand can win with the given winning tile (a decomposition + the tile).

pub type AgariCandidate {
  AgariCandidate(
    decomposition: decompose.DecomposedHand,
    winning_tile: tile.Tile,
  )
}

Constructors

Everything needed to evaluate a winning hand, meaning the winning interpretation plus the situation in which it was won.

pub type AgariInput {
  AgariInput(
    candidate: AgariCandidate,
    method: AgariKind,
    seat_wind: player.Player,
    round_wind: player.Player,
    riichi: option.Option(riichi.Riichi),
    is_first_turn: Bool,
    is_last_tile: Bool,
    is_rinshan: Bool,
    is_chankan: Bool,
  )
}

Constructors

  • AgariInput(
      candidate: AgariCandidate,
      method: AgariKind,
      seat_wind: player.Player,
      round_wind: player.Player,
      riichi: option.Option(riichi.Riichi),
      is_first_turn: Bool,
      is_last_tile: Bool,
      is_rinshan: Bool,
      is_chankan: Bool,
    )

    Arguments

    method

    Tsumo or ron.

    seat_wind

    The winning player’s seat wind.

    round_wind

    The round’s prevalent wind.

    riichi

    Some if the player declared riichi before winning.

    is_first_turn

    Have any calls happened yet?

    is_last_tile

    Is the winning tile the last draw of the wall?

    is_rinshan

    Did the winning tile come from the dead wall after a kan?

    is_chankan

    Was the winning tile robbed from another player after a kan?

Whether the hand was won by self-draw (tsumo) or by claiming a discard (ron).

pub type AgariKind {
  Tsumo
  Ron
}

Constructors

  • Tsumo
  • Ron

Values

pub fn agari_candidates(
  hand: tile_set37.TileSet37,
  melds: List(meld.Meld),
  winning_tile: tile.Tile,
) -> List(AgariCandidate)

Returns every interpretation of the hand that completes with winning_tile, or [] if the hand does not win on that tile.

pub fn is_agari(
  hand: tile_set37.TileSet37,
  melds: List(meld.Meld),
  winning_tile: tile.Tile,
) -> Bool

Returns whether the hand is complete with winning_tile.

pub fn is_closed(candidate: AgariCandidate) -> Bool

Returns whether the hand is closed, i.e. it has no open melds. Ankan counts as closed. Irregular hands (chiitoitsu, kokushi) are always closed.

pub fn pair_or_tanki(
  candidate: AgariCandidate,
) -> option.Option(tile.Tile)

Returns the pair of the hand, or the tanki tile.

pub fn waiting_group(
  candidate: AgariCandidate,
) -> option.Option(hand_group.HandGroup)

Returns the group that the winning tile completes, if there is one. Sequence waits yield a Shuntsu containing the winning tile (starting at the lowest tile of the completed group), a shanpon wait yields the Koutsu of the winning tile. Tanki waits and irregular hands (chiitoitsu, kokushi) have no waiting group.

✨ Search Document