mirror of
https://github.com/correl/riichi.git
synced 2024-11-14 19:19:31 +00:00
San an kou
This commit is contained in:
parent
7e0315bd29
commit
050f3c11eb
3 changed files with 28 additions and 0 deletions
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
-export([
|
-export([
|
||||||
is_valid_tile/1,
|
is_valid_tile/1,
|
||||||
|
is_open/1,
|
||||||
dora/1,
|
dora/1,
|
||||||
nearest/2,
|
nearest/2,
|
||||||
score/3,
|
score/3,
|
||||||
|
@ -32,6 +33,17 @@ is_valid_tile(#tile{suit=Suit, value=Value}) ->
|
||||||
is_valid_tile(_) ->
|
is_valid_tile(_) ->
|
||||||
false.
|
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().
|
-spec dora(tile()) -> tile().
|
||||||
dora(#tile{suit=dragon, value=Value}=Indicator) ->
|
dora(#tile{suit=dragon, value=Value}=Indicator) ->
|
||||||
case Value of
|
case Value of
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
san_shoku_douko/2,
|
san_shoku_douko/2,
|
||||||
san_kan_tsu/2,
|
san_kan_tsu/2,
|
||||||
toi_toi/2,
|
toi_toi/2,
|
||||||
|
san_an_kou/2,
|
||||||
kokushi_musou/2,
|
kokushi_musou/2,
|
||||||
ryuu_iisou/2,
|
ryuu_iisou/2,
|
||||||
dai_san_gen/2]).
|
dai_san_gen/2]).
|
||||||
|
@ -155,6 +156,14 @@ toi_toi(#game{}, #player{hand=#hand{melds=Melds}}) ->
|
||||||
lists:member(T, [pon,kan])],
|
lists:member(T, [pon,kan])],
|
||||||
length(Pons) =:= 4.
|
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.
|
%% @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}})
|
||||||
|
|
|
@ -92,6 +92,13 @@ toi_toi_test() ->
|
||||||
#meld{type=pon, tiles=[#tile{suit=pin, value=V} || V <- [8,8,8]]}]},
|
#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}}})).
|
?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() ->
|
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)]},
|
||||||
|
|
Loading…
Reference in a new issue