riichi/src/yaku.erl

54 lines
1.9 KiB
Erlang
Raw Normal View History

2012-07-21 01:09:28 +00:00
-module(yaku).
-include("../include/riichi.hrl").
-compile([export_all]).
2012-07-21 04:09:27 +00:00
yakuhai(#hand{melds=Melds}) ->
length(lists:filter(fun(#meld{type=Type, tiles=[T|_]}) ->
case {Type, T} of
{pair, _} ->
false;
{chii, _} ->
false;
{_, #tile{suit=wind}} ->
2012-07-21 01:09:28 +00:00
% TODO: Round/Seat Winds
false;
2012-07-21 04:09:27 +00:00
{_, #tile{suit=dragon}} ->
true
2012-07-21 01:09:28 +00:00
end
end,
2012-07-21 04:09:27 +00:00
Melds)).
2012-07-21 01:09:28 +00:00
2012-07-21 04:09:27 +00:00
tanyao(#hand{melds=Melds}) ->
2012-07-21 01:09:28 +00:00
not lists:any(fun(T = #tile{}) ->
case T#tile.suit of
dragon ->
true;
wind ->
true;
_ ->
lists:member(T#tile.value, [1,9])
end
end,
2012-07-21 04:09:27 +00:00
lists:flatten([Tiles || #meld{tiles=Tiles} <- Melds])).
2012-07-21 01:09:28 +00:00
2012-07-21 04:09:27 +00:00
pinfu(#hand{melds=Melds}) ->
2012-07-21 01:09:28 +00:00
% TODO: Verify closed, open wait, pair not round/seat wind
2012-07-21 04:09:27 +00:00
length([M || M = #meld{type=T} <- Melds, T =:= chii]) =:= 4.
2012-07-21 01:09:28 +00:00
% 7 Pairs
2012-07-21 04:09:27 +00:00
chiitoitsu(#hand{tiles=[], melds=Melds})
when length(Melds) =:= 7 ->
Pairs = [S || S <- Melds, S#meld.type =:= pair],
2012-07-21 01:09:28 +00:00
length(Pairs) =:= 7 andalso sets:size(sets:from_list(Pairs)) =:= 7.
% 13 Orphans
2012-07-21 04:09:27 +00:00
kokushi_musou(#hand{tiles=Tiles, melds=[#meld{type=pair, tiles=[T,T]}]}) ->
2012-07-21 01:09:28 +00:00
not lists:any(fun(#tile{value=V}) ->
lists:member(V, lists:seq(2,8))
end,
2012-07-21 04:09:27 +00:00
[T|Tiles])
andalso sets:size(sets:from_list([T|Tiles])) =:= 13.