mirror of
https://github.com/correl/riichi.git
synced 2024-11-23 11:09:56 +00:00
Chanta
This commit is contained in:
parent
217dfb2252
commit
a4c72c860d
2 changed files with 21 additions and 0 deletions
13
src/yaku.erl
13
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}})
|
||||
|
|
|
@ -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})).
|
||||
|
|
Loading…
Reference in a new issue