Cleaning up yaku and hand completion detection

This commit is contained in:
Correl Roush 2012-07-30 22:33:19 -04:00
parent b23700b247
commit 2802bbf15e
2 changed files with 8 additions and 13 deletions

View file

@ -36,7 +36,7 @@ find(Tiles, Hand = #hand{tiles=HT, melds=HM}, Possible) ->
find(Rest, Hand#hand{tiles=[T|HT]}, Possible)
end.
is_complete(#hand{tiles=[], melds=Melds}) ->
is_complete(#hand{tiles=[], melds=Melds}=Hand) ->
Pairs = [M || M <- Melds, M#meld.type =:= pair],
case length(Pairs) of
1 ->
@ -44,19 +44,12 @@ is_complete(#hand{tiles=[], melds=Melds}) ->
length(Melds) =:= 5;
7 ->
% Must be seven *unique* pairs
sets:size(sets:from_list(Pairs)) =:= 7;
yaku:chiitoitsu(Hand);
_ ->
false
end;
is_complete(#hand{}=Hand) ->
kokushi_musou(Hand).
yaku:kokushi_musou(Hand).
% 13 Orphans
kokushi_musou(#hand{tiles=Tiles, melds=Melds}) when
length(Tiles) =:= 13
andalso length(Melds) =:= 0 ->
not lists:any(fun(#tile{value=V}) ->
lists:member(V, lists:seq(2,8))
end,
Tiles)
andalso sets:size(sets:from_list(Tiles)) =:= 13.
km() ->
[#tile{suit=pin, value=1}|?TERMINALS ++ ?HONOURS].

View file

@ -50,4 +50,6 @@ kokushi_musou(#hand{tiles=Tiles, melds=[#meld{type=pair, tiles=[T,T]}]}) ->
lists:member(V, lists:seq(2,8))
end,
[T|Tiles])
andalso sets:size(sets:from_list([T|Tiles])) =:= 13.
andalso sets:size(sets:from_list([T|Tiles])) =:= 13;
kokushi_musou(#hand{}) ->
false.