From 4d85ba0d10e6e48f99920bedec7426270b643764 Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Mon, 30 Jul 2012 22:33:19 -0400 Subject: [PATCH] Cleaning up yaku and hand completion detection --- src/riichi_hand.erl | 17 +++++------------ src/yaku.erl | 4 +++- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/riichi_hand.erl b/src/riichi_hand.erl index 445b37d..027d410 100644 --- a/src/riichi_hand.erl +++ b/src/riichi_hand.erl @@ -36,7 +36,7 @@ find(Tiles, Hand = #hand{tiles=HT, melds=HM}, Possible) -> find(Rest, Hand#hand{tiles=[T|HT]}, Possible) end. -is_complete(#hand{tiles=[], melds=Melds}) -> +is_complete(#hand{tiles=[], melds=Melds}=Hand) -> Pairs = [M || M <- Melds, M#meld.type =:= pair], case length(Pairs) of 1 -> @@ -44,19 +44,12 @@ is_complete(#hand{tiles=[], melds=Melds}) -> length(Melds) =:= 5; 7 -> % Must be seven *unique* pairs - sets:size(sets:from_list(Pairs)) =:= 7; + yaku:chiitoitsu(Hand); _ -> false end; is_complete(#hand{}=Hand) -> - kokushi_musou(Hand). + yaku:kokushi_musou(Hand). -% 13 Orphans -kokushi_musou(#hand{tiles=Tiles, melds=Melds}) when - length(Tiles) =:= 13 - andalso length(Melds) =:= 0 -> - not lists:any(fun(#tile{value=V}) -> - lists:member(V, lists:seq(2,8)) - end, - Tiles) - andalso sets:size(sets:from_list(Tiles)) =:= 13. +km() -> + [#tile{suit=pin, value=1}|?TERMINALS ++ ?HONOURS]. diff --git a/src/yaku.erl b/src/yaku.erl index f742c7a..d3d31a2 100644 --- a/src/yaku.erl +++ b/src/yaku.erl @@ -50,4 +50,6 @@ kokushi_musou(#hand{tiles=Tiles, melds=[#meld{type=pair, tiles=[T,T]}]}) -> lists:member(V, lists:seq(2,8)) end, [T|Tiles]) - andalso sets:size(sets:from_list([T|Tiles])) =:= 13. + andalso sets:size(sets:from_list([T|Tiles])) =:= 13; +kokushi_musou(#hand{}) -> + false.