1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// SPDX-FileCopyrightText: 2025 Apricot S.
// SPDX-License-Identifier: MIT
// This file is part of https://github.com/Apricot-S/xiangting
const NUM_TILE_INDEX: usize = 3 * 9 + 4 + 3;
/// 牌: Tile.
///
/// The value represents the index of the tile.
/// The correspondence between the index and the tile is shown in the table below.
///
/// | Index | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
/// | ----- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
/// | Tile | 1m | 2m | 3m | 4m | 5m | 6m | 7m | 8m | 9m |
///
/// | Index | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |
/// | ----- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
/// | Tile | 1p | 2p | 3p | 4p | 5p | 6p | 7p | 8p | 9p |
///
/// | Index | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
/// | ----- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
/// | Tile | 1s | 2s | 3s | 4s | 5s | 6s | 7s | 8s | 9s |
///
/// | Index | 27 | 28 | 29 | 30 | 31 | 32 | 33 |
/// | ----- | --------- | ---------- | --------- | ---------- | ---------- | ---------- | -------- |
/// | Tile | East (1z) | South (2z) | West (3z) | North (4z) | White (5z) | Green (6z) | Red (7z) |
pub type Tile = u8;
/// A type representing the number of tiles for each kind.
///
/// Each element of the array represents the count of a specific tile in the hand.
/// The correspondence between the index and the tile is the same as [`Tile`](crate::Tile).
///
/// # Examples
///
/// ```
/// # use xiangting::TileCounts;
/// // 111m456p789s11222z
/// let hand: TileCounts = [
/// 3, 0, 0, 0, 0, 0, 0, 0, 0, // m
/// 0, 0, 0, 1, 1, 1, 0, 0, 0, // p
/// 0, 0, 0, 0, 0, 0, 1, 1, 1, // s
/// 2, 3, 0, 0, 0, 0, 0, // z
/// ];
/// ```
pub type TileCounts = ;
/// A type representing tiles as a bit flag set.
///
/// Each bit corresponds to a tile index, following the same mapping as [`Tile`](crate::Tile).
/// The least significant bit (bit 0) represents 1m, bit 1 represents 2m, ...,
/// and bit 33 represents Red (7z).
///
/// This allows efficient representation of sets of tiles, such as
/// necessary tiles or unnecessary tiles.
///
/// # Examples
///
/// ```
/// # use xiangting::TileFlags;
/// // 1m456p789s12z
/// let tiles: TileFlags = 0b0000011_111000000_000111000_000000001;
/// ```
pub type TileFlags = u64;
/// Extension utilities for working with [`TileFlags`](crate::TileFlags).
///
/// This trait provides convenience methods to interpret and transform bit flag sets
/// that represent tiles.