riichi/src/yaku.erl

68 lines
2.6 KiB
Erlang
Raw Normal View History

2012-07-21 01:09:28 +00:00
-module(yaku).
-include("../include/riichi.hrl").
2012-08-01 01:49:51 +00:00
-export([yakuhai/2,
tanyao/2,
pinfu/2,
chiitoitsu/2,
kokushi_musou/2]).
2012-07-21 01:09:28 +00:00
2012-08-01 01:49:51 +00:00
yakuhai(#game{round=Round}, #player{seat=Seat, hand=#hand{melds=Melds}}) ->
2012-07-21 04:09:27 +00:00
length(lists:filter(fun(#meld{type=Type, tiles=[T|_]}) ->
case {Type, T} of
{pair, _} ->
false;
{chii, _} ->
false;
2012-08-01 01:49:51 +00:00
{_, #tile{suit=wind, value=Round}} ->
true;
{_, #tile{suit=wind, value=Seat}} ->
true;
2012-07-21 04:09:27 +00:00
{_, #tile{suit=dragon}} ->
2012-08-01 01:49:51 +00:00
true;
_ ->
false
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-08-01 01:49:51 +00:00
tanyao(#game{}, #player{hand=Hand}) ->
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-08-01 01:49:51 +00:00
riichi_hand:tiles(Hand)).
2012-07-21 01:09:28 +00:00
2012-08-01 01:49:51 +00:00
pinfu(#game{round=Round}, #player{seat=Seat, hand=Hand=#hand{melds=Melds}}) ->
% TODO: Verify closed, open wait, and pair not round/seat wind
Closed = lists:all(fun(T) -> T#tile.from =:= draw end, riichi_hand:tiles(Hand)),
Chiis = length([M || M = #meld{type=chii} <- Melds]) =:= 4,
#meld{type=pair, tiles=[HeadTile,HeadTile]} = riichi_hand:head(Hand),
NonValuePair = HeadTile#tile.value =/= Round
andalso HeadTile#tile.value =/= Seat
andalso HeadTile#tile.suit =/= dragon,
Closed and Chiis and NonValuePair.
2012-07-21 01:09:28 +00:00
% 7 Pairs
2012-08-01 01:49:51 +00:00
chiitoitsu(#game{}, #player{hand=#hand{tiles=[], melds=Melds}})
2012-07-21 04:09:27 +00:00
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-08-01 01:49:51 +00:00
kokushi_musou(#game{}, #player{hand=#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;
2012-08-01 01:49:51 +00:00
kokushi_musou(#game{}, #player{}) ->
false.