From 7e0315bd29f3e173bfd4c22eb70e2a7d95d09a8a Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Tue, 14 Aug 2012 21:10:28 -0400 Subject: [PATCH] Toi toi --- src/yaku.erl | 8 ++++++++ test/riichi_yaku_tests.erl | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/src/yaku.erl b/src/yaku.erl index 969aca1..0306827 100644 --- a/src/yaku.erl +++ b/src/yaku.erl @@ -18,6 +18,7 @@ san_shoku_doujun/2, san_shoku_douko/2, san_kan_tsu/2, + toi_toi/2, kokushi_musou/2, ryuu_iisou/2, dai_san_gen/2]). @@ -147,6 +148,13 @@ san_kan_tsu(#game{}, #player{hand=#hand{melds=Melds}}) -> Kans = [M || M = #meld{type=kan} <- Melds], length(Kans) =:= 3. +%% @doc Returns true for a Toi toi hand +%% Hand must contain all triplets +toi_toi(#game{}, #player{hand=#hand{melds=Melds}}) -> + Pons = [M || M = #meld{type=T} <- Melds, + lists:member(T, [pon,kan])], + length(Pons) =:= 4. + %% @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 eedd93a..72fe07a 100644 --- a/test/riichi_yaku_tests.erl +++ b/test/riichi_yaku_tests.erl @@ -84,6 +84,15 @@ san_kan_tsu_test() -> #meld{type=chii, tiles=[#tile{suit=man, value=V} || V <- [6,7,8]]}]}, ?assertEqual(true, yaku:san_kan_tsu(#game{}, #player{hand=Hand, drawn={tsumo, #tile{suit=dragon, value=red}}})). +toi_toi_test() -> + Hand = #hand{melds=[#meld{type=pair, tiles=lists:duplicate(2, #tile{suit=sou, value=8})}, + #meld{type=kan, tiles=[#tile{suit=sou, value=V} || V <- [1,1,1,1]]}, + #meld{type=kan, tiles=[#tile{suit=man, value=V} || V <- [1,1,1,1]]}, + #meld{type=pon, tiles=[#tile{suit=pin, value=V} || V <- [2,2,2]]}, + #meld{type=pon, tiles=[#tile{suit=pin, value=V} || V <- [8,8,8]]}]}, + ?assertEqual(true, yaku:toi_toi(#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})).