diff --git a/src/yaku.erl b/src/yaku.erl index 81c191e..d7fd17a 100644 --- a/src/yaku.erl +++ b/src/yaku.erl @@ -13,7 +13,8 @@ pinfu/2, chiitoitsu/2, kokushi_musou/2, - ryuu_iisou/2]). + ryuu_iisou/2, + dai_san_gen/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. @@ -92,3 +93,9 @@ 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). + +%% @doc Returns true for a Big Three Dragons hand +-spec dai_san_gen(game(), player()) -> boolean(). +dai_san_gen(#game{}, #player{hand=#hand{melds=Melds}}) -> + [green, red, white] =:= lists:usort([V || #meld{type=T, tiles=[#tile{suit=dragon, value=V}|_]} <- Melds, + lists:member(T, [pon, kan])]). diff --git a/test/riichi_yaku_tests.erl b/test/riichi_yaku_tests.erl index c53d395..78ed9b1 100644 --- a/test/riichi_yaku_tests.erl +++ b/test/riichi_yaku_tests.erl @@ -52,3 +52,11 @@ ryuu_iisou_test() -> #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})). + +dai_san_gen_test() -> + Hand = #hand{melds=[#meld{type=chii, tiles=[#tile{suit=sou, value=V} || V <- [2,3,4]]}, + #meld{type=pon, tiles=lists:duplicate(3, #tile{suit=dragon, value=red})}, + #meld{type=pon, tiles=lists:duplicate(3, #tile{suit=dragon, value=green})}, + #meld{type=kan, tiles=lists:duplicate(4, #tile{suit=dragon, value=white})}, + #meld{type=pair, tiles=lists:duplicate(2, #tile{suit=pin, value=1})}]}, + ?assert(yaku:dai_san_gen(#game{}, #player{hand=Hand})).