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 drawsIn a physical game, the following procedure is used to prepare the wall:
-
Shuffle: 136 tiles => 4 sides x 17 stacks x 2 tiles per stack, treated as a ring.
-
Randomly decide the splitting point on this ring (rules vary on this).
-
From the splitting point: clockwise => head, counterclockwise => tail. Now the ring can be treated as a linear 68 x 2 array of tiles.
-
Reveal the top tile of the 3rd stack from tail; this is the first Dora Indicator. (figure:
###) -
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) -
The button player takes his first self-draw and the round starts. (figure:
#00) -
Additional draw after each Kan is taken from the tail. (figure:
RS0,RS1,RS2,RS3) -
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§
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§
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§
- Partial
Wall - Wall with some tiles unknown.
- Wall
- The wall of tiles. See mod-level docs.