Dai San Gen

This commit is contained in:
Correl Roush 2012-08-01 00:41:43 -04:00
parent fe32170412
commit 11e2a20eeb
2 changed files with 16 additions and 1 deletions

View file

@ -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])]).

View file

@ -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})).