From 72b0b4be81c0ff306528c1ee4d9e9d14eb7875a6 Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Wed, 1 Aug 2012 00:29:56 -0400 Subject: [PATCH] Ryuu Iisou --- src/yaku.erl | 10 +++++++++- test/riichi_yaku_tests.erl | 8 ++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/yaku.erl b/src/yaku.erl index 4eb9f6c..81c191e 100644 --- a/src/yaku.erl +++ b/src/yaku.erl @@ -12,7 +12,8 @@ tanyao/2, pinfu/2, chiitoitsu/2, - kokushi_musou/2]). + kokushi_musou/2, + ryuu_iisou/2]). %% @doc Counts the pons/kans of value tiles in a player's hand. %% Value tiles include all of the dragons, plus the round wind and the player's seat wind. @@ -84,3 +85,10 @@ kokushi_musou(#game{}, #player{hand=#hand{tiles=Tiles, melds=[#meld{type=pair, t andalso sets:size(sets:from_list([T|Tiles])) =:= 13; kokushi_musou(#game{}, #player{}) -> false. + +%% @doc Returns true for an all-green hand. +-spec ryuu_iisou(game(), player()) -> boolean(). +ryuu_iisou(#game{}, #player{hand=Hand}) -> + Greens = sets:from_list([#tile{suit=sou, value=V} || V <- [2,3,4,6,8]] ++ [#tile{suit=dragon, value=green}]), + Tiles = sets:from_list(riichi_hand:tiles(Hand)), + sets:is_subset(Tiles, Greens). diff --git a/test/riichi_yaku_tests.erl b/test/riichi_yaku_tests.erl index b04eb24..c53d395 100644 --- a/test/riichi_yaku_tests.erl +++ b/test/riichi_yaku_tests.erl @@ -44,3 +44,11 @@ kokushi_musou_test() -> Hand = #hand{tiles=?TERMINALS ++ ?HONOURS -- [#tile{suit=pin, value=1}], melds=[#meld{type=pair, tiles=lists:duplicate(2, #tile{suit=pin, value=1})}]}, ?assertEqual(true, yaku:kokushi_musou(#game{}, #player{hand=Hand})). + +ryuu_iisou_test() -> + Hand = #hand{melds=[#meld{type=chii, tiles=[#tile{suit=sou, value=V} || V <- [2,3,4]]}, + #meld{type=chii, tiles=[#tile{suit=sou, value=V} || V <- [2,3,4]]}, + #meld{type=pon, tiles=lists:duplicate(3, #tile{suit=sou, value=6})}, + #meld{type=pon, tiles=lists:duplicate(3, #tile{suit=sou, value=8})}, + #meld{type=pair, tiles=lists:duplicate(2, #tile{suit=dragon, value=green})}]}, + ?assert(yaku:ryuu_iisou(#game{}, #player{hand=Hand})).