pub struct Tile(/* private fields */);Expand description
Represents one tile (牌).
Encoded as a 6-bit integer:
| Encoding | Shorthand | Category (EN) | Category (JP) |
|---|---|---|---|
| 0 ..= 8 | 1m ..= 9m | characters | 萬子 |
| 9 ..= 17 | 1p ..= 9p | dots | 筒子 |
| 18 ..= 26 | 1s ..= 9s | bamboos | 索子 |
| 27 ..= 30 | 1z ..= 4z | winds | 風牌 |
| 31, 32, 33 | 5z, 6z, 7z | dragons | 三元牌 |
| 34, 35, 36 | 0m, 0p, 0s | reds | 赤牌 |
Note that only red 5’s can be represented (not other numbers or honors).
Details of this encoding is significant and implicitly assumed across the crate. It should never be changed.
§Optional serde support
The common string shorthand (e.g. "1m", "0p", "7z") is used as the serialization format.
This ensures readability and interoperability.
Implementations§
Source§impl Tile
impl Tile
pub const MIN_ENCODING: u8 = 0u8
pub const MAX_ENCODING: u8 = 36u8
pub const MIN: Self
pub const MAX: Self
pub const fn from_encoding(encoding: u8) -> Option<Self>
pub const fn from_num_suit(num: u8, suit: u8) -> Option<Self>
pub fn from_wind(wind: Wind) -> Self
pub const fn is_valid(self) -> bool
Sourcepub const fn is_numeral(self) -> bool
pub const fn is_numeral(self) -> bool
Numerals (数牌) := Characters (萬子) + Dots (筒子) + Bamboos (索子)
Sourcepub const fn is_pure_terminal(self) -> bool
pub const fn is_pure_terminal(self) -> bool
Pure terminals (老頭牌) := {1,9}{m,p,s}
Sourcepub const fn is_dragon(self) -> bool
pub const fn is_dragon(self) -> bool
Dragons (三元牌) := {5,6,7}z (correspond to {blue, green, red} dragons).
Sourcepub const fn is_terminal(self) -> bool
pub const fn is_terminal(self) -> bool
Terminals (么九牌) := Pure terminals (老頭牌) + Honors (字牌)
pub const fn encoding(self) -> u8
Sourcepub const fn normal_encoding(self) -> u8
pub const fn normal_encoding(self) -> u8
Encoding of this tile, except red 5 is converted to normal 5
Sourcepub const fn red_encoding(self) -> u8
pub const fn red_encoding(self) -> u8
Encoding of this tile, except normal 5 is converted to red 5
Sourcepub const fn wind(self) -> Option<Wind>
pub const fn wind(self) -> Option<Wind>
Converts to the corresponding wind (ESWN) if this is a wind tile.
Sourcepub const fn normal_num(self) -> u8
pub const fn normal_num(self) -> u8
Returns the “number” part of the shorthand, with reds converted to non-red (i.e. 0 => 5).
Sourcepub const fn suit(self) -> u8
pub const fn suit(self) -> u8
Returns the “suit” part of the shorthand (0, 1, 2, 3 for m, p, s, z respectively)
Sourcepub const fn succ(self) -> Option<Self>
pub const fn succ(self) -> Option<Self>
For numerals 1 to 8, returns 2 to 9 respectively. Otherwise None.
Sourcepub const fn succ2(self) -> Option<Self>
pub const fn succ2(self) -> Option<Self>
For numerals 1 to 7, returns 3 to 9 respectively. Otherwise None.
Sourcepub const fn pred(self) -> Option<Self>
pub const fn pred(self) -> Option<Self>
For numerals 2 to 9, returns 1 to 8 respectively. Otherwise None.
Sourcepub const fn pred2(self) -> Option<Self>
pub const fn pred2(self) -> Option<Self>
For numerals 3 to 9, returns 1 to 7 respectively. Otherwise None.
Sourcepub const fn indicated_dora(self) -> Self
pub const fn indicated_dora(self) -> Self
Given this tile as the dora-indicator (ドラ表示牌), returns the indicated dora tile (ドラ).
Ref:
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Tile
impl<'de> Deserialize<'de> for Tile
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl FromIterator<Tile> for TileMask34
impl FromIterator<Tile> for TileMask34
Source§impl FromIterator<Tile> for TileSet34
impl FromIterator<Tile> for TileSet34
Source§impl FromIterator<Tile> for TileSet37
impl FromIterator<Tile> for TileSet37
Source§impl Ord for Tile
impl Ord for Tile
Source§impl PartialOrd for Tile
impl PartialOrd for Tile
impl Copy for Tile
impl Eq for Tile
impl StructuralPartialEq for Tile
Auto Trait Implementations§
impl Freeze for Tile
impl RefUnwindSafe for Tile
impl Send for Tile
impl Sync for Tile
impl Unpin for Tile
impl UnwindSafe for Tile
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more