Skip to content

Commit

Permalink
refactor!: get_hand_score signature changed to remove raw string input
Browse files Browse the repository at this point in the history
  • Loading branch information
DrCheeseFace committed Sep 8, 2024
1 parent 09bddb8 commit 6879294
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
16 changes: 3 additions & 13 deletions src/calc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@ impl std::fmt::Display for CalculatorErrors {

/// Get the score breakdown of the hand.
pub fn get_hand_score(
tiles: Vec<String>,
win: String,
dora: Option<Vec<String>>,
seat: String,
prev: String,
hand: Hand,
dora: Option<Vec<TileGroup>>,
tsumo: bool,
riichi: bool,
doubleriichi: bool,
Expand All @@ -41,7 +38,6 @@ pub fn get_hand_score(
tenhou: bool,
honba: HonbaCounter,
) -> Result<Score, HandErr> {
let hand = Hand::new(tiles, win, seat, prev)?;
if hand.kans().is_empty() && rinshan {
return Err(HandErr::RinshanKanWithoutKan);
}
Expand Down Expand Up @@ -79,13 +75,7 @@ pub fn get_hand_score(
};

// get han from dora tiles
let doras: Option<Vec<TileGroup>> = dora.map(|dora_tiles| {
dora_tiles
.into_iter()
.filter_map(|tile| tile.try_into().ok())
.collect()
});
let dora_count = hand.get_dora_count(doras);
let dora_count = hand.get_dora_count(dora);

let han = yaku.0 + dora_count;
let fu_value = calculate_total_fu_value(&fu);
Expand Down
17 changes: 14 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ use std::io::Write;
use clap::Parser;
use mahc::calc;
use mahc::hand::error::HandErr;
use mahc::hand::Hand;
use mahc::payment::Payment;
use mahc::score::{FuValue, HanValue, HonbaCounter, Score};
use mahc::tile_group::TileGroup;
use serde_json::json;

/// riichi mahjong calculator tool
Expand Down Expand Up @@ -127,12 +129,21 @@ pub fn parse_hand(args: &Args) -> Result<String, HandErr> {
if args.doubleriichi && args.haitei && args.chankan {
return Err(HandErr::DoubleRiichiHaiteiChankan);
}
let score = calc::get_hand_score(
let hand = Hand::new(
args.tiles.clone().unwrap(),
args.win.clone().unwrap(),
args.dora.clone(),
args.seat.clone(),
args.prev.clone(),
args.seat.clone(),
)?;
let doras: Option<Vec<TileGroup>> = args.dora.clone().map(|dora_tiles| {
dora_tiles
.into_iter()
.filter_map(|tile| tile.try_into().ok())
.collect()
});
let score = calc::get_hand_score(
hand,
doras,
args.tsumo,
args.riichi,
args.doubleriichi,
Expand Down

0 comments on commit 6879294

Please sign in to comment.