Skip to content

Commit

Permalink
feat: yaku validation, tenhou and chiihou
Browse files Browse the repository at this point in the history
  • Loading branch information
DrCheeseFace committed Jul 30, 2024
1 parent 58edf04 commit 098e778
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ cd mahc/x86_64-unknown-linux-gnu/release
- [x] ChuurenPoutou
- [x] ChuurenPoutou 9 sided wait
- [x] Suukantsu
- [ ] Tenhou NOT SURE WHAT TO DO WITH THIS
- [ ] Chiihou NOT SURE WHAT TO DO WITH THIS
- [x] Tenhou
- [x] Chiihou

## TODO
- validation a hand is possible (eg not having 20 east tiles :)
Expand Down
Binary file modified demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/calc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub fn get_hand_score(
haitei: bool,
rinshan: bool,
chankan: bool,
tenhou: bool,
honba: u16,
) -> Result<(Vec<u32>, Vec<Yaku>, Vec<mahc::Fu>, Vec<u16>, bool), HandErr> {
let hand = mahc::Hand::new(tiles, win, seat, prev)?;
Expand All @@ -46,6 +47,7 @@ pub fn get_hand_score(
haitei,
rinshan,
chankan,
tenhou,
tsumo,
);
if yaku.0 == 0 {
Expand Down Expand Up @@ -92,6 +94,7 @@ pub fn get_yaku_han(
haitei: bool,
rinshan: bool,
chankan: bool,
tenhou: bool,
tsumo: bool,
) -> (u16, Vec<Yaku>) {
let mut yaku: Vec<Yaku> = vec![];
Expand Down Expand Up @@ -139,6 +142,8 @@ pub fn get_yaku_han(
(hand.is_daisuushii(), Yaku::Daisuushii),
(hand.is_kokushi(), Yaku::KokushiMusou),
(hand.is_kokushi13sided(), Yaku::KokushiMusou13SidedWait),
(hand.is_tenhou(tenhou), Yaku::Tenhou),
(hand.is_chiihou(tenhou), Yaku::Chiihou),
];

for (condition, yaku_type) in yakumanconditions {
Expand Down
16 changes: 14 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ impl HandErr {
HandErr::IppatsuWithoutRiichi => "Cant Ippatsu without Riichi".to_string(),
HandErr::ChankanTsumo => "Cant Tsumo and Chankan".to_string(),
HandErr::RinshanKanWithoutKan => "Cant Rinshan without Kan".to_string(),
HandErr::RinshanWithoutTsumo=> "Cant Rinshan without tsumo".to_string(),
HandErr::RinshanIppatsu=> "Cant Rinshan and Ippatsu".to_string(),
HandErr::RinshanWithoutTsumo => "Cant Rinshan without tsumo".to_string(),
HandErr::RinshanIppatsu => "Cant Rinshan and Ippatsu".to_string(),
HandErr::DoubleRiichiHaiteiIppatsu => {
"Cant Double Riichi, Ippatsu and haitei".to_string()
}
Expand Down Expand Up @@ -791,6 +791,18 @@ impl Hand {
pub fn is_kokushi13sided(&self) -> bool {
self.is_kokushi() && self.groups.last().unwrap().group_type == GroupType::Pair
}
pub fn is_tenhou(&self, tenhou: bool) -> bool {
if tenhou && self.seat_tile().value == "E" {
return true;
}
return false;
}
pub fn is_chiihou(&self, tenhou: bool) -> bool {
if tenhou && !(self.seat_tile().value == "E") {
return true;
}
return false;
}
}

#[derive(Debug, Clone, PartialEq)]
Expand Down
5 changes: 5 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ pub struct Args {
#[arg(long, default_value_t = false)]
chankan: bool,

/// is tenhou/chihou
#[arg(long, default_value_t = false)]
tenhou: bool,

/// honba count
#[arg(short, long, default_value_t = 0)]
ba: u16,
Expand Down Expand Up @@ -126,6 +130,7 @@ pub fn parse_hand(args: &Args) -> Result<String, mahc::HandErr> {
args.haitei,
args.rinshan,
args.chankan,
args.tenhou,
args.ba,
)?;

Expand Down

0 comments on commit 098e778

Please sign in to comment.