From 4438b8bc38431ebf5d9e29ee460453515fa1e919 Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Fri, 10 Aug 2012 21:29:35 -0400 Subject: [PATCH] Itsuu --- src/yaku.erl | 13 +++++++++++++ test/riichi_yaku_tests.erl | 8 ++++++++ 2 files changed, 21 insertions(+) diff --git a/src/yaku.erl b/src/yaku.erl index 724ff78..e650d10 100644 --- a/src/yaku.erl +++ b/src/yaku.erl @@ -13,6 +13,7 @@ pinfu/2, iipeikou/2, chanta/2, + itsuu/2, chiitoitsu/2, kokushi_musou/2, ryuu_iisou/2, @@ -100,6 +101,18 @@ chanta(#game{}, #player{hand=#hand{tiles=[], melds=Melds}}) -> end, Sets). +%% @doc Returns true for an Itsuu hand +%% Hand must contain a 1-9 run in one suit +-spec itsuu(game(), player()) -> boolean(). +itsuu(#game{}, #player{hand=#hand{tiles=[], melds=Melds}}) -> + Tiles = lists:flatten([TS || #meld{type=chii, tiles=TS} <- Melds]), + Runs = [lists:filter(fun(#tile{suit=S, value=V}) -> S =:= Suit end, Tiles) + || Suit <- [man,sou,pin]], + lists:any(fun(TS) -> + sets:from_list([V || #tile{value=V} <- TS]) =:= sets:from_list(lists:seq(1,9)) + end, + Runs). + %% @doc Returns true for a 7-pair hand. -spec chiitoitsu(game(), player()) -> boolean(). chiitoitsu(#game{}, #player{hand=#hand{tiles=[], melds=Melds}}) diff --git a/test/riichi_yaku_tests.erl b/test/riichi_yaku_tests.erl index c57dec8..aff85c1 100644 --- a/test/riichi_yaku_tests.erl +++ b/test/riichi_yaku_tests.erl @@ -52,6 +52,14 @@ chanta_test() -> #meld{type=chii, tiles=[#tile{suit=man, value=V} || V <- [7,8,9]]}]}, ?assertEqual(true, yaku:chanta(#game{}, #player{hand=Hand, drawn={tsumo, #tile{suit=dragon, value=red}}})). +itsuu_test() -> + Hand = #hand{melds=[#meld{type=pair, tiles=lists:duplicate(2, #tile{suit=sou, value=8})}, + #meld{type=chii, tiles=[#tile{suit=sou, value=V} || V <- [1,2,3]]}, + #meld{type=chii, tiles=[#tile{suit=sou, value=V} || V <- [4,5,6]]}, + #meld{type=chii, tiles=[#tile{suit=sou, value=V} || V <- [7,8,9]]}, + #meld{type=chii, tiles=[#tile{suit=man, value=V} || V <- [6,7,8]]}]}, + ?assertEqual(true, yaku:itsuu(#game{}, #player{hand=Hand, drawn={tsumo, #tile{suit=dragon, value=red}}})). + chiitoitsu_test() -> Hand = #hand{melds=[#meld{type=pair, tiles=lists:duplicate(2, #tile{suit=pin, value=V})} || V <- lists:seq(1,7)]}, ?assertEqual(true, yaku:chiitoitsu(#game{}, #player{hand=Hand})).