San shoku douko

This commit is contained in:
Correl Roush 2012-08-14 20:06:40 -04:00
parent 7eab34d4cd
commit 48810c1e60
2 changed files with 16 additions and 0 deletions

View file

@ -16,6 +16,7 @@
itsuu/2, itsuu/2,
chiitoitsu/2, chiitoitsu/2,
san_shoku_doujun/2, san_shoku_doujun/2,
san_shoku_douko/2,
kokushi_musou/2, kokushi_musou/2,
ryuu_iisou/2, ryuu_iisou/2,
dai_san_gen/2]). dai_san_gen/2]).
@ -132,6 +133,13 @@ san_shoku_doujun(#game{}, #player{hand=#hand{melds=Melds}=Hand}) ->
Chiis = [M || #meld{type=chii} = M <- Melds], Chiis = [M || #meld{type=chii} = M <- Melds],
lists:any(fun(M) -> san_shoku(M, Hand) end, Chiis). lists:any(fun(M) -> san_shoku(M, Hand) end, Chiis).
%% @doc Returns true for a San shoku douko hand
%% Hand must contain the same triplet in all three suits
-spec san_shoku_douko(game(), player()) -> boolean().
san_shoku_douko(#game{}, #player{hand=#hand{melds=Melds}=Hand}) ->
Pons = [M || #meld{type=pon} = M <- Melds],
lists:any(fun(M) -> san_shoku(M, Hand) end, Pons).
%% @doc Returns true for a 7-pair hand. %% @doc Returns true for a 7-pair hand.
-spec chiitoitsu(game(), player()) -> boolean(). -spec chiitoitsu(game(), player()) -> boolean().
chiitoitsu(#game{}, #player{hand=#hand{tiles=[], melds=Melds}}) chiitoitsu(#game{}, #player{hand=#hand{tiles=[], melds=Melds}})

View file

@ -68,6 +68,14 @@ san_shoku_doujun_test() ->
#meld{type=chii, tiles=[#tile{suit=man, value=V} || V <- [6,7,8]]}]}, #meld{type=chii, tiles=[#tile{suit=man, value=V} || V <- [6,7,8]]}]},
?assertEqual(true, yaku:san_shoku_doujun(#game{}, #player{hand=Hand, drawn={tsumo, #tile{suit=dragon, value=red}}})). ?assertEqual(true, yaku:san_shoku_doujun(#game{}, #player{hand=Hand, drawn={tsumo, #tile{suit=dragon, value=red}}})).
san_shoku_douko_test() ->
Hand = #hand{melds=[#meld{type=pair, tiles=lists:duplicate(2, #tile{suit=sou, value=8})},
#meld{type=pon, tiles=[#tile{suit=sou, value=V} || V <- [1,1,1]]},
#meld{type=pon, tiles=[#tile{suit=man, value=V} || V <- [1,1,1]]},
#meld{type=pon, tiles=[#tile{suit=pin, value=V} || V <- [1,1,1]]},
#meld{type=chii, tiles=[#tile{suit=man, value=V} || V <- [6,7,8]]}]},
?assertEqual(true, yaku:san_shoku_douko(#game{}, #player{hand=Hand, drawn={tsumo, #tile{suit=dragon, value=red}}})).
chiitoitsu_test() -> chiitoitsu_test() ->
Hand = #hand{melds=[#meld{type=pair, tiles=lists:duplicate(2, #tile{suit=pin, value=V})} || V <- lists:seq(1,7)]}, 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})). ?assertEqual(true, yaku:chiitoitsu(#game{}, #player{hand=Hand})).