Module wall

Module wall 

Source
Expand description

The wall of tiles (牌山/山/壁牌) and utils.

§How we represent the wall

                         _______________      ______________
                        <--- TAIL (CCW) |    / HEAD (CW) --->
 self draws |  dora indicators  |rinshan|   |            initial deal             | self draws
     118 120|122 124 126 128 130|132 134|   | 0   2   4   6   8  10        48  50 |52  54
... +---+---*---+---+---+---+###*---+---+   +---+---+---+---+---+---+ ... +---+---*---+---+ ...
    |#66|#68| D4| D3| D2| D1| D0|RS2|RS0|   |E0 |E2 |S0 |S2 |W0 |W2 |     |E12|W12|#00|#02|      TOP
... +===+===*===+===+===+===+===*===+===+   +===+===+===+===+===+===+ ... +===+===*===+===+ ...
    |#67|#69|UD4|UD3|UD2|UD1|UD0|RS3|RS1|   |E1 |E3 |S1 |S3 |W1 |W3 |     |S12|N12|#01|#03|      BOTTOM
... +---+---*---+---+---+---+---*---+---+   +---+---+---+---+---+---+ ... +---+---*---+---+ ...
     119 121|123 125 127 129 131|133 135|   | 1   3   5   7   9  11        49  51 |53  55
 self draws |ura-dora indicators|rinshan|   |            initial deal             | self draws

In a physical game, the following procedure is used to prepare the wall:

  1. Shuffle: 136 tiles => 4 sides x 17 stacks x 2 tiles per stack, treated as a ring.

  2. Randomly decide the splitting point on this ring (rules vary on this).

  3. From the splitting point: clockwise => head, counterclockwise => tail. Now the ring can be treated as a linear 68 x 2 array of tiles.

  4. Reveal the top tile of the 3rd stack from tail; this is the first Dora Indicator. (figure: ###)

  5. Initial deal: Players take turns (E->S->W->N->E->…) to draw 2 stacks (= 4 tiles) from the head until everyone has 12. Each player then draws one more tile. (figure: E0E3, S0S3, (…), W8W11, N8N11; E12, S12, W12, N12)

  6. The button player takes his first self-draw and the round starts. (figure: #00)

  7. Additional draw after each Kan is taken from the tail. (figure: RS0, RS1, RS2, RS3)

  8. Additional Dora Indicators are flipped further from tail since the initial one. (figure: D1, D2, D3, D4)

In this crate, we assign an index to each of the 136 tiles in the “linear” wall after splitting. The split wall is indexed head-to-tail (major), top-to-bottom (minor). In the figure, this index is annotated as numbers next to the boxes (above/below).

§Ref

Structs§

PartialWallDisplay
WallDisplay

Constants§

DEAL_INDEX
For each player starting from the button player, which wall tiles to take as the initial draw?
DORA_INDICATOR_INDEX
Index of dora indicators in the wall, by their order of revealing first-to-last.
KAN_DRAW_INDEX
Index of kan draws in the wall, first-to-last.
MAX_NUM_DRAWS
Total number of draws (front + back) cannot exceed this.
URA_DORA_INDICATOR_INDEX
Index of ura-dora indicators in the wall; order corresponding to dora indicators.

Traits§

PartialWallDisplayMethod
WallDisplayMethod

Functions§

deal
Draws the initial 13 tiles for each of the 4 players, according to standard rules. See module-level docs.
dora_indicator
Returns the indexed (0..=4) dora indicator.
dora_indicators
Returns the entire dora indicator section of the wall as an array. Note that this does not handle the gradual revealing of dora indicators.
fill_missing_tiles_in_partial_wall
Combine the partially-known wall and (reordered) unknown tiles to form a fully-known wall.
get_missing_tiles_in_partial_wall
Deduces the set of unknown tiles from the given partially-known wall, and the known total number of red tiles.
is_valid_wall
Make sure that a wall is valid — 34 kinds x 4 each = 136
kan_draw
Returns the indexed (0..=3) Kan draw.
make_dummy_wall
Constructor for an obviously invalid wall. Useful for mutating it later.
make_sorted_wall
Make a sorted wall of the standard 136-tile set, including specified number of red-5’s for each (numeral) suit.
ura_dora_indicator
Returns the indexed (0..=4) ura-dora indicator.
ura_dora_indicators
Returns the entire ura-dora indicator section of the wall as an array. Note that this does not handle the final revealing of ura-dora indicators.

Type Aliases§

PartialWall
Wall with some tiles unknown.
Wall
The wall of tiles. See mod-level docs.