mirror of
https://github.com/correl/riichi.git
synced 2024-11-27 11:09:56 +00:00
Cleaning up yaku and hand completion detection
This commit is contained in:
parent
0a0db90e43
commit
4d85ba0d10
2 changed files with 8 additions and 13 deletions
|
@ -36,7 +36,7 @@ find(Tiles, Hand = #hand{tiles=HT, melds=HM}, Possible) ->
|
||||||
find(Rest, Hand#hand{tiles=[T|HT]}, Possible)
|
find(Rest, Hand#hand{tiles=[T|HT]}, Possible)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
is_complete(#hand{tiles=[], melds=Melds}) ->
|
is_complete(#hand{tiles=[], melds=Melds}=Hand) ->
|
||||||
Pairs = [M || M <- Melds, M#meld.type =:= pair],
|
Pairs = [M || M <- Melds, M#meld.type =:= pair],
|
||||||
case length(Pairs) of
|
case length(Pairs) of
|
||||||
1 ->
|
1 ->
|
||||||
|
@ -44,19 +44,12 @@ is_complete(#hand{tiles=[], melds=Melds}) ->
|
||||||
length(Melds) =:= 5;
|
length(Melds) =:= 5;
|
||||||
7 ->
|
7 ->
|
||||||
% Must be seven *unique* pairs
|
% Must be seven *unique* pairs
|
||||||
sets:size(sets:from_list(Pairs)) =:= 7;
|
yaku:chiitoitsu(Hand);
|
||||||
_ ->
|
_ ->
|
||||||
false
|
false
|
||||||
end;
|
end;
|
||||||
is_complete(#hand{}=Hand) ->
|
is_complete(#hand{}=Hand) ->
|
||||||
kokushi_musou(Hand).
|
yaku:kokushi_musou(Hand).
|
||||||
|
|
||||||
% 13 Orphans
|
km() ->
|
||||||
kokushi_musou(#hand{tiles=Tiles, melds=Melds}) when
|
[#tile{suit=pin, value=1}|?TERMINALS ++ ?HONOURS].
|
||||||
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.
|
|
||||||
|
|
|
@ -50,4 +50,6 @@ kokushi_musou(#hand{tiles=Tiles, melds=[#meld{type=pair, tiles=[T,T]}]}) ->
|
||||||
lists:member(V, lists:seq(2,8))
|
lists:member(V, lists:seq(2,8))
|
||||||
end,
|
end,
|
||||||
[T|Tiles])
|
[T|Tiles])
|
||||||
andalso sets:size(sets:from_list([T|Tiles])) =:= 13.
|
andalso sets:size(sets:from_list([T|Tiles])) =:= 13;
|
||||||
|
kokushi_musou(#hand{}) ->
|
||||||
|
false.
|
||||||
|
|
Loading…
Reference in a new issue