mirror of
https://github.com/correl/riichi.git
synced 2024-11-23 19:19:55 +00:00
Itsuu
This commit is contained in:
parent
d3220e1906
commit
4438b8bc38
2 changed files with 21 additions and 0 deletions
13
src/yaku.erl
13
src/yaku.erl
|
@ -13,6 +13,7 @@
|
|||
pinfu/2,
|
||||
iipeikou/2,
|
||||
chanta/2,
|
||||
itsuu/2,
|
||||
chiitoitsu/2,
|
||||
kokushi_musou/2,
|
||||
ryuu_iisou/2,
|
||||
|
@ -100,6 +101,18 @@ chanta(#game{}, #player{hand=#hand{tiles=[], melds=Melds}}) ->
|
|||
end,
|
||||
Sets).
|
||||
|
||||
%% @doc Returns true for an Itsuu hand
|
||||
%% Hand must contain a 1-9 run in one suit
|
||||
-spec itsuu(game(), player()) -> boolean().
|
||||
itsuu(#game{}, #player{hand=#hand{tiles=[], melds=Melds}}) ->
|
||||
Tiles = lists:flatten([TS || #meld{type=chii, tiles=TS} <- Melds]),
|
||||
Runs = [lists:filter(fun(#tile{suit=S, value=V}) -> S =:= Suit end, Tiles)
|
||||
|| Suit <- [man,sou,pin]],
|
||||
lists:any(fun(TS) ->
|
||||
sets:from_list([V || #tile{value=V} <- TS]) =:= sets:from_list(lists:seq(1,9))
|
||||
end,
|
||||
Runs).
|
||||
|
||||
%% @doc Returns true for a 7-pair hand.
|
||||
-spec chiitoitsu(game(), player()) -> boolean().
|
||||
chiitoitsu(#game{}, #player{hand=#hand{tiles=[], melds=Melds}})
|
||||
|
|
|
@ -52,6 +52,14 @@ chanta_test() ->
|
|||
#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}}})).
|
||||
|
||||
itsuu_test() ->
|
||||
Hand = #hand{melds=[#meld{type=pair, tiles=lists:duplicate(2, #tile{suit=sou, value=8})},
|
||||
#meld{type=chii, tiles=[#tile{suit=sou, value=V} || V <- [1,2,3]]},
|
||||
#meld{type=chii, tiles=[#tile{suit=sou, value=V} || V <- [4,5,6]]},
|
||||
#meld{type=chii, tiles=[#tile{suit=sou, value=V} || V <- [7,8,9]]},
|
||||
#meld{type=chii, tiles=[#tile{suit=man, value=V} || V <- [6,7,8]]}]},
|
||||
?assertEqual(true, yaku:itsuu(#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})).
|
||||
|
|
Loading…
Reference in a new issue