From d3220e1906c82eeb10b8c24bc9cba1cb54dde4b0 Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Fri, 10 Aug 2012 20:42:52 -0400 Subject: [PATCH] Chanta --- src/yaku.erl | 13 +++++++++++++ test/riichi_yaku_tests.erl | 8 ++++++++ 2 files changed, 21 insertions(+) diff --git a/src/yaku.erl b/src/yaku.erl index aefd827..724ff78 100644 --- a/src/yaku.erl +++ b/src/yaku.erl @@ -12,6 +12,7 @@ tanyao/2, pinfu/2, iipeikou/2, + chanta/2, chiitoitsu/2, kokushi_musou/2, ryuu_iisou/2, @@ -87,6 +88,18 @@ iipeikou(#game{}, #player{hand=#hand{melds=Melds}}) -> Counts = [C || {_, C} <- count_unique(Chiis)], lists:max(Counts) > 1 andalso lists:max(Counts) < 4. +%% @doc Returns true for a Chanta hand +%% All melds and the pair must include a terminal or honor tile +-spec chanta(game(), player()) -> boolean(). +chanta(#game{}, #player{hand=#hand{tiles=[], melds=Melds}}) -> + Sets = [[{T#tile.suit, T#tile.value} || T <- Tiles] + || #meld{tiles=Tiles} <- Melds], + ChantaTiles = [{T#tile.suit, T#tile.value} || T <- (?TERMINALS ++ ?HONOURS)], + lists:all(fun(Tiles) -> + (Tiles -- ChantaTiles =/= Tiles) + end, + Sets). + %% @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 d7d6cd0..c57dec8 100644 --- a/test/riichi_yaku_tests.erl +++ b/test/riichi_yaku_tests.erl @@ -44,6 +44,14 @@ iipeikou_test() -> #meld{type=chii, tiles=[#tile{suit=man, value=V} || V <- [6,7,8]]}]}, ?assertEqual(true, yaku:iipeikou(#game{}, #player{hand=Hand, drawn={tsumo, #tile{suit=sou, value=6}}})). +chanta_test() -> + Hand = #hand{melds=[#meld{type=pair, tiles=lists:duplicate(2, #tile{suit=dragon, value=red})}, + #meld{type=chii, tiles=[#tile{suit=pin, value=V} || V <- [1,2,3]]}, + #meld{type=pon, tiles=[#tile{suit=sou, value=V} || V <- [1,1,1]]}, + #meld{type=pon, tiles=[#tile{suit=sou, value=V} || V <- [9,9,9]]}, + #meld{type=chii, tiles=[#tile{suit=man, value=V} || V <- [7,8,9]]}]}, + ?assertEqual(true, yaku:chanta(#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})).