San an kou

This commit is contained in:
Correl Roush 2012-08-14 21:25:51 -04:00
parent 7e0315bd29
commit 050f3c11eb
3 changed files with 28 additions and 0 deletions

View file

@ -10,6 +10,7 @@
-export([
is_valid_tile/1,
is_open/1,
dora/1,
nearest/2,
score/3,
@ -32,6 +33,17 @@ is_valid_tile(#tile{suit=Suit, value=Value}) ->
is_valid_tile(_) ->
false.
-spec is_open(hand() | meld() | tile()) -> boolean().
is_open(#tile{from=draw}) ->
false;
is_open(#tile{}) ->
true;
is_open(#meld{tiles=Tiles}) ->
lists:any(fun is_open/1, Tiles);
is_open(#hand{tiles=Tiles, melds=Melds}) ->
lists:any(fun is_open/1, Tiles)
orelse lists:any(fun is_open/1, Melds).
-spec dora(tile()) -> tile().
dora(#tile{suit=dragon, value=Value}=Indicator) ->
case Value of

View file

@ -19,6 +19,7 @@
san_shoku_douko/2,
san_kan_tsu/2,
toi_toi/2,
san_an_kou/2,
kokushi_musou/2,
ryuu_iisou/2,
dai_san_gen/2]).
@ -155,6 +156,14 @@ toi_toi(#game{}, #player{hand=#hand{melds=Melds}}) ->
lists:member(T, [pon,kan])],
length(Pons) =:= 4.
%% @doc Returns true for a San an kou hand
%% Hand must contain three concealed triplets
san_an_kou(#game{}, #player{hand=#hand{melds=Melds}}) ->
ClosedPons = [M || M = #meld{type=T} <- Melds,
not riichi:is_open(M),
lists:member(T, [pon,kan])],
length(ClosedPons) =:= 3.
%% @doc Returns true for a 7-pair hand.
-spec chiitoitsu(game(), player()) -> boolean().
chiitoitsu(#game{}, #player{hand=#hand{tiles=[], melds=Melds}})

View file

@ -92,6 +92,13 @@ toi_toi_test() ->
#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}}})).
san_an_kou_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 <- [1,1,1]]},
#meld{type=chii, tiles=[#tile{suit=man, value=V} || V <- [6,7,8]]}]},
?assertEqual(true, yaku:san_an_kou(#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)]},